View Javadoc

1   /* 
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.jetspeed.security.om.impl;
18  
19  import java.util.ArrayList;
20  import java.util.Collection;
21  
22  import org.apache.jetspeed.security.om.InternalUserPrincipal;
23  
24  /***
25   * <p>{@link InternalUserPrincipal} interface implementation.</p>
26   * 
27   * @author <a href="mailto:dlestrat@apache.org">David Le Strat</a>
28   */
29  public class InternalUserPrincipalImpl extends InternalPrincipalImpl implements InternalUserPrincipal
30  {
31      /*** The serial version uid. */
32      private static final long serialVersionUID = 6713096308414915156L;
33  
34      /*** <p>User principal security class.</p> */
35      static String USER_PRINCIPAL_CLASSNAME = "org.apache.jetspeed.security.InternalUserPrincipalImpl";
36      
37      /*** The credentials. */
38      private Collection credentials;
39      
40      /*** The role principals. */
41      private Collection rolePrincipals;
42      
43      /*** The group principals. */
44      private Collection groupPrincipals;
45  
46      /***
47       * <p>InternalUserPrincipal implementation default constructor.</p>
48       */
49      public InternalUserPrincipalImpl()
50      {
51          super();
52      }
53      
54      /***
55       * <p>Constructor to create a new user principal and its credential given
56       * a username and password.</p>
57       * @param username The username.
58       */
59      public InternalUserPrincipalImpl(String username)
60      {
61          super(USER_PRINCIPAL_CLASSNAME, username);
62          this.rolePrincipals = new ArrayList();
63          this.groupPrincipals = new ArrayList();
64      }
65  
66      /***
67       * @see org.apache.jetspeed.security.om.InternalUserPrincipal#getCredentials()
68       */
69      public Collection getCredentials()
70      {
71          return this.credentials;
72      }
73  
74      /***
75       * @see org.apache.jetspeed.security.om.InternalUserPrincipal#setCredentials(java.util.Collection)
76       */
77      public void setCredentials(Collection credentials)
78      {
79          this.credentials = credentials;
80      }
81  
82      /***
83       * @see org.apache.jetspeed.security.om.InternalUserPrincipal#getRolePrincipals()
84       */
85      public Collection getRolePrincipals()
86      {
87          return this.rolePrincipals;
88      }
89  
90      /***
91       * @see org.apache.jetspeed.security.om.InternalUserPrincipal#setRolePrincipals(java.util.Collection)
92       */
93      public void setRolePrincipals(Collection rolePrincipals)
94      {
95          this.rolePrincipals = rolePrincipals;
96      }
97  
98      /***
99       * @see org.apache.jetspeed.security.om.InternalUserPrincipal#getGroupPrincipals()
100      */
101     public Collection getGroupPrincipals()
102     {
103         return this.groupPrincipals;
104     }
105 
106     /***
107      * @see org.apache.jetspeed.security.om.InternalUserPrincipal#setGroupPrincipals(java.util.Collection)
108      */
109     public void setGroupPrincipals(Collection groupPrincipals)
110     {
111         this.groupPrincipals = groupPrincipals;
112     }
113 
114     /***
115      * <p>Compares this {@link InternalUserPrincipal} to the provided user principal
116      * and check if they are equal.</p>
117      * return Whether the {@link InternalUserPrincipal} are equal.
118      */
119     public boolean equals(Object object)
120     {  
121         if (!(object instanceof InternalUserPrincipal))
122             return false;
123 
124         InternalUserPrincipal r = (InternalUserPrincipal) object;
125         boolean isEqual = (r.getFullPath().equals(this.getFullPath()));
126         return isEqual;
127     }
128 
129 }