@Override
public void lifecycleEvent(LifecycleEvent lifecycleEvent) {
String lifecycleEventType = lifecycleEvent.getType();
if (lifecycleEventType.equals(Lifecycle.BEFORE_START_EVENT)) {
//Initialize SpecSecurityBuilder
SpecSecurityBuilder specSecurityBuilder = new SpecSecurityBuilder(bundle, deploymentDescriptor, annotationScanRequired);
GeronimoStandardContext standardContext = (GeronimoStandardContext) lifecycleEvent.getSource();
GeronimoApplicationContext applicationContext = (GeronimoApplicationContext) standardContext.getInternalServletContext();
applicationContext.setSpecSecurityBuilder(specSecurityBuilder);
} else if (lifecycleEventType.equals(Lifecycle.START_EVENT)) {
GeronimoStandardContext standardContext = (GeronimoStandardContext) lifecycleEvent.getSource();
GeronimoApplicationContext applicationContext = (GeronimoApplicationContext) standardContext.getInternalServletContext();
//Calculate the final Security Permissions
SpecSecurityBuilder specSecurityBuilder = applicationContext.getSpecSecurityBuilder();
Map<String, ComponentPermissions> contextIdPermissionsMap = new HashMap<String, ComponentPermissions>();
contextIdPermissionsMap.put(contextId, specSecurityBuilder.buildSpecSecurityConfig());
//Update ApplicationPolicyConfigurationManager
try {
applicationPolicyConfigurationManager.updateApplicationPolicyConfiguration(contextIdPermissionsMap);
} catch (LoginException e) {
logger.error("Fail to set application policy configurations", e);
throw new RuntimeException("Fail to set application policy configurations", e);
} catch (PolicyContextException e) {
logger.error("Fail to set application policy configurations", e);
throw new RuntimeException("Fail to set application policy configurations", e);
} catch (ClassNotFoundException e) {
logger.error("Fail to set application policy configurations", e);
throw new RuntimeException("Fail to set application policy configurations", e);
} finally {
//Clear SpecSecurityBuilder
specSecurityBuilder.clear();
applicationContext.setSpecSecurityBuilder(null);
}
}
}