1 21 22 package org.apache.derby.impl.jdbc.authentication; 23 24 import org.apache.derby.iapi.reference.MessageId; 25 import org.apache.derby.iapi.reference.Attribute; 26 import org.apache.derby.authentication.UserAuthenticator; 27 import org.apache.derby.iapi.services.property.PropertyUtil; 28 import org.apache.derby.iapi.services.daemon.Serviceable; 29 import org.apache.derby.iapi.services.monitor.ModuleFactory; 30 import org.apache.derby.iapi.services.monitor.Monitor; 31 import org.apache.derby.iapi.services.sanity.SanityManager; 32 import org.apache.derby.iapi.error.StandardException; 33 import org.apache.derby.iapi.services.i18n.MessageService; 34 import org.apache.derby.iapi.store.access.TransactionController; 35 import org.apache.derby.iapi.jdbc.AuthenticationService; 36 import org.apache.derby.iapi.util.StringUtil; 37 38 import java.util.Properties ; 39 import java.security.MessageDigest ; 41 import java.security.NoSuchAlgorithmException ; 42 import java.io.Serializable ; 43 import java.util.Dictionary ; 44 45 61 public final class BasicAuthenticationServiceImpl 62 extends AuthenticationServiceBase implements UserAuthenticator { 63 64 68 71 public boolean canSupport(Properties properties) { 72 73 if (!requireAuthentication(properties)) 74 return false; 75 76 86 String authenticationProvider = PropertyUtil.getPropertyFromSet( 87 properties, 88 org.apache.derby.iapi.reference.Property.AUTHENTICATION_PROVIDER_PARAMETER); 89 90 if ( (authenticationProvider != null) && 91 (authenticationProvider.length() != 0) && 92 (!(StringUtil.SQLEqualsIgnoreCase(authenticationProvider, 93 org.apache.derby.iapi.reference.Property.AUTHENTICATION_PROVIDER_BUILTIN)))) 94 return false; 95 else 96 return true; } 98 99 104 public void boot(boolean create, Properties properties) 105 throws StandardException { 106 107 110 super.boot(create, properties); 112 113 try { 121 MessageDigest digestAlgorithm = MessageDigest.getInstance("SHA-1"); 122 digestAlgorithm.reset(); 123 124 } catch (NoSuchAlgorithmException nsae) { 125 throw Monitor.exceptionStartingModule(nsae); 126 } 127 128 this.setAuthenticationService(this); 132 } 133 134 137 138 146 public boolean authenticateUser(String userName, 147 String userPassword, 148 String databaseName, 149 Properties info 150 ) 151 { 152 String clientSecurityMechanism = null; 156 int secMec = 0; 159 160 if (userName == null) 166 return false; 168 169 String definedUserPassword = null, passedUserPassword = null; 170 171 if ((clientSecurityMechanism = 180 info.getProperty(Attribute.CLIENT_SECURITY_MECHANISM)) != null) 181 { 182 secMec = Integer.parseInt(clientSecurityMechanism); 183 } 184 185 String userNameProperty = 192 org.apache.derby.iapi.reference.Property.USER_PROPERTY_PREFIX.concat( 193 userName); 194 195 definedUserPassword = getDatabaseProperty(userNameProperty); 197 198 if (definedUserPassword != null) 199 { 200 if (secMec != SECMEC_USRSSBPWD) 201 { 202 passedUserPassword = encryptPassword(userPassword); 204 } 205 else 206 { 207 definedUserPassword = substitutePassword(userName, 212 definedUserPassword, 213 info, true); 214 passedUserPassword = userPassword; 217 } 218 } 219 else 220 { 221 definedUserPassword = getSystemProperty(userNameProperty); 223 passedUserPassword = userPassword; 224 225 if ((definedUserPassword != null) && 226 (secMec == SECMEC_USRSSBPWD)) 227 { 228 definedUserPassword = substitutePassword(userName, 230 definedUserPassword, 231 info, false); 232 } 233 } 234 235 if (definedUserPassword == null) 236 return false; 238 239 if (!definedUserPassword.equals(passedUserPassword)) 241 return false; 242 243 247 return true; 249 } 250 } 251 | Popular Tags |