aslcore/src/org/gcube/application/framework/core/security/LDAPAuthenticationModule.java

149 lines
4.9 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;
import org.gcube.application.framework.core.util.UserCredential;
import org.gcube.vomanagement.vomsapi.ExtendedVOMSAdmin;
import org.gcube.vomanagement.vomsapi.VOMSAdmin;
import org.gridforum.jgss.ExtendedGSSCredential;
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();
// Check user's credential
ExtendedGSSCredential cred = UserCredential.getPlainCredential(username, password);
System.out.println("Getting credential from VOMS");
if (cred == null) {
System.out.println("The credential does NOT exist");
throw new Exception("key4", e);
} else {
System.out.println("The credential is OK!!!!!!!!!!!!");
return true;
}
} catch (LoginException e) {
e.printStackTrace();
// Check user's credential
ExtendedGSSCredential cred = UserCredential.getPlainCredential(username, password);
System.out.println("Getting credential from VOMS");
if (cred == null) {
System.out.println("The credential does NOT exist");
throw new Exception("key4", e);
} else {
System.out.println("The credential is OK!!!!!!!!!!!!");
return true;
}
}
// Attempt login
try {
loginContext.login();
} catch (FailedLoginException e) {
// Check user's credential
ExtendedGSSCredential cred = UserCredential.getPlainCredential(username, password);
// throw new Exception("key4", e);
if (cred == null) {
e.printStackTrace();
System.out.println("The credential is NULL!!!!!!!!!!!!");
return false;
} else {
System.out.println("The credential is OK!!!!!!!!!!!!");
return true;
}
} catch (AccountExpiredException e) {
// Check user's credential
ExtendedGSSCredential cred = UserCredential.getPlainCredential(username, password);
// throw new Exception("key4", e);
if (cred == null) {
e.printStackTrace();
System.out.println("The credential is NULL!!!!!!!!!!!!");
return false;
} else {
System.out.println("The credential is OK!!!!!!!!!!!!");
return true;
}
} catch (CredentialExpiredException e) {
// Check user's credential
ExtendedGSSCredential cred = UserCredential.getPlainCredential(username, password);
// throw new Exception("key4", e);
if (cred == null) {
e.printStackTrace();
System.out.println("The credential is NULL!!!!!!!!!!!!");
return false;
} else {
System.out.println("The credential is OK!!!!!!!!!!!!");
return true;
}
} catch (Exception e) {
// Check user's credential
ExtendedGSSCredential cred = UserCredential.getPlainCredential(username, password);
// throw new Exception("key4", e);
if (cred == null) {
e.printStackTrace();
System.out.println("The credential is NULL!!!!!!!!!!!!");
return false;
} else {
System.out.println("The credential is OK!!!!!!!!!!!!");
return true;
}
}
System.out.println("ASL returning value true");
return true;
// Check user's credential
// ExtendedGSSCredential cred = UserCredential.getPlainCredential(username, password);
//
// System.out.println("Getting credential from VOMS");
// if (cred == null) {
// System.out.println("The credential does NOT exist");
// return false;
// } else {
// System.out.println("The credential is OK!!!!!!!!!!!!");
// return true;
// }
}
}