160 lines
5.1 KiB
Java
160 lines
5.1 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.gridforum.jgss.ExtendedGSSCredential;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
/**
|
|
* FOR THE MOMENT IT'S SOMEWHAT DUMMY... WAITING FOR THE NEW SECURITY MODEL TO BE COMPLETED AND THEN INTEGRATE IT HERE
|
|
*
|
|
* @author nikolas
|
|
*
|
|
*/
|
|
public class LDAPAuthenticationModule {
|
|
|
|
/** The logger. */
|
|
private static final Logger logger = LoggerFactory.getLogger(LDAPAuthenticationModule.class);
|
|
|
|
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 {
|
|
|
|
logger.debug("The new security model should be integrated in ASL");
|
|
return true;
|
|
|
|
|
|
/*
|
|
logger.info("beginning authentication for " + username);
|
|
|
|
LoginContext loginContext;
|
|
|
|
// Create the LoginContext
|
|
try {
|
|
loginContext = new LoginContext(contextName, new JaasCallbackHandler(username, password));
|
|
} catch (SecurityException e) {
|
|
logger.error("Exception:", e);
|
|
// Check user's credential
|
|
ExtendedGSSCredential cred = UserCredential.getPlainCredential(username, password);
|
|
|
|
logger.info("Getting credential from VOMS");
|
|
if (cred == null) {
|
|
logger.info("The credential does NOT exist");
|
|
throw new Exception("key4", e);
|
|
} else {
|
|
logger.info("The credential is OK!!!!!!!!!!!!");
|
|
return true;
|
|
}
|
|
|
|
} catch (LoginException e) {
|
|
logger.error("Exception:", e);
|
|
// Check user's credential
|
|
ExtendedGSSCredential cred = UserCredential.getPlainCredential(username, password);
|
|
|
|
logger.info("Getting credential from VOMS");
|
|
if (cred == null) {
|
|
logger.info("The credential does NOT exist");
|
|
throw new Exception("key4", e);
|
|
} else {
|
|
logger.info("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) {
|
|
logger.error("Exception:", e);
|
|
logger.info("The credential is NULL!!!!!!!!!!!!");
|
|
return false;
|
|
} else {
|
|
logger.info("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) {
|
|
logger.error("Exception:", e);
|
|
logger.info("The credential is NULL!!!!!!!!!!!!");
|
|
return false;
|
|
} else {
|
|
logger.info("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) {
|
|
logger.error("Exception:", e);
|
|
logger.info("The credential is NULL!!!!!!!!!!!!");
|
|
return false;
|
|
} else {
|
|
logger.info("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) {
|
|
logger.error("Exception:", e);
|
|
logger.info("The credential is NULL!!!!!!!!!!!!");
|
|
return false;
|
|
} else {
|
|
logger.info("The credential is OK!!!!!!!!!!!!");
|
|
return true;
|
|
}
|
|
}
|
|
logger.info("ASL returning value true");
|
|
return true;
|
|
|
|
// Check user's credential
|
|
// ExtendedGSSCredential cred = UserCredential.getPlainCredential(username, password);
|
|
//
|
|
// logger.info("Getting credential from VOMS");
|
|
// if (cred == null) {
|
|
// logger.info("The credential does NOT exist");
|
|
// return false;
|
|
// } else {
|
|
// logger.info("The credential is OK!!!!!!!!!!!!");
|
|
// return true;
|
|
// }
|
|
|
|
*/
|
|
}
|
|
|
|
|
|
}
|