| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
| UserAttribute |
|
| 1.3;1.3 |
| 1 | /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited |
|
| 2 | * |
|
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
| 4 | * you may not use this file except in compliance with the License. |
|
| 5 | * You may obtain a copy of the License at |
|
| 6 | * |
|
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
| 8 | * |
|
| 9 | * Unless required by applicable law or agreed to in writing, software |
|
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
| 12 | * See the License for the specific language governing permissions and |
|
| 13 | * limitations under the License. |
|
| 14 | */ |
|
| 15 | ||
| 16 | package org.acegisecurity.userdetails.memory; |
|
| 17 | ||
| 18 | import org.acegisecurity.GrantedAuthority; |
|
| 19 | import org.acegisecurity.GrantedAuthorityImpl; |
|
| 20 | ||
| 21 | import java.util.ArrayList; |
|
| 22 | import java.util.Iterator; |
|
| 23 | import java.util.List; |
|
| 24 | import java.util.Vector; |
|
| 25 | ||
| 26 | ||
| 27 | /** |
|
| 28 | * Used by {@link InMemoryDaoImpl} to temporarily store the attributes associated with a user. |
|
| 29 | * |
|
| 30 | * @author Ben Alex |
|
| 31 | * @version $Id: UserAttribute.java 1642 2006-09-04 21:54:15Z carlossg $ |
|
| 32 | */ |
|
| 33 | public class UserAttribute { |
|
| 34 | //~ Instance fields ================================================================================================ |
|
| 35 | ||
| 36 | 62 | private List authorities = new Vector(); |
| 37 | private String password; |
|
| 38 | 62 | private boolean enabled = true; |
| 39 | ||
| 40 | //~ Constructors =================================================================================================== |
|
| 41 | ||
| 42 | public UserAttribute() { |
|
| 43 | 62 | super(); |
| 44 | 62 | } |
| 45 | ||
| 46 | //~ Methods ======================================================================================================== |
|
| 47 | ||
| 48 | public void addAuthority(GrantedAuthority newAuthority) { |
|
| 49 | 115 | this.authorities.add(newAuthority); |
| 50 | 115 | } |
| 51 | ||
| 52 | public GrantedAuthority[] getAuthorities() { |
|
| 53 | 66 | GrantedAuthority[] toReturn = {new GrantedAuthorityImpl("demo")}; |
| 54 | ||
| 55 | 66 | return (GrantedAuthority[]) this.authorities.toArray(toReturn); |
| 56 | } |
|
| 57 | ||
| 58 | /** |
|
| 59 | * Set all authorities for this user. |
|
| 60 | * |
|
| 61 | * @param authorities {@link List} <{@link GrantedAuthority}> |
|
| 62 | * @since 1.1 |
|
| 63 | */ |
|
| 64 | public void setAuthorities(List authorities) { |
|
| 65 | 58 | this.authorities = authorities; |
| 66 | 58 | } |
| 67 | ||
| 68 | /** |
|
| 69 | * Set all authorities for this user from String values. |
|
| 70 | * It will create the necessary {@link GrantedAuthority} objects. |
|
| 71 | * |
|
| 72 | * @param authoritiesAsString {@link List} <{@link String}> |
|
| 73 | * @since 1.1 |
|
| 74 | */ |
|
| 75 | public void setAuthoritiesAsString(List authoritiesAsString) { |
|
| 76 | 58 | setAuthorities(new ArrayList(authoritiesAsString.size())); |
| 77 | 58 | Iterator it = authoritiesAsString.iterator(); |
| 78 | 169 | while (it.hasNext()) { |
| 79 | 111 | GrantedAuthority grantedAuthority = new GrantedAuthorityImpl((String) it.next()); |
| 80 | 111 | addAuthority(grantedAuthority); |
| 81 | 111 | } |
| 82 | 58 | } |
| 83 | ||
| 84 | public String getPassword() { |
|
| 85 | 58 | return password; |
| 86 | } |
|
| 87 | ||
| 88 | public boolean isEnabled() { |
|
| 89 | 54 | return enabled; |
| 90 | } |
|
| 91 | ||
| 92 | public boolean isValid() { |
|
| 93 | 61 | if ((this.password != null) && (authorities.size() > 0)) { |
| 94 | 58 | return true; |
| 95 | } else { |
|
| 96 | 3 | return false; |
| 97 | } |
|
| 98 | } |
|
| 99 | ||
| 100 | public void setEnabled(boolean enabled) { |
|
| 101 | 49 | this.enabled = enabled; |
| 102 | 49 | } |
| 103 | ||
| 104 | public void setPassword(String password) { |
|
| 105 | 62 | this.password = password; |
| 106 | 62 | } |
| 107 | } |