KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > wsm > axis > security > model > MemoryUserImpl


1 package org.apache.beehive.wsm.axis.security.model;
2
3 /*
4  * DropInDeploymentHandler.java
5  *
6  * Copyright 2001-2004 The Apache Software Foundation.
7  *
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */

22
23 import java.util.Collection JavaDoc;
24 import java.util.Hashtable JavaDoc;
25 import java.util.Map JavaDoc;
26
27 import org.apache.commons.codec.digest.DigestUtils;
28
29 import org.apache.beehive.wsm.axis.security.User;
30 import org.apache.beehive.wsm.axis.security.Group;
31 import org.apache.beehive.wsm.axis.security.UserList;
32 import org.apache.beehive.wsm.axis.security.Role;
33
34
35 public class MemoryUserImpl implements User {
36
37     private String JavaDoc name;
38     private String JavaDoc password;
39     private boolean md5;
40
41     private Map JavaDoc<String JavaDoc,Role> roles;
42     private Map JavaDoc<String JavaDoc,Group> groups;
43
44     public MemoryUserImpl ()
45     {
46         roles = new Hashtable JavaDoc<String JavaDoc,Role>();
47         groups = new Hashtable JavaDoc<String JavaDoc,Group>();
48     }
49
50     public void setName ( String JavaDoc name )
51     {
52         this.name = name;
53     }
54
55     public String JavaDoc getName ()
56     {
57         return name;
58     }
59
60     public void setPassword ( String JavaDoc password )
61     {
62         this.password = password;
63     }
64
65     public String JavaDoc getPassword ()
66     {
67         return password;
68     }
69
70     public void setMd5 ( boolean isMd5 )
71     {
72         this.md5 = isMd5;
73     }
74
75     public boolean isMd5 ()
76     {
77         return md5;
78     }
79
80     public boolean authenticate ( String JavaDoc password )
81     {
82         try{
83             if ( ( this.password == null ) && ( password == null ) ){
84                 // if both null, returns true; Probably a user intentionally set null for both.
85
return true;
86             }
87
88             if ( isMd5() )
89             {
90                 // todo: implement in case md5 is used.
91
if ( this.password.equals( DigestUtils.md5Hex(password)) )
92                     return true;
93             }
94             else
95             {
96                 if ( this.password.equals( password ) )
97                     return true;
98             }
99         }catch(NullPointerException JavaDoc npe){
100             return false;
101         }
102
103         return false;
104
105     }
106
107     public void addGroup( Group group )
108     {
109         groups.put(group.getName(), group);
110     }
111
112     public Group getGroup ( String JavaDoc group )
113     {
114         return groups.get(group);
115     }
116
117     public Collection JavaDoc<Group> getGroups ()
118     {
119         return groups.values();
120     }
121
122     public void addRole( Role role )
123     {
124         roles.put(role.getName(), role);
125     }
126
127     public Role getRole ( String JavaDoc role )
128     {
129         return roles.get(role);
130     }
131
132     public Collection JavaDoc<Role> getRoles ()
133     {
134         return roles.values();
135     }
136
137 }
138
Popular Tags