javax.security.auth.message.config.ServerAuthConfig Java Examples

The following examples show how to use javax.security.auth.message.config.ServerAuthConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AuthenticatorBase.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
private JaspicState getJaspicState(AuthConfigProvider jaspicProvider, Request request,
        Response response, boolean authMandatory) throws IOException {
    JaspicState jaspicState = new JaspicState();

    jaspicState.messageInfo =
            new MessageInfoImpl(request.getRequest(), response.getResponse(), authMandatory);

    try {
        CallbackHandler callbackHandler = createCallbackHandler();
        ServerAuthConfig serverAuthConfig = jaspicProvider.getServerAuthConfig(
                "HttpServlet", jaspicAppContextID, callbackHandler);
        String authContextID = serverAuthConfig.getAuthContextID(jaspicState.messageInfo);
        jaspicState.serverAuthContext = serverAuthConfig.getAuthContext(authContextID, null, null);
    } catch (AuthException e) {
        log.warn(sm.getString("authenticator.jaspicServerAuthContextFail"), e);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return null;
    }

    return jaspicState;
}
 
Example #2
Source File: JBossAuthConfigProvider.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @see AuthConfigProvider#getServerAuthConfig(String, String, CallbackHandler)
 */
public ServerAuthConfig getServerAuthConfig(String layer, String appContext, 
      CallbackHandler handler) throws AuthException
{ 
   //TODO: Throw SecurityException if user has no perms
   if(handler == null)
   {
      try
      {
          handler = this.instantiateCallbackHandler();  
      } 
      catch(Exception e)
      {
         throw new AuthException(e.getLocalizedMessage());
      }
   }
   return new JBossServerAuthConfig(layer,appContext, handler, contextProperties);
}
 
Example #3
Source File: AuthenticatorBase.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public void logout(Request request) {
    AuthConfigProvider provider = getJaspicProvider();
    if (provider != null) {
        MessageInfo messageInfo = new MessageInfoImpl(request, request.getResponse(), true);
        Subject client = (Subject) request.getNote(Constants.REQ_JASPIC_SUBJECT_NOTE);
        if (client != null) {
            ServerAuthContext serverAuthContext;
            try {
                ServerAuthConfig serverAuthConfig = provider.getServerAuthConfig("HttpServlet",
                        jaspicAppContextID, CallbackHandlerImpl.getInstance());
                String authContextID = serverAuthConfig.getAuthContextID(messageInfo);
                serverAuthContext = serverAuthConfig.getAuthContext(authContextID, null, null);
                serverAuthContext.cleanSubject(messageInfo, client);
            } catch (AuthException e) {
                log.debug(sm.getString("authenticator.jaspicCleanSubjectFail"), e);
            }
        }
    }

    Principal p = request.getPrincipal();
    if (p instanceof TomcatPrincipal) {
        try {
            ((TomcatPrincipal) p).logout();
        } catch (Throwable t) {
            ExceptionUtils.handleThrowable(t);
            log.debug(sm.getString("authenticator.tomcatPrincipalLogoutFail"), t);
        }
    }

    register(request, request.getResponse(), null, null, null, null);
}
 
Example #4
Source File: SimpleAuthConfigProvider.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public ServerAuthConfig getServerAuthConfig(String layer, String appContext,
        CallbackHandler handler) throws AuthException {
    ServerAuthConfig serverAuthConfig = this.serverAuthConfig;
    if (serverAuthConfig == null) {
        synchronized (this) {
            if (this.serverAuthConfig == null) {
                this.serverAuthConfig = createServerAuthConfig(layer, appContext, handler, properties);
            }
            serverAuthConfig = this.serverAuthConfig;
        }
    }
    return serverAuthConfig;
}
 
Example #5
Source File: SimpleAuthConfigProvider.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Override
public void refresh() {
    ServerAuthConfig serverAuthConfig = this.serverAuthConfig;
    if (serverAuthConfig != null) {
        serverAuthConfig.refresh();
    }
}
 
Example #6
Source File: TestSimpleServerAuthConfig.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testConfigOnServerAuthConfig() throws Exception {
    ServerAuthConfig serverAuthConfig =
            new SimpleServerAuthConfig(null,  null, null, CONFIG_PROPERTIES);
    ServerAuthContext serverAuthContext = serverAuthConfig.getAuthContext(null, null, null);

    validateServerAuthContext(serverAuthContext);
}
 
Example #7
Source File: TestSimpleServerAuthConfig.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testConfigOnGetAuthContext() throws Exception {
    ServerAuthConfig serverAuthConfig = new SimpleServerAuthConfig(null,  null, null, null);
    ServerAuthContext serverAuthContext =
            serverAuthConfig.getAuthContext(null, null, CONFIG_PROPERTIES);

    validateServerAuthContext(serverAuthContext);
}
 
Example #8
Source File: TomEESecurityContext.java    From tomee with Apache License 2.0 5 votes vote down vote up
private ServerAuthContext getServerAuthContext(final HttpServletRequest request) throws AuthException {
    final String appContext = request.getServletContext().getVirtualServerName() + " " + request.getContextPath();

    final AuthConfigProvider authConfigProvider =
            AuthConfigFactory.getFactory().getConfigProvider("HttpServlet", appContext, null);
    final ServerAuthConfig serverAuthConfig =
            authConfigProvider.getServerAuthConfig("HttpServlet", appContext, CallbackHandlerImpl.getInstance());

    return serverAuthConfig.getAuthContext(null, null, null);
}
 
Example #9
Source File: AuthenticatorBase.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
public ServerAuthConfig getServerAuthConfig(String layer, String appContext, CallbackHandler handler)
        throws AuthException {
    return null;
}
 
Example #10
Source File: SimpleAuthConfigProvider.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
protected ServerAuthConfig createServerAuthConfig(String layer, String appContext,
        CallbackHandler handler, Map<String,String> properties) {
    return new SimpleServerAuthConfig(layer, appContext, handler, properties);
}
 
Example #11
Source File: TestSimpleServerAuthConfig.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Test(expected=AuthException.class)
public void testConfigNone() throws Exception {
    ServerAuthConfig serverAuthConfig = new SimpleServerAuthConfig(null,  null, null, null);
    serverAuthConfig.getAuthContext(null, null, null);
}
 
Example #12
Source File: CustomAuthConfigProvider.java    From eplmp with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public ServerAuthConfig getServerAuthConfig(String layer, String appContext, CallbackHandler callbackHandler) throws AuthException {
    return new CustomServerAuthConfig(authConfig, layer, appContext, callbackHandler);
}
 
Example #13
Source File: TomEESecurityAuthConfigProvider.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
public ServerAuthConfig getServerAuthConfig(final String layer, final String appContext,
                                            final CallbackHandler handler)
        throws AuthException, SecurityException {
    return new TomEESecurityServerAuthConfig(layer, appContext, handler);
}
 
Example #14
Source File: TheAuthConfigProvider.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
public ServerAuthConfig getServerAuthConfig(String layer, String appContext, CallbackHandler handler) throws AuthException,
        SecurityException {
    return new TheServerAuthConfig(layer, appContext, handler == null ? createDefaultCallbackHandler() : handler,
            providerProperties, serverAuthModule);
}