1 17 package org.alfresco.filesys.server.auth; 18 19 import java.util.Random ; 20 21 import org.alfresco.config.ConfigElement; 22 import org.alfresco.filesys.server.SrvSession; 23 import org.alfresco.filesys.server.config.InvalidConfigurationException; 24 import org.alfresco.filesys.server.config.ServerConfiguration; 25 import org.alfresco.filesys.server.core.ShareType; 26 import org.alfresco.filesys.server.core.SharedDevice; 27 import org.alfresco.filesys.smb.server.SMBSrvSession; 28 import org.alfresco.filesys.util.DataPacker; 29 30 41 public class LocalAuthenticator extends SrvAuthenticator 42 { 43 44 46 private Random m_random = new Random (System.currentTimeMillis()); 47 48 50 private ServerConfiguration m_config; 51 52 57 public LocalAuthenticator() 58 { 59 setAccessMode(SrvAuthenticator.USER_MODE); 60 setEncryptedPasswords(true); 61 } 62 63 72 public int authenticateShareConnect(ClientInfo client, SharedDevice share, String pwd, SrvSession sess) 73 { 74 75 77 if (this.getAccessMode() == SHARE_MODE) 78 return SrvAuthenticator.Writeable; 79 80 82 if (share.getType() == ShareType.ADMINPIPE) 83 return SrvAuthenticator.Writeable; 84 85 93 UserAccount user = null; 94 if (client != null) 95 user = getUserDetails(client.getUserName()); 96 97 if (user == null) 98 { 99 100 102 return allowGuest() ? SrvAuthenticator.Writeable : SrvAuthenticator.NoAccess; 103 } 104 else if (user.hasShare(share.getName()) == false) 105 return SrvAuthenticator.NoAccess; 106 107 109 return SrvAuthenticator.Writeable; 110 } 111 112 119 public int authenticateUser(ClientInfo client, SrvSession sess, int alg) 120 { 121 122 124 UserAccount userAcc = getUserDetails(client.getUserName()); 125 if (userAcc != null) 126 { 127 128 130 boolean authSts = false; 131 132 if (client.getPassword() != null) 133 { 134 135 137 authSts = validatePassword(userAcc.getPassword(), client.getPassword(), sess.getChallengeKey(), alg); 138 } 139 else if (client.hasANSIPassword()) 140 { 141 142 144 authSts = validatePassword(userAcc.getPassword(), client.getANSIPassword(), sess.getChallengeKey(), 145 SrvAuthenticator.LANMAN); 146 } 147 148 150 return authSts == true ? SrvAuthenticator.AUTH_ALLOW : SrvAuthenticator.AUTH_BADPASSWORD; 151 } 152 153 157 if (client.isNullSession() && sess instanceof SMBSrvSession) 158 return SrvAuthenticator.AUTH_ALLOW; 159 160 162 return allowGuest() ? SrvAuthenticator.AUTH_GUEST : SrvAuthenticator.AUTH_DISALLOW; 163 } 164 165 171 public byte[] getChallengeKey(SrvSession sess) 172 { 173 174 176 byte[] key = new byte[8]; 177 178 DataPacker.putIntelLong(m_random.nextLong(), key, 0); 179 return key; 180 } 181 182 188 public UserAccount getUserDetails(String user) 189 { 190 191 193 UserAccountList userList = m_config.getUserAccounts(); 194 if (userList == null || userList.numberOfUsers() == 0) 195 return null; 196 197 199 return userList.findUser(user); 200 } 201 202 209 public void initialize(ServerConfiguration config, ConfigElement params) throws InvalidConfigurationException 210 { 211 212 214 m_config = config; 215 } 216 } | Popular Tags |