001: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
002: *
003: * Licensed under the Apache License, Version 2.0 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at
006: *
007: * http://www.apache.org/licenses/LICENSE-2.0
008: *
009: * Unless required by applicable law or agreed to in writing, software
010: * distributed under the License is distributed on an "AS IS" BASIS,
011: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: * See the License for the specific language governing permissions and
013: * limitations under the License.
014: */
015:
016: package org.acegisecurity.userdetails.memory;
017:
018: import org.acegisecurity.GrantedAuthority;
019: import org.acegisecurity.GrantedAuthorityImpl;
020:
021: import java.util.ArrayList;
022: import java.util.Iterator;
023: import java.util.List;
024: import java.util.Vector;
025:
026: /**
027: * Used by {@link InMemoryDaoImpl} to temporarily store the attributes associated with a user.
028: *
029: * @author Ben Alex
030: * @version $Id: UserAttribute.java 1642 2006-09-04 21:54:15Z carlossg $
031: */
032: public class UserAttribute {
033: //~ Instance fields ================================================================================================
034:
035: private List authorities = new Vector();
036: private String password;
037: private boolean enabled = true;
038:
039: //~ Constructors ===================================================================================================
040:
041: public UserAttribute() {
042: super ();
043: }
044:
045: //~ Methods ========================================================================================================
046:
047: public void addAuthority(GrantedAuthority newAuthority) {
048: this .authorities.add(newAuthority);
049: }
050:
051: public GrantedAuthority[] getAuthorities() {
052: GrantedAuthority[] toReturn = { new GrantedAuthorityImpl("demo") };
053:
054: return (GrantedAuthority[]) this .authorities.toArray(toReturn);
055: }
056:
057: /**
058: * Set all authorities for this user.
059: *
060: * @param authorities {@link List} <{@link GrantedAuthority}>
061: * @since 1.1
062: */
063: public void setAuthorities(List authorities) {
064: this .authorities = authorities;
065: }
066:
067: /**
068: * Set all authorities for this user from String values.
069: * It will create the necessary {@link GrantedAuthority} objects.
070: *
071: * @param authoritiesAsString {@link List} <{@link String}>
072: * @since 1.1
073: */
074: public void setAuthoritiesAsString(List authoritiesAsString) {
075: setAuthorities(new ArrayList(authoritiesAsString.size()));
076: Iterator it = authoritiesAsString.iterator();
077: while (it.hasNext()) {
078: GrantedAuthority grantedAuthority = new GrantedAuthorityImpl(
079: (String) it.next());
080: addAuthority(grantedAuthority);
081: }
082: }
083:
084: public String getPassword() {
085: return password;
086: }
087:
088: public boolean isEnabled() {
089: return enabled;
090: }
091:
092: public boolean isValid() {
093: if ((this .password != null) && (authorities.size() > 0)) {
094: return true;
095: } else {
096: return false;
097: }
098: }
099:
100: public void setEnabled(boolean enabled) {
101: this .enabled = enabled;
102: }
103:
104: public void setPassword(String password) {
105: this.password = password;
106: }
107: }
|