Skip to content

Commit

Permalink
[WFLY-8803] Backport Latest WildFly Elytron Integration Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
darranl committed May 18, 2017
2 parents 891782c + aada71e commit 9f3f755
Show file tree
Hide file tree
Showing 24 changed files with 191 additions and 829 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@
import static java.security.AccessController.doPrivileged;

import java.net.URI;
import java.security.GeneralSecurityException;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;

import javax.net.ssl.SSLContext;

import org.jboss.as.ee.component.Attachments;
import org.jboss.as.ee.component.ComponentDescription;
Expand Down Expand Up @@ -154,37 +159,41 @@ private RegistrationService(Module module) {
@Override
public void start(StartContext context) throws StartException {

doPrivileged((PrivilegedAction<Void>) () -> {
// associate the EJB client context and discovery setup with the deployment classloader
final EJBClientContextService ejbClientContextService = ejbClientContextInjectedValue.getValue();
final EJBClientContext ejbClientContext = ejbClientContextService.getClientContext();
final AuthenticationContext ejbClientClustersAuthenticationContext = ejbClientContextService.getClustersAuthenticationContext();
final ModuleClassLoader classLoader = module.getClassLoader();
EjbLogger.DEPLOYMENT_LOGGER.debugf("Registering EJB client context %s for classloader %s", ejbClientContext, classLoader);
final ContextManager<AuthenticationContext> authenticationContextManager = AuthenticationContext.getContextManager();
final RemotingProfileService profileService = profileServiceInjectedValue.getOptionalValue();
if (profileService != null || ejbClientClustersAuthenticationContext != null) {
// this is cheating but it works for our purposes
AuthenticationContext authenticationContext = authenticationContextManager.getClassLoaderDefault(classLoader);
if (authenticationContext == null) {
authenticationContext = authenticationContextManager.get();
}
// now transform it
if (profileService != null) {
for (RemotingProfileService.ConnectionSpec connectionSpec : profileService.getConnectionSpecs()) {
authenticationContext = transformOne(connectionSpec, authenticationContext);
try {
doPrivileged((PrivilegedExceptionAction<Void>) () -> {
// associate the EJB client context and discovery setup with the deployment classloader
final EJBClientContextService ejbClientContextService = ejbClientContextInjectedValue.getValue();
final EJBClientContext ejbClientContext = ejbClientContextService.getClientContext();
final AuthenticationContext ejbClientClustersAuthenticationContext = ejbClientContextService.getClustersAuthenticationContext();
final ModuleClassLoader classLoader = module.getClassLoader();
EjbLogger.DEPLOYMENT_LOGGER.debugf("Registering EJB client context %s for classloader %s", ejbClientContext, classLoader);
final ContextManager<AuthenticationContext> authenticationContextManager = AuthenticationContext.getContextManager();
final RemotingProfileService profileService = profileServiceInjectedValue.getOptionalValue();
if (profileService != null || ejbClientClustersAuthenticationContext != null) {
// this is cheating but it works for our purposes
AuthenticationContext authenticationContext = authenticationContextManager.getClassLoaderDefault(classLoader);
if (authenticationContext == null) {
authenticationContext = authenticationContextManager.get();
}
// now transform it
if (profileService != null) {
for (RemotingProfileService.ConnectionSpec connectionSpec : profileService.getConnectionSpecs()) {
authenticationContext = transformOne(connectionSpec, authenticationContext);
}
}
if (ejbClientClustersAuthenticationContext != null) {
authenticationContext = ejbClientClustersAuthenticationContext.with(authenticationContext);
}
// and set the result
authenticationContextManager.setClassLoaderDefault(classLoader, authenticationContext);
}
if (ejbClientClustersAuthenticationContext != null) {
authenticationContext = ejbClientClustersAuthenticationContext.with(authenticationContext);
}
// and set the result
authenticationContextManager.setClassLoaderDefault(classLoader, authenticationContext);
}
EJBClientContext.getContextManager().setClassLoaderDefault(classLoader, ejbClientContext);
Discovery.getContextManager().setClassLoaderDefault(classLoader, discoveryInjector.getValue());
return null;
});
EJBClientContext.getContextManager().setClassLoaderDefault(classLoader, ejbClientContext);
Discovery.getContextManager().setClassLoaderDefault(classLoader, discoveryInjector.getValue());
return null;
});
} catch (PrivilegedActionException e) {
throw (StartException) e.getCause();
}
}

@Override
Expand All @@ -206,9 +215,10 @@ public Void getValue() throws IllegalStateException, IllegalArgumentException {
return null;
}

private static AuthenticationContext transformOne(RemotingProfileService.ConnectionSpec connectionSpec, AuthenticationContext context) {
private static AuthenticationContext transformOne(RemotingProfileService.ConnectionSpec connectionSpec, AuthenticationContext context) throws StartException {
final AbstractOutboundConnectionService connectionService = connectionSpec.getInjector().getValue();
AuthenticationConfiguration authenticationConfiguration = connectionService.getAuthenticationConfiguration();
SSLContext sslContext = connectionService.getSSLContext();
final URI destinationUri = connectionService.getDestinationUri();
MatchRule rule = MatchRule.ALL;
final String scheme = destinationUri.getScheme();
Expand All @@ -227,14 +237,19 @@ private static AuthenticationContext transformOne(RemotingProfileService.Connect
if (path != null && ! path.isEmpty()) {
rule = rule.matchPath(path);
}
final String userInfo = destinationUri.getUserInfo();
if (userInfo != null) {
rule = rule.matchUser(userInfo);
}
final OptionMap connectOptions = connectionSpec.getConnectOptions();
authenticationConfiguration = RemotingOptions.mergeOptionsIntoAuthenticationConfiguration(connectOptions, authenticationConfiguration);
AuthenticationConfiguration configuration = CLIENT.getAuthenticationConfiguration(destinationUri, context, - 1, "ejb", "jboss", null);
return context.with(0, rule, configuration.with(authenticationConfiguration));
if (sslContext == null) {
try {
sslContext = CLIENT.getSSLContext(destinationUri, context);
} catch (GeneralSecurityException e) {
throw EjbLogger.ROOT_LOGGER.failedToObtainSSLContext(e);
}
}
final SSLContext finalSSLContext = sslContext;
AuthenticationContext mergedAuthenticationContext = context.with(0, rule, configuration.with(authenticationConfiguration));
return mergedAuthenticationContext.withSsl(0, rule, () -> finalSSLContext);
}
}
}
3 changes: 3 additions & 0 deletions ejb3/src/main/java/org/jboss/as/ejb3/logging/EjbLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -3145,4 +3145,7 @@ public interface EjbLogger extends BasicLogger {
@LogMessage(level = INFO)
@Message(id = 493, value = "EJB subsystem suspension complete")
void suspensionComplete();

@Message(id = 494, value = "Failed to obtain SSLContext")
StartException failedToObtainSSLContext(@Cause Exception cause);
}
1 change: 0 additions & 1 deletion testsuite/domain/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@
<include>org/jboss/as/test/integration/respawn/*TestCase.java</include>
<include>org/jboss/as/test/integration/domain/*TestCase.java</include>
<include>org/jboss/as/test/integration/domain/suites/*TestSuite.java</include>
<include>org/jboss/as/test/integration/domain/elytron/*TestCase.java</include>
</includes>
</configuration>
</plugin>
Expand Down

This file was deleted.

0 comments on commit 9f3f755

Please sign in to comment.