Skip to content

Commit

Permalink
[WFLY-15750] / [WFLY-13889] Remove the dependency on PicketBox from W…
Browse files Browse the repository at this point in the history
…eld.
  • Loading branch information
darranl committed Nov 25, 2021
1 parent 6535911 commit 40b430b
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 97 deletions.
13 changes: 0 additions & 13 deletions ee-9/source-transform/weld/subsystem/pom.xml
Expand Up @@ -120,13 +120,6 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.picketbox</groupId>
<artifactId>picketbox</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
Expand Down Expand Up @@ -226,12 +219,6 @@
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-server</artifactId>
<exclusions>
<exclusion>
<groupId>org.picketbox</groupId>
<artifactId>picketbox</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down
Expand Up @@ -41,8 +41,6 @@
<module name="org.jboss.weld.core" />
<module name="org.jboss.weld.spi" />
<module name="org.jboss.as.weld.spi" />
<!-- Only needed if capability 'org.wildfly.legacy-security.server-security-manager' is present -->
<module name="org.picketbox" optional="true"/>
<module name="org.jboss.as.weld.common" />
<module name="org.jboss.as.weld.ejb" optional="true" services="import" />
<module name="org.jboss.as.weld.jpa" optional="true" services="import" />
Expand Down
13 changes: 0 additions & 13 deletions weld/subsystem/pom.xml
Expand Up @@ -57,13 +57,6 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.picketbox</groupId>
<artifactId>picketbox</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>wildfly-ee</artifactId>
Expand Down Expand Up @@ -92,12 +85,6 @@
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-server</artifactId>
<exclusions>
<exclusion>
<groupId>org.picketbox</groupId>
<artifactId>picketbox</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down
Expand Up @@ -32,7 +32,6 @@
import org.jboss.weld.security.spi.SecurityServices;

import java.util.function.Consumer;
import java.util.function.Supplier;

/**
* @author Martin Kouba
Expand All @@ -46,11 +45,8 @@ public ServiceName install(ServiceTarget serviceTarget, DeploymentUnit deploymen
final CapabilityServiceSupport capabilities = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
final ServiceBuilder<?> sb = serviceTarget.addService(serviceName);
final Consumer<SecurityServices> securityServicesConsumer = sb.provides(serviceName);
Supplier<?> securityManagerSupplier = null;
if (capabilities.hasCapability("org.wildfly.legacy-security.server-security-manager")) {
securityManagerSupplier = sb.requires(capabilities.getCapabilityServiceName("org.wildfly.legacy-security.server-security-manager"));
}
sb.setInstance(new WeldSecurityServices(securityServicesConsumer, securityManagerSupplier));

sb.setInstance(new WeldSecurityServices(securityServicesConsumer));
sb.install();
return serviceName;
}
Expand Down
Expand Up @@ -25,7 +25,6 @@
import java.security.Principal;
import java.security.PrivilegedAction;
import java.util.function.Consumer;
import java.util.function.Supplier;

import org.jboss.as.weld.ServiceNames;
import org.jboss.as.weld.logging.WeldLogger;
Expand All @@ -34,8 +33,6 @@
import org.jboss.msc.service.StartContext;
import org.jboss.msc.service.StartException;
import org.jboss.msc.service.StopContext;
import org.jboss.security.SecurityContext;
import org.jboss.security.SecurityContextAssociation;
import org.jboss.weld.security.spi.SecurityServices;
import org.wildfly.security.auth.server.SecurityDomain;
import org.wildfly.security.auth.server.SecurityIdentity;
Expand All @@ -48,14 +45,9 @@ public class WeldSecurityServices implements Service, SecurityServices {

public static final ServiceName SERVICE_NAME = ServiceNames.WELD_SECURITY_SERVICES_SERVICE_NAME;
private final Consumer<SecurityServices> securityServicesConsumer;
// This is a Supplier<ServerSecurityManager>. I use ? even though with type erasure
// that doesn't matter, just to make it harder for someone to modify this class and
// accidentally introduce any unnecessary loading of ServerSecurityManager
private final Supplier<?> securityManagerSupplier;

public WeldSecurityServices(final Consumer<SecurityServices> securityServicesConsumer, final Supplier<?> securityManagerSupplier) {
public WeldSecurityServices(final Consumer<SecurityServices> securityServicesConsumer) {
this.securityServicesConsumer = securityServicesConsumer;
this.securityManagerSupplier = securityManagerSupplier;
}

@Override
Expand All @@ -82,21 +74,6 @@ public Principal getPrincipal() {
public void cleanup() {
}

@Override
public org.jboss.weld.security.spi.SecurityContext getSecurityContext() {
if (securityManagerSupplier == null) {
return SecurityServices.super.getSecurityContext();
}

SecurityContext ctx;
if (WildFlySecurityManager.isChecking()) {
ctx = AccessController.doPrivileged((PrivilegedAction<SecurityContext>) () -> SecurityContextAssociation.getSecurityContext());
} else {
ctx = SecurityContextAssociation.getSecurityContext();
}
return new WeldSecurityContext(ctx);
}

@Override
public Consumer<Runnable> getSecurityContextAssociator(){
SecurityDomain elytronDomain = getCurrentSecurityDomain();
Expand All @@ -117,43 +94,4 @@ private SecurityDomain getCurrentSecurityDomain() {
}
}

static class WeldSecurityContext implements org.jboss.weld.security.spi.SecurityContext, PrivilegedAction<Void> {

private final SecurityContext ctx;

WeldSecurityContext(SecurityContext ctx) {
this.ctx = ctx;
}

@Override
public void associate() {
if (WildFlySecurityManager.isChecking()) {
AccessController.doPrivileged((PrivilegedAction<Void>) () -> this.run());
} else {
run();
}
}

@Override
public void dissociate() {
if (WildFlySecurityManager.isChecking()) {
AccessController.doPrivileged((PrivilegedAction<Void>)() -> {
SecurityContextAssociation.clearSecurityContext();
return null;
});
} else {
SecurityContextAssociation.clearSecurityContext();
}
}

@Override
public void close() {
}

@Override
public Void run() {
SecurityContextAssociation.setSecurityContext(ctx);
return null;
}
}
}

0 comments on commit 40b430b

Please sign in to comment.