01: /*
02: * Copyright 2001-2006 C:1 Financial Services GmbH
03: *
04: * This software is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License Version 2.1, as published by the Free Software Foundation.
07: *
08: * This software is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11: * Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public
14: * License along with this library; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
16: */
17:
18: package de.finix.contelligent.core.security;
19:
20: import java.util.Collection;
21: import java.util.Collections;
22: import java.util.HashSet;
23: import java.util.Set;
24:
25: public final class ContelligentUser extends ContelligentPrincipalImpl
26: implements User {
27:
28: private Set roleSet = new HashSet();
29: private boolean authenticated = false;
30:
31: private String alias;
32:
33: ContelligentUser(String principalGroup, String principalId) {
34: this (principalGroup, principalId, null);
35: }
36:
37: ContelligentUser(String principalGroup, String principalId,
38: String displayName) {
39: super (principalId, principalGroup, displayName);
40: }
41:
42: ContelligentUser(String principalGroup, String principalId,
43: String alias, String displayName, Collection roles) {
44: this (principalGroup, principalId, displayName);
45: this .alias = sanitize(alias);
46: roleSet.addAll(roles);
47: }
48:
49: // assert: data.isUser() == true
50: ContelligentUser(PrincipalData data) {
51: this (data.getGroupId(), data.getId(), data.getDisplayName());
52: alias = sanitize(data.getAliasId());
53: }
54:
55: ContelligentUser(PrincipalData data, Collection roles) {
56: this (data);
57: roleSet.addAll(roles);
58: }
59:
60: public Collection getRoles() {
61: return Collections.unmodifiableSet(roleSet);
62: }
63:
64: public boolean hasRole(Role role) {
65: return roleSet.contains(role);
66: }
67:
68: public String getAlias() {
69: return alias;
70: }
71:
72: public void setAuthenticated(boolean authenticated) {
73: SecurityManager sm = System.getSecurityManager();
74: if (sm != null) {
75: sm.checkPermission(new RuntimePermission(
76: RuntimePermissionTargets.VALIDATE_AUTHENTICATION));
77: }
78: this .authenticated = authenticated;
79: }
80:
81: public boolean isAuthenticated() {
82: return authenticated;
83: }
84: }
|