01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: RoleUserAuthenticated.java 3643 2007-01-12 15:29:45Z gbevin $
07: */
08: package com.uwyn.rife.authentication.elements;
09:
10: import com.uwyn.rife.authentication.Credentials;
11: import com.uwyn.rife.authentication.credentials.RoleUserCredentials;
12:
13: /**
14: * Extends the generic {@link Authenticated} element with support for a {@code role}
15: * property that will be used together with {@link RoleUserCredentials}
16: * credentials to only allow people with that role to access the child page.
17: *
18: * @author Geert Bevin (gbevin[remove] at uwyn dot com)
19: * @version $Revision: 3643 $
20: * @since 1.0
21: */
22: public abstract class RoleUserAuthenticated extends Authenticated {
23: public boolean hasAttribute(String key) {
24: return key.equals("role") && hasProperty("role");
25: }
26:
27: public String getAttribute(String key) {
28: if (key.equals("role")) {
29: return getPropertyString("role");
30: }
31:
32: return null;
33: }
34:
35: protected void validatedCredentials(Credentials credentials) {
36: if (hasProperty("role")) {
37: ((RoleUserCredentials) credentials)
38: .setRole(getPropertyString("role"));
39: }
40: }
41: }
|