use of javax.security.auth.message.config.ServerAuthConfig in project jetty.project by eclipse.
the class JaspiAuthenticatorFactory method getAuthenticator.
/* ------------------------------------------------------------ */
public Authenticator getAuthenticator(Server server, ServletContext context, AuthConfiguration configuration, IdentityService identityService, LoginService loginService) {
Authenticator authenticator = null;
try {
AuthConfigFactory authConfigFactory = AuthConfigFactory.getFactory();
RegistrationListener listener = new RegistrationListener() {
public void notify(String layer, String appContext) {
}
};
Subject serviceSubject = findServiceSubject(server);
String serverName = findServerName(server, serviceSubject);
String contextPath = context.getContextPath();
if (contextPath == null || contextPath.length() == 0)
contextPath = "/";
String appContext = serverName + " " + context.getContextPath();
AuthConfigProvider authConfigProvider = authConfigFactory.getConfigProvider(MESSAGE_LAYER, appContext, listener);
if (authConfigProvider != null) {
ServletCallbackHandler servletCallbackHandler = new ServletCallbackHandler(loginService);
ServerAuthConfig serverAuthConfig = authConfigProvider.getServerAuthConfig(MESSAGE_LAYER, appContext, servletCallbackHandler);
if (serverAuthConfig != null) {
Map map = new HashMap();
for (String key : configuration.getInitParameterNames()) map.put(key, configuration.getInitParameter(key));
authenticator = new JaspiAuthenticator(serverAuthConfig, map, servletCallbackHandler, serviceSubject, true, identityService);
}
}
} catch (AuthException e) {
LOG.warn(e);
}
return authenticator;
}
use of javax.security.auth.message.config.ServerAuthConfig in project Payara by payara.
the class RealmAdapter method invokeAuthenticateDelegate.
/**
* Authenticates the user making this request, based on the specified login configuration. Return <code>true</code> if
* any specified requirements have been satisfied, or <code>false</code> if we have created a response challenge
* already.
*
* @param request Request we are processing
* @param response Response we are creating
* @param context The Context to which client of this class is attached.
* @param authenticator the current authenticator.
* @param calledFromAuthenticate
* @return
* @exception IOException if an input/output error occurs
*/
@Override
public boolean invokeAuthenticateDelegate(HttpRequest request, HttpResponse response, Context context, Authenticator authenticator, boolean calledFromAuthenticate) throws IOException {
boolean result = false;
LoginConfig loginConfig = context.getLoginConfig();
ServerAuthConfig serverAuthConfig = getServerAuthConfig();
if (serverAuthConfig != null) {
try {
context.fireContainerEvent(BEFORE_AUTHENTICATION, null);
// Get the WebPrincipal principal and add to the security context principals
RequestFacade requestFacade = (RequestFacade) request.getRequest();
setAdditionalPrincipalInContext(requestFacade);
if (requestTracing != null && requestTracing.isRequestTracingEnabled()) {
result = doTraced(serverAuthConfig, context, requestFacade, () -> validate(request, response, loginConfig, authenticator, calledFromAuthenticate));
} else {
result = validate(request, response, loginConfig, authenticator, calledFromAuthenticate);
}
} finally {
resetAdditionalPrincipalInContext();
context.fireContainerEvent(AFTER_AUTHENTICATION, null);
}
} else {
// JSR 196 is not enabled. Use the current authenticator.
result = ((AuthenticatorBase) authenticator).authenticate(request, response, loginConfig);
}
return result;
}
use of javax.security.auth.message.config.ServerAuthConfig in project Payara by payara.
the class PipeHelper method getServerAuthContext.
@Override
public ServerAuthContext getServerAuthContext(MessageInfo info, Subject s) throws AuthException {
ServerAuthConfig c = (ServerAuthConfig) getAuthConfig(true);
if (c != null) {
addModel(info, map);
addPolicy(info, map);
return c.getAuthContext(c.getAuthContextID(info), s, map);
}
return null;
}
use of javax.security.auth.message.config.ServerAuthConfig in project cdap by caskdata.
the class JASPIAuthenticationHandler method getHandlerAuthenticator.
@Override
protected Authenticator getHandlerAuthenticator() {
JaspiAuthenticatorFactory jaspiAuthenticatorFactory = new JaspiAuthenticatorFactory();
jaspiAuthenticatorFactory.setLoginService(getHandlerLoginService());
HashMap<String, ServerAuthContext> serverAuthContextMap = new HashMap<>();
ServletCallbackHandler callbackHandler = new ServletCallbackHandler(getHandlerLoginService());
ServerAuthModule authModule = new BasicAuthModule(callbackHandler, "JAASRealm");
serverAuthContextMap.put("authContextID", new ServerAuthContextImpl(Collections.singletonList(authModule)));
ServerAuthContextType serverAuthContextType = new ServerAuthContextType("HTTP", "server *", "authContextID", new AuthModuleType<ServerAuthModule>());
ServerAuthConfigType serverAuthConfigType = new ServerAuthConfigType(serverAuthContextType, true);
ServerAuthConfig serverAuthConfig = new ServerAuthConfigImpl(serverAuthConfigType, serverAuthContextMap);
return new JaspiAuthenticator(serverAuthConfig, null, callbackHandler, new Subject(), true, getHandlerIdentityService());
}
use of javax.security.auth.message.config.ServerAuthConfig in project jbossws-cxf by jbossws.
the class DefaultJASPIAuthenticationProvider method enableServerAuthentication.
public boolean enableServerAuthentication(Deployment dep, JBossWebservicesMetaData wsmd) {
String securityDomain = null;
if (wsmd != null) {
securityDomain = wsmd.getProperty(JaspiServerAuthenticator.JASPI_SECURITY_DOMAIN);
}
if (securityDomain == null) {
return false;
}
ApplicationPolicy appPolicy = SecurityConfiguration.getApplicationPolicy(securityDomain);
if (appPolicy == null) {
Loggers.ROOT_LOGGER.noApplicationPolicy(securityDomain);
return false;
}
BaseAuthenticationInfo bai = appPolicy.getAuthenticationInfo();
if (bai == null || bai instanceof AuthenticationInfo) {
Loggers.ROOT_LOGGER.noJaspiApplicationPolicy(securityDomain);
return false;
}
JASPIAuthenticationInfo jai = (JASPIAuthenticationInfo) bai;
String contextRoot = dep.getService().getContextRoot();
String appId = "localhost " + contextRoot;
AuthConfigFactory factory = AuthConfigFactory.getFactory();
Properties properties = new Properties();
AuthConfigProvider provider = new JBossWSAuthConfigProvider(properties, factory);
provider = factory.getConfigProvider(JBossWSAuthConstants.SOAP_LAYER, appId, null);
JBossCallbackHandler callbackHandler = new JBossCallbackHandler();
try {
ServerAuthConfig serverConfig = provider.getServerAuthConfig(JBossWSAuthConstants.SOAP_LAYER, appId, callbackHandler);
Properties serverContextProperties = new Properties();
serverContextProperties.put("security-domain", securityDomain);
serverContextProperties.put("jaspi-policy", jai);
Bus bus = dep.getAttachment(Bus.class);
serverContextProperties.put(Bus.class, bus);
String authContextID = dep.getSimpleName();
ServerAuthContext sctx = serverConfig.getAuthContext(authContextID, null, serverContextProperties);
JaspiServerAuthenticator serverAuthenticator = new JaspiServerAuthenticator(sctx);
bus.getInInterceptors().add(new JaspiSeverInInterceptor(serverAuthenticator));
bus.getOutInterceptors().add(new JaspiSeverOutInterceptor(serverAuthenticator));
return true;
} catch (Exception e) {
Loggers.DEPLOYMENT_LOGGER.cannotCreateServerAuthContext(securityDomain, e);
}
return false;
}
Aggregations