Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAYARA-3785 Security code cleaning sweep 6 #3920

Merged
merged 1 commit into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@

/**
* Security Deployer which generate and clean the security policies
*
* <p>
* This contains many JACC life cycle methods which can/should be moved to the JACC package
*
*/
@Service(name = "Security")
Expand Down Expand Up @@ -154,7 +157,7 @@ public void event(Event event) {

Set<WebBundleDescriptor> webBundleDescriptors = app.getBundleDescriptors(WebBundleDescriptor.class);
linkPolicies(app, webBundleDescriptors);
commitEjbs(app);
commitEjbPolicies(app);

if (webBundleDescriptors != null && !webBundleDescriptors.isEmpty()) {
// Register the WebSecurityComponentInvocationHandler
Expand All @@ -164,7 +167,7 @@ public void event(Event event) {
}
}
} else if (AFTER_SERVLET_CONTEXT_INITIALIZED_EVENT.equals(event.type())) {
commitPolicy((WebBundleDescriptor) event.hook());
commitWebPolicy((WebBundleDescriptor) event.hook());
}
}
};
Expand Down Expand Up @@ -234,11 +237,6 @@ public MetaData getMetaData() {
return new MetaData(false, null, new Class[] { Application.class });
}



// ### Private methods


/**
* Translate Web Bundle Policy
*
Expand All @@ -262,25 +260,32 @@ public void loadPolicy(WebBundleDescriptor webDescriptor, boolean remove) throws
throw new DeploymentException("Error in generating security policy for " + webDescriptor.getModuleDescriptor().getModuleName(), se);
}
}



// ### Private methods


/**
* Puts Web Bundle Policy In Service, repeats translation is Descriptor indicate policy was changed by ContextListener.
*
* @param webBundleDescriptor
* @throws DeploymentException
*/
private void commitPolicy(WebBundleDescriptor webBundleDescriptor) throws DeploymentException {
private void commitWebPolicy(WebBundleDescriptor webBundleDescriptor) throws DeploymentException {
try {
if (webBundleDescriptor != null) {
if (webBundleDescriptor.isPolicyModified()) {
// redo policy translation for web module
loadPolicy(webBundleDescriptor, true);
}
String cid = SecurityUtil.getContextID(webBundleDescriptor);
websecurityProbeProvider.policyCreationStartedEvent(cid);
SecurityUtil.generatePolicyFile(cid);
websecurityProbeProvider.policyCreationEndedEvent(cid);
websecurityProbeProvider.policyCreationEvent(cid);

String contextId = SecurityUtil.getContextID(webBundleDescriptor);

websecurityProbeProvider.policyCreationStartedEvent(contextId);
SecurityUtil.generatePolicyFile(contextId);
websecurityProbeProvider.policyCreationEndedEvent(contextId);
websecurityProbeProvider.policyCreationEvent(contextId);

}
} catch (Exception se) {
Expand All @@ -295,15 +300,15 @@ private void commitPolicy(WebBundleDescriptor webBundleDescriptor) throws Deploy
*
* @param ejbs
*/
private void commitEjbs(Application app) throws DeploymentException {
Set<EjbBundleDescriptor> ejbDescriptors = app.getBundleDescriptors(EjbBundleDescriptor.class);
private void commitEjbPolicies(Application app) throws DeploymentException {
try {
for (EjbBundleDescriptor ejbBD : ejbDescriptors) {
String pcid = SecurityUtil.getContextID(ejbBD);
ejbProbeProvider.policyCreationStartedEvent(pcid);
SecurityUtil.generatePolicyFile(pcid);
ejbProbeProvider.policyCreationEndedEvent(pcid);
ejbProbeProvider.policyCreationEvent(pcid);
for (EjbBundleDescriptor ejbBD : app.getBundleDescriptors(EjbBundleDescriptor.class)) {
String contextId = SecurityUtil.getContextID(ejbBD);

ejbProbeProvider.policyCreationStartedEvent(contextId);
SecurityUtil.generatePolicyFile(contextId);
ejbProbeProvider.policyCreationEndedEvent(contextId);
ejbProbeProvider.policyCreationEvent(contextId);

}
} catch (Exception se) {
Expand Down Expand Up @@ -415,6 +420,30 @@ public static List<EventTypes> getDeploymentEvents() {
return events;
}

private void handleCNonceCacheBSInit(String appName, Set<WebBundleDescriptor> webDesc, boolean isHA) {
boolean hasDigest = false;
for (WebBundleDescriptor webBD : webDesc) {
LoginConfiguration lc = webBD.getLoginConfiguration();
if (lc != null && LoginConfiguration.DIGEST_AUTHENTICATION.equals(lc.getAuthenticationMethod())) {
hasDigest = true;
break;
}
}
if (!hasDigest) {
return;
}
// initialize the backing stores as well for cnonce cache.
if (isHaEnabled() && isHA) {
final String clusterName = haUtil.getClusterName();
final String instanceName = haUtil.getInstanceName();
if (cnonceCacheFactory != null) {
CNonceCache cache = cnonceCacheFactory.createCNonceCache(appName, clusterName, instanceName, HA_CNONCE_BS_NAME);
this.appCnonceMap.put(appName, cache);
}

}
}

private boolean isHaEnabled() {
boolean haEnabled = false;
// lazily init the required services instead of
Expand All @@ -439,28 +468,4 @@ private boolean isHaEnabled() {

return haEnabled;
}

private void handleCNonceCacheBSInit(String appName, Set<WebBundleDescriptor> webDesc, boolean isHA) {
boolean hasDigest = false;
for (WebBundleDescriptor webBD : webDesc) {
LoginConfiguration lc = webBD.getLoginConfiguration();
if (lc != null && LoginConfiguration.DIGEST_AUTHENTICATION.equals(lc.getAuthenticationMethod())) {
hasDigest = true;
break;
}
}
if (!hasDigest) {
return;
}
// initialize the backing stores as well for cnonce cache.
if (isHaEnabled() && isHA) {
final String clusterName = haUtil.getClusterName();
final String instanceName = haUtil.getInstanceName();
if (cnonceCacheFactory != null) {
CNonceCache cache = cnonceCacheFactory.createCNonceCache(appName, clusterName, instanceName, HA_CNONCE_BS_NAME);
this.appCnonceMap.put(appName, cache);
}

}
}
}
Loading