001: /*
002: * Copyright 2004 Outerthought bvba and Schaubroeck nv
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.outerj.daisy.repository.commonimpl.user;
017:
018: import org.outerj.daisy.repository.commonimpl.AuthenticatedUser;
019: import org.outerj.daisy.repository.user.*;
020: import org.outerj.daisy.repository.RepositoryException;
021: import org.outerj.daisy.repository.RepositoryListener;
022:
023: public class CommonUserManager {
024: protected final UserManagementStrategy userManagementStrategy;
025: private UserCache userCache;
026:
027: public CommonUserManager(
028: UserManagementStrategy userManagementStrategy,
029: UserCache userCache) {
030: this .userManagementStrategy = userManagementStrategy;
031: this .userCache = userCache;
032: }
033:
034: public RepositoryListener getCacheListener() {
035: return userCache;
036: }
037:
038: public Users getUsers(AuthenticatedUser user)
039: throws RepositoryException {
040: return userManagementStrategy.loadUsers(user);
041: }
042:
043: public long[] getUserIds(AuthenticatedUser user)
044: throws RepositoryException {
045: return userManagementStrategy.getUserIds(user);
046: }
047:
048: public PublicUserInfo getPublicUserInfo(long userId)
049: throws RepositoryException {
050: return userCache.getPublicUserInfo(userId);
051: }
052:
053: public PublicUserInfo getPublicUserInfo(String login)
054: throws RepositoryException {
055: return userCache.getPublicUserInfo(login);
056: }
057:
058: public PublicUserInfos getPublicUserInfos(AuthenticatedUser user)
059: throws RepositoryException {
060: return userManagementStrategy.getPublicUserInfos(user);
061: }
062:
063: public Roles getRoles(AuthenticatedUser user)
064: throws RepositoryException {
065: return userManagementStrategy.loadRoles(user);
066: }
067:
068: public User createUser(String login, AuthenticatedUser user) {
069: return new UserImpl(userManagementStrategy, login, user);
070: }
071:
072: public void deleteUser(long userId, AuthenticatedUser user)
073: throws RepositoryException {
074: userManagementStrategy.deleteUser(userId, user);
075: }
076:
077: public Role createRole(String roleName, AuthenticatedUser user) {
078: return new RoleImpl(userManagementStrategy, roleName, user);
079: }
080:
081: public void deleteRole(long roleId, AuthenticatedUser user)
082: throws RepositoryException {
083: userManagementStrategy.deleteRole(roleId, user);
084: }
085:
086: public User getUser(String login, boolean updateable,
087: AuthenticatedUser user) throws RepositoryException {
088: if (updateable) {
089: return userManagementStrategy.getUser(login, user);
090: } else {
091: User theUser = userCache.getUser(login, user);
092: if (theUser.getId() != user.getId()
093: && !user.isInAdministratorRole())
094: throw new UserManagementException(
095: "Only administrators can access user records of other users.");
096: return theUser;
097: }
098: }
099:
100: public Role getRole(String name, boolean updateable,
101: AuthenticatedUser user) throws RepositoryException {
102: if (updateable) {
103: return userManagementStrategy.getRole(name, user);
104: } else {
105: return userCache.getRole(name);
106: }
107: }
108:
109: public User getUser(long userId, boolean updateable,
110: AuthenticatedUser user) throws RepositoryException {
111: if (updateable) {
112: return userManagementStrategy.getUser(userId, user);
113: } else {
114: if (userId != user.getId() && !user.isInAdministratorRole())
115: throw new UserManagementException(
116: "Only administrators can access user records of other users.");
117: return userCache.getUser(userId, user);
118: }
119: }
120:
121: public Role getRole(long roleId, boolean updateable,
122: AuthenticatedUser user) throws RepositoryException {
123: if (updateable) {
124: return userManagementStrategy.getRole(roleId, user);
125: } else {
126: return userCache.getRole(roleId);
127: }
128: }
129:
130: public String getUserDisplayName(long userId)
131: throws RepositoryException {
132: return userCache.getPublicUserInfo(userId).getDisplayName();
133: }
134:
135: public String getUserLogin(long userId) throws RepositoryException {
136: return userCache.getPublicUserInfo(userId).getLogin();
137: }
138:
139: public long getUserId(String login) throws RepositoryException {
140: return userCache.getPublicUserInfo(login).getId();
141: }
142:
143: public String getRoleDisplayName(long roleId)
144: throws RepositoryException {
145: return userCache.getRole(roleId).getName();
146: }
147:
148: public Users getUsersByEmail(String email, AuthenticatedUser user)
149: throws RepositoryException {
150: return userManagementStrategy.getUsersByEmail(email, user);
151: }
152:
153: public AuthenticationSchemeInfos getAuthenticationSchemes(
154: AuthenticatedUser user) throws RepositoryException {
155: return userManagementStrategy.getAuthenticationSchemes(user);
156: }
157: }
|