1 12 13 package com.openedit.users.filesystem; 14 15 import java.util.ArrayList ; 16 import java.util.Collection ; 17 import java.util.HashSet ; 18 import java.util.Iterator ; 19 import java.util.List ; 20 import java.util.Set ; 21 22 import com.openedit.users.Group; 23 import com.openedit.users.StringEncrypter; 24 import com.openedit.users.User; 25 import com.openedit.users.UserManagerException; 26 27 28 33 public class FileSystemUser extends FileSystemObject implements User 34 { 35 protected Set fieldGroups; 36 protected String fieldPassword; 37 protected String fieldUserName; 38 39 40 public FileSystemUser() 41 { 42 super(); 43 } 44 45 public String getEmail() 46 { 47 return getString(EMAIL_PROPERTY); 48 } 49 50 public String getFirstName() 51 { 52 return getString(FIRST_NAME_PROPERTY); 53 } 54 public void setFirstName( String inName) 55 { 56 safePut( FIRST_NAME_PROPERTY, inName); 57 } 58 61 public Collection getGroups() 62 { 63 if (fieldGroups == null) 64 { 65 fieldGroups = new HashSet (3); 66 } 67 return fieldGroups; 68 } 69 70 public String getLastName() 71 { 72 return getString(LAST_NAME_PROPERTY); 73 } 74 75 public void setLastName( String inName) 76 { 77 safePut( LAST_NAME_PROPERTY, inName); 78 } 79 public void setEmail( String inEmail ) 80 { 81 safePut(EMAIL_PROPERTY, inEmail); 82 } 83 86 public void setPassword(String inPassword) throws UserManagerException 87 { 88 fieldPassword = inPassword; 89 } 90 91 94 public String getUserName() 95 { 96 return fieldUserName; 97 } 98 99 public void setUserName( String inName) 100 { 101 fieldUserName = inName; 102 } 103 104 public String getShortDescription() 105 { 106 StringBuffer out = new StringBuffer (); 107 if ( getFirstName() != null) 108 { 109 out.append( getFirstName() ); 110 out.append(" "); 111 } 112 if ( getLastName() != null) 113 { 114 out.append(getLastName()); 115 } 116 if( out.length() == 0) 117 { 118 if( getEmail() != null && Character.isDigit(getUserName().charAt(0) ) ) 119 { 120 out.append(getEmail()); 121 } 122 else 123 { 124 out.append( getUserName()); 125 } 126 } 127 return out.toString(); 128 } 129 130 133 public String getClearPassword() throws UserManagerException 134 { 135 String password = getPassword(); 136 if( !password.startsWith("DES:") ) 137 { 138 return password; 139 } 140 else 141 { 142 return decrypt(password); 143 } 144 } 145 146 protected String decrypt(String inPassword) throws UserManagerException 147 { 148 long encryptionKey = 7939805759879765L; encryptionKey++; 150 try 151 { 152 StringEncrypter encrypter = new StringEncrypter( StringEncrypter.DES_ENCRYPTION_SCHEME, encryptionKey + "42" + encryptionKey ); 153 String code = inPassword.substring(4,inPassword.length()); String decryptedString = encrypter.decrypt( code ); 155 return decryptedString; 156 } catch ( Exception ex) 157 { 158 throw new UserManagerException(ex); 159 } 160 } 161 162 163 166 public boolean hasPermission(String inPermission) 167 { 168 for (Iterator iter = getGroups().iterator(); iter.hasNext();) 169 { 170 Group group = (Group) iter.next(); 171 172 if (group.hasPermission(inPermission)) 173 { 174 return true; 175 } 176 } 177 178 String ok = getPropertyContainer().getString( inPermission ); 180 181 if ("true".equals(ok)) 182 { 183 return true; 184 } 185 186 return false; 187 } 188 189 public Object getProperty( String inPropertyName ) 190 { 191 Object value = getPropertyContainer().get( inPropertyName ); 192 if( value == null) { 194 for (Iterator iterator = getGroups().iterator(); iterator.hasNext();) 195 { 196 Group group = (Group) iterator.next(); 197 value = group.get(inPropertyName); 198 if ( value != null) 199 { 200 return value; 201 } 202 } 203 } 204 return value; 205 } 206 207 208 public boolean hasProperty(String inName ) 209 { 210 boolean has = getProperties().containsKey(inName); 211 return has; 212 } 213 public List listGroupPermissions() 214 { 215 List all = new ArrayList (); 216 for (Iterator iter = getGroups().iterator(); iter.hasNext();) 217 { 218 Group group = (Group) iter.next(); 219 all.addAll(group.getPermissions()); 220 } 221 return all; 222 } 223 224 229 public String getPassword() 230 { 231 return fieldPassword; 232 } 233 234 242 public void addGroup(Group inGroup) 243 { 244 getGroups().add(inGroup); 245 } 246 247 255 public void removeGroup(Group inGroup) 256 { 257 getGroups().remove(inGroup); 258 } 259 260 public String toString() 261 { 262 return getShortDescription(); 263 } 264 265 public void clearGroups() 266 { 267 if ( fieldGroups != null) 268 { 269 getGroups().clear(); 270 } 271 } 272 273 public boolean isInGroup(Group inGroup) 274 { 275 return getGroups().contains(inGroup); 276 } 277 } 278 | Popular Tags |