Skip to content

Commit

Permalink
Merge pull request wildfly#18479 from darranl/WFLY-20001
Browse files Browse the repository at this point in the history
[WFLY-20001] Switch to using PolicyUtil from Elytron EE to access java.security.Policy
  • Loading branch information
darranl authored Dec 11, 2024
2 parents 5f6455f + b3bf55e commit e23c04d
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<module name="org.jboss.as.controller"/>
<module name="org.jboss.as.naming" optional="true"/>
<module name="org.wildfly.security.elytron-private"/>
<module name="org.wildfly.security.jakarta.authorization"/>
<module name="org.wildfly.extension.request-controller" />
<module name="org.jboss.as.server" />
<module name="org.jboss.invocation"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
<module name="org.wildfly.http-client.ejb" services="import"/>
<module name="org.wildfly.iiop-openjdk"/>
<module name="org.wildfly.security.elytron-private"/>
<module name="org.wildfly.security.jakarta.authorization"/>
<module name="org.wildfly.service"/>
<module name="org.wildfly.subsystem"/>
<module name="org.wildfly.transaction.client"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<module name="org.wildfly.security.elytron-private"/>
<module name="org.wildfly.security.elytron-web.undertow-server"/>
<module name="org.wildfly.security.elytron-web.undertow-server-servlet"/>
<module name="org.wildfly.security.jakarta.authorization"/>
<module name="org.jboss.as.server"/>
<module name="org.jboss.common-beans" services="import"/>
<module name="org.jboss.marshalling"/>
Expand Down
4 changes: 4 additions & 0 deletions ee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@
<groupId>org.wildfly.security</groupId>
<artifactId>wildfly-elytron-security-manager-action</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.security.jakarta</groupId>
<artifactId>jakarta-authorization</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.transaction</groupId>
<artifactId>wildfly-transaction-client</artifactId>
Expand Down
5 changes: 2 additions & 3 deletions ee/src/main/java/org/jboss/as/ee/security/JaccService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

import static org.jboss.as.ee.logging.EeLogger.ROOT_LOGGER;
import static org.wildfly.common.Assert.checkNotNullParam;

import java.security.Policy;
import static org.wildfly.security.authz.jacc.PolicyUtil.getPolicyUtil;

import jakarta.security.jacc.PolicyConfiguration;
import jakarta.security.jacc.PolicyConfigurationFactory;
Expand Down Expand Up @@ -84,7 +83,7 @@ public void start(StartContext context) throws StartException {
policyConfiguration.commit();
}
// Allow the policy to incorporate the policy configs
Policy.getPolicy().refresh();
getPolicyUtil().refresh();
}
} catch (Exception e) {
throw ROOT_LOGGER.unableToStartException("JaccService", e);
Expand Down
5 changes: 5 additions & 0 deletions ejb3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ vi:ts=4:sw=4:expandtab
<artifactId>wildfly-elytron-security-manager-action</artifactId>
</dependency>

<dependency>
<groupId>org.wildfly.security.jakarta</groupId>
<artifactId>jakarta-authorization</artifactId>
</dependency>

<dependency>
<groupId>jakarta.transaction</groupId>
<artifactId>jakarta.transaction-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.Policy;
import java.security.Principal;
import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;
Expand Down Expand Up @@ -68,6 +67,7 @@
import org.wildfly.security.auth.server.SecurityDomain;
import org.wildfly.security.auth.server.SecurityIdentity;
import org.wildfly.security.authz.Roles;
import org.wildfly.security.authz.jacc.PolicyUtil;
import org.wildfly.security.manager.WildFlySecurityManager;
import org.wildfly.transaction.client.ContextTransactionManager;

Expand Down Expand Up @@ -423,9 +423,9 @@ public boolean isBeanManagedTransaction() {
public boolean isCallerInRole(final String roleName) throws IllegalStateException {
if (isSecurityDomainKnown()) {
if (enableJacc) {
Policy policy = WildFlySecurityManager.isChecking() ? doPrivileged((PrivilegedAction<Policy>) Policy::getPolicy) : Policy.getPolicy();
PolicyUtil policyUtil = WildFlySecurityManager.isChecking() ? doPrivileged((PrivilegedAction<PolicyUtil>) PolicyUtil::getPolicyUtil) : PolicyUtil.getPolicyUtil();
ProtectionDomain domain = new ProtectionDomain(null, null, null, JaccInterceptor.getGrantedRoles(getCallerSecurityIdentity()));
return policy.implies(domain, new EJBRoleRefPermission(getComponentName(), roleName));
return policyUtil.implies(domain, new EJBRoleRefPermission(getComponentName(), roleName));
} else {
boolean tmpBool = checkCallerSecurityIdentityRole(roleName); // rls debug todo remove
if (ROOT_LOGGER.isTraceEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.Policy;
import java.security.Principal;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
Expand All @@ -32,6 +31,7 @@
import org.wildfly.common.Assert;
import org.wildfly.security.auth.server.SecurityDomain;
import org.wildfly.security.auth.server.SecurityIdentity;
import org.wildfly.security.authz.jacc.PolicyUtil;
import org.wildfly.security.manager.WildFlySecurityManager;

/**
Expand Down Expand Up @@ -96,8 +96,8 @@ private void hasPermission(EJBComponent ejbComponent, ComponentView componentVie
MethodInterfaceType methodIntfType = componentView.getPrivateData(MethodInterfaceType.class);
EJBMethodPermission permission = createEjbMethodPermission(method, ejbComponent, methodIntfType);
ProtectionDomain domain = new ProtectionDomain (componentView.getProxyClass().getProtectionDomain().getCodeSource(), null, null, getGrantedRoles(securityIdentity));
Policy policy = WildFlySecurityManager.isChecking() ? doPrivileged((PrivilegedAction<Policy>) Policy::getPolicy) : Policy.getPolicy();
if (!policy.implies(domain, permission)) {
PolicyUtil policyUtil = WildFlySecurityManager.isChecking() ? doPrivileged((PrivilegedAction<PolicyUtil>) PolicyUtil::getPolicyUtil) : PolicyUtil.getPolicyUtil();
if (!policyUtil.implies(domain, permission)) {
throw EjbLogger.ROOT_LOGGER.invocationOfMethodNotAllowed(method,ejbComponent.getComponentName());
}
}
Expand Down
4 changes: 4 additions & 0 deletions undertow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@
<groupId>org.wildfly.security</groupId>
<artifactId>wildfly-elytron-ssl</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.security.jakarta</groupId>
<artifactId>jakarta-authorization</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import java.security.CodeSource;
import java.security.Permission;
import java.security.Policy;
import java.security.Principal;
import java.security.PrivilegedAction;
import java.security.ProtectionDomain;
Expand All @@ -30,6 +29,7 @@
import io.undertow.servlet.api.ServletInfo;
import io.undertow.servlet.api.SingleConstraintMatch;
import io.undertow.servlet.api.TransportGuaranteeType;
import org.wildfly.security.authz.jacc.PolicyUtil;
import org.wildfly.security.manager.WildFlySecurityManager;

/**
Expand Down Expand Up @@ -125,8 +125,8 @@ private boolean hasPermission(Account account, Deployment deployment, ServletInf
}

private boolean hasPermission(ProtectionDomain domain, Permission permission) {
Policy policy = WildFlySecurityManager.isChecking() ? doPrivileged((PrivilegedAction<Policy>) Policy::getPolicy) : Policy.getPolicy();
return policy.implies(domain, permission);
PolicyUtil policyUtil = WildFlySecurityManager.isChecking() ? doPrivileged((PrivilegedAction<PolicyUtil>) PolicyUtil::getPolicyUtil) : PolicyUtil.getPolicyUtil();
return policyUtil.implies(domain, permission);
}

private Principal[] getGrantedRoles(Account account, Deployment deployment) {
Expand Down

0 comments on commit e23c04d

Please sign in to comment.