01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com> and
03: * JR Boyens <gnu-jrb[remove] at gmx dot net>
04: * Distributed under the terms of either:
05: * - the common development and distribution license (CDDL), v1.0; or
06: * - the GNU Lesser General Public License, v2.1 or later
07: * $Id: RoleUsersManagerRetriever.java 3643 2007-01-12 15:29:45Z gbevin $
08: */
09: package com.uwyn.rife.authentication.credentialsmanagers;
10:
11: import com.uwyn.rife.authentication.CredentialsManager;
12: import com.uwyn.rife.authentication.SessionValidator;
13: import com.uwyn.rife.authentication.SessionValidatorRetriever;
14: import com.uwyn.rife.authentication.credentialsmanagers.RoleUsersManager;
15: import com.uwyn.rife.authentication.credentialsmanagers.exceptions.NotRoleUsersManagedException;
16: import com.uwyn.rife.engine.ElementInfo;
17: import com.uwyn.rife.engine.Site;
18:
19: /**
20: * This abstract class provides the functionalities to retrieve a {@link
21: * com.uwyn.rife.authentication.credentialsmanagers.RoleUsersManager
22: * RoleUsersManager} from a particular {@link
23: * com.uwyn.rife.authentication.elements.Authenticated Authenticated} element
24: * in a site.
25: * <p>Since you can have many authentication schemes and backends being active
26: * in a single web application. it's quite verbose to retrieve a
27: * RoleUsersManager when you want to perform some operations on its stored
28: * credentials. This class provides the functionalities to quickly perform
29: * this retrieval.
30: *
31: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
32: * @author JR Boyens <gnu-jrb[remove] at gmx dot net>
33: * @see com.uwyn.rife.authentication.credentialsmanagers.RoleUsersManager
34: * @see com.uwyn.rife.authentication.elements.Authenticated
35: * @version $Revision: 3643 $
36: * @since 1.0
37: */
38: public abstract class RoleUsersManagerRetriever {
39: /**
40: * Retrieves a {@code RoleUsersManager} manager from an
41: * {@code Authenticated} element in a {@code Site}.
42: *
43: * @param site the site in which the authenticated element is declared
44: * @param authElementId the absolute ID of the authenticated element that
45: * provides the {@code RoleUsersManager}
46: * @param reference a reference element against which to resolve the id; or
47: * {@code null} if the provided id is absolute
48: * @exception AuthenticatedElementNotFoundException when the element ID
49: * couldn't be found in the site
50: * @exception NotAuthenticatedElementException when the element ID doesn't
51: * refer to an {@code Authenticated} element
52: * @exception NotRoleUsersManagedException when the
53: * {@code CredentialsManager} of the Authenticated element is not a
54: * {@code RoleUsersManager}
55: * @since 1.0
56: */
57: public static RoleUsersManager getRoleUsersManager(Site site,
58: String authElementId, ElementInfo reference) {
59: SessionValidator validator = SessionValidatorRetriever
60: .getSessionValidator(site, authElementId, reference);
61: CredentialsManager credentials = validator
62: .getCredentialsManager();
63: if (null == credentials
64: || !(credentials instanceof RoleUsersManager)) {
65: throw new NotRoleUsersManagedException(authElementId);
66: }
67:
68: return (RoleUsersManager) credentials;
69: }
70: }
|