throws AuthException
{
//Control Flag behavior
boolean encounteredRequiredError = false;
boolean encounteredOptionalError = false;
AuthException moduleException = null;
AuthStatus overallDecision = AuthStatus.FAILURE;
int length = modules.size();
for(int i = 0; i < length; i++)
{
ServerAuthModule module = (ServerAuthModule)modules.get(i);
ControlFlag flag = (ControlFlag)this.controlFlags.get(i);
AuthStatus decision = AuthStatus.FAILURE;
try
{
decision = module.validateRequest(messageInfo, clientSubject, serviceSubject);
}
catch(Exception ae)
{
decision = AuthStatus.FAILURE;
if(moduleException == null)
moduleException = new AuthException(ae.getMessage());
}
if(decision == AuthStatus.SUCCESS)
{
overallDecision = AuthStatus.SUCCESS;
//SUFFICIENT case
if(flag == ControlFlag.SUFFICIENT && encounteredRequiredError == false)
return AuthStatus.SUCCESS;
continue; //Continue with the other modules
}
//Go through the failure cases
//REQUISITE case
if(flag == ControlFlag.REQUISITE)
{
if(trace)
log.trace("REQUISITE failed for " + module);
if(moduleException == null)
moduleException = new AuthException("Auth failed");
else
throw moduleException;
}
//REQUIRED Case
if(flag == ControlFlag.REQUIRED)
{
if(trace)
log.trace("REQUIRED failed for " + module);
if(encounteredRequiredError == false)
encounteredRequiredError = true;
}
if(flag == ControlFlag.OPTIONAL)
encounteredOptionalError = true;
}
//All the authorization modules have been visited.
String msg = getAdditionalErrorMessage(moduleException);
if(encounteredRequiredError)
throw new AuthException("Auth Failed:"+ msg);
if(overallDecision == AuthStatus.FAILURE && encounteredOptionalError)
throw new AuthException("Auth Failed:" + msg);
if(overallDecision == AuthStatus.FAILURE)
throw new AuthException("Auth Failed:Denied.");
return AuthStatus.SUCCESS;
}