2 * Copyright 2005-2010 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.security.authorization;
18 import org.wamblee.security.authentication.InMemoryGroupSet;
19 import org.wamblee.security.authentication.InMemoryUserSet;
20 import org.wamblee.security.authentication.Md5HexMessageDigester;
21 import org.wamblee.security.authentication.RegexpNameValidator;
22 import org.wamblee.security.authentication.UserAccessor;
23 import org.wamblee.security.authentication.UserAdministration;
24 import org.wamblee.security.authentication.UserAdministrationImpl;
25 import org.wamblee.security.authentication.UserMgtException.Reason;
28 * User access that always returns a user that belongs to a fixed group.
30 * @author Erik Brakkee
32 public class TestUserAccessor implements UserAccessor {
33 private static final String USER = "erik";
35 private static final String PASSWORD = "abc123";
37 private static final String GROUP = "users";
39 private UserAdministration userAdmin;
41 public TestUserAccessor() {
42 userAdmin = new UserAdministrationImpl(new InMemoryUserSet(
43 new RegexpNameValidator(RegexpNameValidator.PASSWORD_PATTERN,
44 Reason.INVALID_PASSWORD,
45 "Password must contain at least 6 characters"),
46 new Md5HexMessageDigester()), new InMemoryGroupSet(),
47 new RegexpNameValidator(RegexpNameValidator.ID_PATTERN,
48 Reason.INVALID_USERNAME, "Invalid user"),
49 new RegexpNameValidator(RegexpNameValidator.ID_PATTERN,
50 Reason.INVALID_GROUPNAME, "Invalid group"));
52 userAdmin.createGroup(GROUP);
53 userAdmin.createUser(USER, PASSWORD);
54 userAdmin.addUserToGroup(USER, GROUP);
57 // NOTE: This is only for test. Normally the user accessor would not depend
58 // on user administration. This just ensures that a user administration is
60 // that knows about the given user.
61 public UserAdministration getUserAdmin() {
68 * @see org.wamblee.usermgt.UserAccessor#getCurrentUser()
70 public String getCurrentUser() {