Example usage for javax.security.auth.login LoginContext logout

List of usage examples for javax.security.auth.login LoginContext logout

Introduction

In this page you can find the example usage for javax.security.auth.login LoginContext logout.

Prototype

public void logout() throws LoginException 

Source Link

Document

Logout the Subject .

Usage

From source file:AuthenticateNT.java

public static void main(String[] args) {
    try {/*from  www . j  a  va 2 s .c  om*/
        LoginContext loginContext = new LoginContext("AuthenticateNT");
        loginContext.login();
        System.out.println("Login Successful");
        Subject subject = loginContext.getSubject();
        System.out.println(subject);
        Subject.doAs(subject, new WriteFileAction());
        loginContext.logout();
        System.exit(0);
    } catch (LoginException loginException) {
        loginException.printStackTrace();
        System.exit(-1);
    }
}

From source file:org.jboss.as.test.integration.security.picketlink.SAML2KerberosAuthenticationTestCase.java

/**
 * Returns response body for the given URL request as a String. It also checks if the returned HTTP status code is the
 * expected one. If the server returns {@link HttpServletResponse#SC_UNAUTHORIZED} and an username is provided, then the
 * given user is authenticated against Kerberos and a new request is executed under the new subject.
 *
 * @param uri  URI to which the request should be made
 * @param user Username/*  w  w  w.  j  a  va2 s  .  com*/
 * @param pass Password
 * @return HTTP response body
 * @throws IOException
 * @throws URISyntaxException
 * @throws PrivilegedActionException
 * @throws LoginException
 */
public static String makeCallWithKerberosAuthn(URI uri, URI idpUri, final String user, final String pass)
        throws IOException, URISyntaxException, PrivilegedActionException, LoginException {

    final String canonicalHost = Utils.getDefaultHost(true);
    uri = Utils.replaceHost(uri, canonicalHost);
    idpUri = Utils.replaceHost(idpUri, canonicalHost);

    LOGGER.trace("Making call to: " + uri);
    LOGGER.trace("Expected IDP: " + idpUri);

    final Krb5LoginConfiguration krb5configuration = new Krb5LoginConfiguration(Utils.getLoginConfiguration());
    // Use our custom configuration to avoid reliance on external config
    Configuration.setConfiguration(krb5configuration);

    // 1. Authenticate to Kerberos.
    final LoginContext lc = Utils.loginWithKerberos(krb5configuration, user, pass);

    // 2. Perform the work as authenticated Subject.
    final String responseBody = Subject.doAs(lc.getSubject(), new HttpGetInKerberos(uri, idpUri));
    lc.logout();
    krb5configuration.resetConfiguration();
    return responseBody;
}

From source file:com.adito.activedirectory.ActiveDirectoryUserDatabaseConfiguration.java

static void logoutContext(LoginContext context) {
    try {/*w  ww  .j  a v a  2s  .  c o m*/
        if (context != null) {
            context.logout();
        }
    } catch (LoginException e) {
        // ignore
    }
}

From source file:be.fedict.hsm.ws.impl.JAASSOAPHandler.java

private void logout(SOAPMessageContext context) throws LoginException {
    LoginContext loginContext = (LoginContext) context.remove(LOGIN_CONTEXT_ATTRIBUTE);
    if (null == loginContext) {
        return;// w ww.j a  v a  2 s.  co  m
    }
    loginContext.logout();
}

From source file:de.ingrid.server.security.IngridRealm.java

@Override
public void logout(final Principal principal) {
    try {/* w ww.  ja  v a2  s .  co  m*/
        if (principal instanceof KnownPrincipal) {
            final KnownPrincipal knownPrincipal = (KnownPrincipal) principal;
            final LoginContext loginContext = knownPrincipal.getLoginContext();
            if (loginContext != null) {
                loginContext.logout();
            }
            LOG.info("principal has logged out: " + knownPrincipal);
        }
    } catch (final LoginException e) {
        LOG.warn("logout failed", e);
    }
}

From source file:de.ingrid.admin.security.IngridRealm.java

@Override
public void logout(Principal principal) {
    try {//from  w  ww  .  j a  v a 2 s . co  m
        if (principal instanceof KnownPrincipal) {
            KnownPrincipal knownPrincipal = (KnownPrincipal) principal;
            LoginContext loginContext = knownPrincipal.getLoginContext();
            if (loginContext != null) {
                loginContext.logout();
            }
            LOG.info("principal has logged out: " + knownPrincipal);
        }
    } catch (LoginException e) {
        LOG.warn("logout failed", e);
    }
}

From source file:io.druid.security.kerberos.DruidKerberosAuthenticationHandler.java

@Override
public void destroy() {
    keytab = null;/*  w w w .j av  a  2 s .  c  o  m*/
    serverSubject = null;
    for (LoginContext loginContext : loginContexts) {
        try {
            loginContext.logout();
        } catch (LoginException ex) {
            log.warn(ex, ex.getMessage());
        }
    }
    loginContexts.clear();
}

From source file:org.jasig.cas.authentication.handler.support.JaasAuthenticationHandler.java

protected final boolean authenticateUsernamePasswordInternal(final UsernamePasswordCredentials credentials)
        throws AuthenticationException {

    final String transformedUsername = getPrincipalNameTransformer().transform(credentials.getUsername());

    try {/*from ww  w .  j a  v a  2  s .c om*/
        if (log.isDebugEnabled()) {
            log.debug("Attempting authentication for: " + transformedUsername);
        }
        final LoginContext lc = new LoginContext(this.realm,
                new UsernamePasswordCallbackHandler(transformedUsername, credentials.getPassword()));

        lc.login();
        lc.logout();
    } catch (final LoginException fle) {
        if (log.isDebugEnabled()) {
            log.debug("Authentication failed for: " + transformedUsername);
        }
        return false;
    }

    if (log.isDebugEnabled()) {
        log.debug("Authentication succeeded for: " + transformedUsername);
    }
    return true;
}

From source file:com.cubusmail.server.services.CubusService.java

public void logout() throws Exception {

    try {//from w ww  .j  av a  2s .  c  o m
        LoginContext context = new LoginContext(MailboxLoginModule.class.getSimpleName(),
                SessionManager.get().getSubject());
        context.logout();
        SessionManager.invalidateSession();
    } catch (LoginException e) {
        log.error(e.getMessage(), e);
        throw new GWTLogoutException(e.getMessage());
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}

From source file:com.hs.mail.web.controller.WebConsole.java

private ModelAndView doLogout(WebSession session, HttpServletRequest request) {
    try {/*from w w  w  .j a  v a2  s .c om*/
        LoginContext lc = (LoginContext) session.retrieveBean(WebSession.LOGIN_CONTEXT);
        lc.logout();
        session.removeBean(WebSession.LOGIN_CONTEXT);
    } catch (LoginException e) {
        logger.error(e.getMessage(), e);
    }
    return new ModelAndView("index");
}