Skip to content
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 @@ -251,14 +251,30 @@ void addIdentityManager(SecurityTemplate template, BuildProducer<ServletExtensio
// Create the configured identity manager
IdentityManagerBuildItem identityManager = identityManagers.get(0);
// Collect all of the authentication mechanisms and create a ServletExtension to register the Undertow identity manager
ArrayList<AuthConfig> allAuthConfigs = new ArrayList<>();
ServletExtension idmExt = template.configureUndertowIdentityManager(securityDomain.getSecurityDomain(),
identityManager.getIdentityManager());
extension.produce(new ServletExtensionBuildItem(idmExt));
}

/**
* Produces a {@code ServletExtension} to configure Undertow {@code AuthConfigBuildItem} produced during the build
*
* @param template - the runtime template class used to access runtime behaviors
* @param extension - the ServletExtensionBuildItem producer used to add the Undertow auth config
* @param authConfigs - the authentication method information that has been registered
*/
@BuildStep
@Record(ExecutionTime.STATIC_INIT)
void addLoginConfig(SecurityTemplate template, List<AuthConfigBuildItem> authConfigs,
BuildProducer<ServletExtensionBuildItem> extension) {
List<AuthConfig> allAuthConfigs = new ArrayList<>();

for (AuthConfigBuildItem authConfigExt : authConfigs) {
AuthConfig ac = authConfigExt.getAuthConfig();
allAuthConfigs.add(ac);
}
ServletExtension idmExt = template.configureUndertowIdentityManager(securityDomain.getSecurityDomain(),
identityManager.getIdentityManager(), allAuthConfigs);
extension.produce(new ServletExtensionBuildItem(idmExt));

extension.produce(new ServletExtensionBuildItem(template.configureLoginConfig(allAuthConfigs)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,24 +266,37 @@ public IdentityManager createIdentityManager(RuntimeValue<SecurityDomain> domain
* @return - the ServletExtension instance to register
*/
public ServletExtension configureUndertowIdentityManager(RuntimeValue<SecurityDomain> domain,
IdentityManager identityManager,
List<AuthConfig> authConfigs) {
IdentityManager identityManager) {
return new ServletExtension() {
@Override
public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) {
deploymentInfo.setIdentityManager(identityManager);
}
};
}

/**
* Called to create a {@linkplain ServletExtension} to associate the {@linkplain LoginConfig} with the
* deployment.
*
* @param authConfigs - the authenticaiton methods to register with the deployment {@linkplain LoginConfig}
* @return - the ServletExtension instance to register
*/
public ServletExtension configureLoginConfig(List<AuthConfig> authConfigs) {
return new ServletExtension() {
@Override
public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) {
if (authConfigs.size() > 0) {
AuthConfig first = authConfigs.get(0);
log.debugf("configureUndertowIdentityManager, %s", authConfigs);
log.debugf("configureLoginConfig, %s", authConfigs);
LoginConfig loginConfig = new LoginConfig(first.authMechanism, first.realmName);
for (int n = 1; n < authConfigs.size(); n++) {
AuthConfig ac = authConfigs.get(n);
loginConfig.addLastAuthMethod(ac.getAuthMechanism());
}
deploymentInfo.setLoginConfig(loginConfig);
}
deploymentInfo.setIdentityManager(identityManager);
}
};
}

}