73 lines
2.0 KiB
Java
73 lines
2.0 KiB
Java
package org.gcube.application.framework.core.security;
|
|
|
|
|
|
import javax.security.auth.login.AccountExpiredException;
|
|
import javax.security.auth.login.CredentialExpiredException;
|
|
import javax.security.auth.login.FailedLoginException;
|
|
import javax.security.auth.login.LoginContext;
|
|
import javax.security.auth.login.LoginException;
|
|
|
|
|
|
|
|
|
|
public class LDAPAuthenticationModule {
|
|
|
|
public static String LDAP_HOST = "LDAP_HOST";
|
|
public static String BASE_DN = "BASE_DN";
|
|
|
|
|
|
private String contextName = "Gridsphere";
|
|
//private String contextName = "AslLoginConf";
|
|
|
|
public LDAPAuthenticationModule () {
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
public boolean checkAuthentication(String username, String password) throws Exception {
|
|
|
|
System.out.println("beginning authentication for " + username);
|
|
System.out.println("I am in ASL");
|
|
|
|
|
|
LoginContext loginContext;
|
|
|
|
// Create the LoginContext
|
|
try {
|
|
loginContext = new LoginContext(contextName, new JaasCallbackHandler(username, password));
|
|
} catch (SecurityException e) {
|
|
e.printStackTrace();
|
|
throw new Exception("key4", e);
|
|
} catch (LoginException e) {
|
|
e.printStackTrace();
|
|
throw new Exception("key4", e);
|
|
}
|
|
|
|
// Attempt login
|
|
try {
|
|
loginContext.login();
|
|
} catch (FailedLoginException e) {
|
|
// throw new Exception("key4", e);
|
|
e.printStackTrace();
|
|
return false;
|
|
} catch (AccountExpiredException e) {
|
|
//throw new Exception("key1");
|
|
e.printStackTrace();
|
|
return false;
|
|
} catch (CredentialExpiredException e) {
|
|
// throw new Exception("key2", e);
|
|
e.printStackTrace();
|
|
return false;
|
|
} catch (Exception e) {
|
|
// throw new Exception("key3", e);
|
|
return false;
|
|
}
|
|
System.out.println("ASL returning value true");
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
}
|