throws AuthorizationException
{
//Control Flag behavior
boolean encounteredRequiredError = false;
boolean encounteredOptionalError = false;
AuthorizationException moduleException = null;
int overallDecision = DENY;
int length = modules.size();
for(int i = 0; i < length; i++)
{
AuthorizationModule module = (AuthorizationModule)modules.get(i);
ControlFlag flag = (ControlFlag)this.controlFlags.get(i);
int decision = DENY;
try
{
decision = module.authorize(resource);
}
catch(Exception ae)
{
decision = DENY;
if(moduleException == null)
moduleException = new AuthorizationException(ae.getMessage());
}
if(decision == PERMIT)
{
overallDecision = PERMIT;
//SUFFICIENT case
if(flag == ControlFlag.SUFFICIENT && encounteredRequiredError == false)
return PERMIT;
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 AuthorizationException("Authorization 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 AuthorizationException("Authorization Failed:"+ msg);
if(overallDecision == DENY && encounteredOptionalError)
throw new AuthorizationException("Authorization Failed:" + msg);
if(overallDecision == DENY)
throw new AuthorizationException("Authorization Failed:No modules active.");
return PERMIT;
}