if (internal.match(url)) {
//Authentication vars
String repositoryID = null;
AuthenticationProcessImpl authProcess = null;
ValveRepositoryConfiguration repositoryConfig = null;
int order = 1;
int size = authenticationImplementationsOrder.size();
if (authenticationImplementationsOrder == null) {
order = 0;
logger.error("No Authentication module has been defined. Please check and add those needed at config file");
}
while ((1 <= order) && (order <= size)) {
//Get the repository ID
logger.debug("###Processing repository # " + order + " ###");
Integer orderInt = new Integer(order);
if (authenticationImplementationsOrder.containsKey(orderInt)) {
repositoryID =
authenticationImplementationsOrder.get(orderInt);
} else {
logger.error("Error during processing authentication methods. Order is not valid");
break;
}
//Get the Repository config and authentication class
authProcess = authenticationImplementations.get(repositoryID);
repositoryConfig = valveConf.getRepository(repositoryID);
logger.debug("Authenticating ID: " + repositoryConfig.getId());
if (repositoryConfig.getId().equals("root")) {
//Root should be used for main authentication against an identity repository (LDAP, DB, ..)
//and should not be used as a content repository that contains documents
try {
//add support to cookie array
rootAuthCookies.clear();
rootStatusCode =
authProcess.authenticate(request, response,
rootAuthCookies, url,
creds, "root");
logger.info("Repository authentication - " +
repositoryConfig.getId() +
" completed. Response was " +
rootStatusCode);
if (rootStatusCode ==
HttpServletResponse.SC_UNAUTHORIZED) {
logger.error("Root AuthN failed");
} else {
//Support to cookie array
if (rootStatusCode == HttpServletResponse.SC_OK) {
logger.debug("Root AuthN is SC_OK (200)");
if (!rootAuthCookies.isEmpty()) {
logger.debug("Root AuthN returns cookies");
for (int j = 0; j < rootAuthCookies.size();
j++) {
logger.debug("Root Cookie found: " +
rootAuthCookies.elementAt(j).getName() +
":" +
rootAuthCookies.elementAt(j).getValue());
authCookies.add(rootAuthCookies.elementAt(j));
}
} else {
logger.debug("Root AuthN does NOT return cookies");
}
}
}
//If no repository is defined called root then rootStatusCode must be set to OK
// This flag is used to indicate that a root repository has been defined.
rootAuthNDefined = true;
//
} catch (Exception e) {
logger.debug("Exception with authentication for ID: " +
repositoryConfig.getId() + " - " +
e.getMessage());
rootAuthNDefined = true;
}
} else {
try {
//add support to cookie array
repositoryAuthCookies.clear();
logger.debug("Let's do the authentication");
repositoryAuthStatusCode =
authProcess.authenticate(request, response,
repositoryAuthCookies,
url, creds,
repositoryConfig.getId());
//add support to cookie array
if (repositoryAuthStatusCode ==
HttpServletResponse.SC_OK) {
logger.debug("Repository AuthN [" +
repositoryConfig.getId() +
"] is SC_OK (200)");
//check if multiple repository is set to valid
if (repositoryOKAuthN == false) {
repositoryOKAuthN = true;
}
//check if cookie array is not empty and consume it
if (!repositoryAuthCookies.isEmpty()) {
logger.debug("Repository AuthN [" +
repositoryConfig.getId() +
"] returns " +
repositoryAuthCookies.size() +
" cookies");
for (int j = 0;
j < repositoryAuthCookies.size(); j++) {
logger.debug("Repository Cookie found: " +
repositoryAuthCookies.elementAt(j).getName() +
":" +
repositoryAuthCookies.elementAt(j).getValue());
authCookies.add(repositoryAuthCookies.elementAt(j));
}
} else {
logger.debug("Repository AuthN [" +
repositoryConfig.getId() +
"] does NOT return cookies");
}
}
//end Krb support
logger.info("Repository authentication - " +
repositoryConfig.getId() +
" completed. Response was " +
repositoryAuthStatusCode);
} catch (Exception e) {
logger.debug("Exception with authentication for ID: " +
repositoryConfig.getId() + " - " +
e.getMessage());
}
}
//increase order