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;
29 * User access that always returns a user that belongs to a fixed group.
31 * @author Erik Brakkee
33 public class TestUserAccessor implements UserAccessor {
34 private static final String USER = "erik";
36 private static final String PASSWORD = "abc123";
38 private static final String GROUP = "users";
40 private UserAdministration userAdmin;
42 public TestUserAccessor() {
43 userAdmin = new UserAdministrationImpl(
44 new InMemoryUserSet(new RegexpNameValidator(
45 RegexpNameValidator.PASSWORD_PATTERN, Reason.INVALID_PASSWORD,
46 "Password must contain at least 6 characters"),
47 new Md5HexMessageDigester()), new InMemoryGroupSet(),
48 new RegexpNameValidator(RegexpNameValidator.ID_PATTERN,
49 Reason.INVALID_USERNAME, "Invalid user"),
50 new RegexpNameValidator(RegexpNameValidator.ID_PATTERN,
51 Reason.INVALID_GROUPNAME, "Invalid group"));
53 userAdmin.createGroup(GROUP);
54 userAdmin.createUser(USER, PASSWORD);
55 userAdmin.addUserToGroup(USER, GROUP);
58 // NOTE: This is only for test. Normally the user accessor would not depend
59 // on user administration. This just ensures that a user administration is created
60 // that knows about the given user.
61 public UserAdministration getUserAdmin() {
68 * @see org.wamblee.usermgt.UserAccessor#getCurrentUser()
70 public String getCurrentUser() {