001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.core.security;
019:
020: import java.util.Collection;
021: import java.util.Collections;
022: import java.util.HashSet;
023:
024: /**
025: * This class represents a principal entry in the db.
026: */
027: public class PrincipalData {
028:
029: private String id;
030:
031: private String aliasId;
032:
033: private String groupId;
034:
035: private String displayName;
036:
037: private String password;
038:
039: private boolean isUser;
040:
041: private boolean active;
042:
043: private int hashCode;
044:
045: private Collection roles;
046:
047: public PrincipalData(String id, String aliasId, String groupId,
048: String displayName, String password, boolean user,
049: boolean active) {
050: this .id = id;
051: this .aliasId = aliasId;
052: this .groupId = groupId;
053: this .displayName = displayName;
054: this .password = password;
055: this .active = active;
056: isUser = user;
057: hashCode = (groupId + ContelligentPrincipal.SEPARATOR + id)
058: .hashCode();
059: }
060:
061: public String getId() {
062: return id;
063: }
064:
065: public String getAliasId() {
066: return aliasId;
067: }
068:
069: public String getGroupId() {
070: return groupId;
071: }
072:
073: public String getDisplayName() {
074: return displayName;
075: }
076:
077: public String getPassword() {
078: return password;
079: }
080:
081: public boolean isUser() {
082: return isUser;
083: }
084:
085: public boolean isRole() {
086: return !isUser;
087: }
088:
089: public Collection getRoles() {
090: if (roles == null) {
091: return Collections.EMPTY_SET;
092: }
093: return roles;
094: }
095:
096: public void setRoles(Collection roles) {
097: this .roles = roles;
098: }
099:
100: public void addRole(Role role) {
101: if (roles == null) {
102: roles = new HashSet();
103: }
104: roles.add(role);
105: }
106:
107: public int hashCode() {
108: return hashCode;
109: }
110:
111: public boolean equals(Object obj) {
112: if (!(obj instanceof PrincipalData)) {
113: return false;
114: }
115: PrincipalData data = (PrincipalData) obj;
116: return data.getId().equals(getId())
117: && data.getGroupId().equals(getGroupId());
118: }
119:
120: public void setDisplayName(String displayName) {
121: this .displayName = displayName;
122: }
123:
124: public boolean isActive() {
125: return active;
126: }
127:
128: public void setActive(boolean active) {
129: this.active = active;
130: }
131: }
|