Example usage for org.springframework.security.authentication.event InteractiveAuthenticationSuccessEvent InteractiveAuthenticationSuccessEvent

List of usage examples for org.springframework.security.authentication.event InteractiveAuthenticationSuccessEvent InteractiveAuthenticationSuccessEvent

Introduction

In this page you can find the example usage for org.springframework.security.authentication.event InteractiveAuthenticationSuccessEvent InteractiveAuthenticationSuccessEvent.

Prototype

public InteractiveAuthenticationSuccessEvent(Authentication authentication, Class<?> generatedBy) 

Source Link

Usage

From source file:org.messic.server.facade.security.CustomUsernamePasswordAuthenticationFilter.java

/**
* 
*///  www  .  ja v  a  2s  . c  om
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response,
        Authentication authResult) throws IOException, ServletException {

    if (logger.isDebugEnabled()) {
        logger.debug("Authentication success. Updating SecurityContextHolder to contain: " + authResult);
    }

    SecurityContextHolder.getContext().setAuthentication(authResult);

    getRememberMeServices().loginSuccess(request, response, authResult);

    // Fire event
    if (this.eventPublisher != null) {
        eventPublisher.publishEvent(new InteractiveAuthenticationSuccessEvent(authResult, this.getClass()));
    }

    UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(
            obtainUsername(request), obtainPassword(request));

    String token = AuthenticationSessionManager.successfulAuthentication(authentication);

    request.setAttribute("messic_token", token);

    getSuccessHandler().onAuthenticationSuccess(request, response, authResult);

}

From source file:net.kamhon.ieagle.security.AuthenticationUtil.java

@Override
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response,
        Authentication authResult) throws IOException, ServletException {
    if (log.isDebugEnabled()) {
        log.debug("Authentication success: " + authResult.toString());
    }//from  ww  w. ja va  2 s  .c  o  m

    SecurityContextHolder.getContext().setAuthentication(authResult);

    if (log.isDebugEnabled()) {
        log.debug(
                "Updated SecurityContextHolder to contain the following Authentication: '" + authResult + "'");
    }

    /*
     * if (invalidateSessionOnSuccessfulAuthentication) {
     * SessionUtils.startNewSessionIfRequired(request,
     * migrateInvalidatedSessionAttributes, sessionRegistry); }
     * 
     * String targetUrl = determineTargetUrl(request);
     * 
     * if (log.isDebugEnabled()) {
     * log.debug("Redirecting to target URL from HTTP Session (or default): "
     * + targetUrl); }
     */

    // onSuccessfulAuthentication(request, response, authResult);

    getRememberMeServices().loginSuccess(request, response, authResult);

    // Fire event
    if (this.eventPublisher != null) {
        eventPublisher.publishEvent(new InteractiveAuthenticationSuccessEvent(authResult, this.getClass()));
    }
}

From source file:org.jasig.springframework.security.portlet.authentication.PortletAuthenticationProcessingFilter.java

/**
* Puts the <code>Authentication</code> instance returned by the
* authentication manager into the secure context.
*//*w  ww .  j a v  a2 s.co  m*/
protected void successfulAuthentication(PortletRequest request, PortletResponse response,
        Authentication authResult) {
    if (logger.isDebugEnabled()) {
        logger.debug("Authentication success: " + authResult);
    }
    SecurityContextHolder.getContext().setAuthentication(authResult);
    // Fire event
    if (this.eventPublisher != null) {
        eventPublisher.publishEvent(new InteractiveAuthenticationSuccessEvent(authResult, this.getClass()));
    }
}

From source file:de.itsvs.cwtrpc.security.AbstractRpcAuthenticationProcessingFilter.java

protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {
    if (log.isDebugEnabled()) {
        log.debug("Successful authentication of '" + authentication.getName() + "'");
    }//  ww  w.jav a2  s  .  co m

    SecurityContextHolder.getContext().setAuthentication(authentication);

    getRememberMeServices().loginSuccess(request, response, authentication);
    if (getApplicationEventPublisher() != null) {
        getApplicationEventPublisher()
                .publishEvent(new InteractiveAuthenticationSuccessEvent(authentication, getClass()));
    }
}

From source file:org.josso.spring.security.JOSSOAuthenticationFilter.java

public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain)
        throws IOException, ServletException {

    if (!(servletRequest instanceof HttpServletRequest)) {
        throw new IllegalArgumentException("Non HTTP request unsupported by this filter");
    }//from w w  w. jav  a 2 s.co  m

    if (!(servletResponse instanceof HttpServletResponse)) {
        throw new IllegalArgumentException("Non HTTP response unsupported by this filter");
    }

    HttpServletRequest request = (HttpServletRequest) servletRequest;
    HttpServletResponse response = (HttpServletResponse) servletResponse;

    // We have to provide Authentication information based on JOSSO auth information ...

    // Obtain a JOSSO security context instance, if none is found is because user has not been authenticated.
    JOSSOSecurityContext sctx = WebAccessControlUtil.getSecurityContext((HttpServletRequest) request);

    logger.debug("Current JOSSO Security Context is " + sctx);

    // This is the authentication information used by ACEGI
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

    // If authentication information is present, we only need to validate that it is up to date.
    if (authentication != null) {

        if (logger.isDebugEnabled()) {
            logger.debug("Authentication information already present : '"
                    + SecurityContextHolder.getContext().getAuthentication() + "'");
        }

        // If there is no principal, we may need to logout this user ... TODO detect anonymous principals ?
        if (sctx == null && authentication.isAuthenticated()) {

            // If an authenticated Authentication is present, we must issue a logout !
            if (logger.isDebugEnabled()) {
                logger.debug("Logging out user '" + authentication + "'");
            }

            for (int i = 0; i < handlers.length; i++) {
                handlers[i].logout(request, response, authentication);
            }

        }

        chain.doFilter(request, response);

        return;
    }

    // We have a principal but no Spring Security authentication, propagate identity from JOSSO to Spring Security.
    if (sctx != null) {

        // If a saved request is present, we use the saved request to redirect the user to the original resource.
        SavedRequest savedRequest = new HttpSessionRequestCache().getRequest(request, response);

        if (savedRequest != null)
            logger.debug("Redirecting to original resource " + savedRequest.getRedirectUrl());

        UserDetails userDetails = userDetailsService.loadUserByUsername(sctx.getSSOSession());
        //            String jossoSessionId = (String) request.getAttribute("org.josso.agent.ssoSessionid");

        // New authenticated autentication instance.
        Authentication jossoAuth = new JOSSOAuthenticationToken(sctx.getSSOSession(), userDetails,
                userDetails.getAuthorities());

        // Store to SecurityContextHolder
        SecurityContextHolder.getContext().setAuthentication(jossoAuth);
        if (logger.isDebugEnabled()) {
            logger.debug("SecurityContextHolder populated with JOSSO Authentication Token: '"
                    + SecurityContextHolder.getContext().getAuthentication() + "'");
        }

        // Fire event
        if (this.eventPublisher != null) {
            eventPublisher.publishEvent(new InteractiveAuthenticationSuccessEvent(
                    SecurityContextHolder.getContext().getAuthentication(), this.getClass()));
        }

        // We have a saved request, redirect to original URL ...
        if (savedRequest != null)
            response.sendRedirect(savedRequest.getRedirectUrl());

    } else {
        if (logger.isDebugEnabled())
            logger.debug("No principal found in request !");

    }

    // Move on ...
    chain.doFilter(request, response);

}

From source file:ro.nextreports.server.web.integration.IntegrationAuthenticationFilter.java

protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response,
        Authentication authResult) throws IOException, ServletException {

    if (logger.isDebugEnabled()) {
        logger.debug("Authentication success. Updating SecurityContextHolder to contain: " + authResult);
    }//w  w  w. j  a  va 2s.  co m

    SecurityContextHolder.getContext().setAuthentication(authResult);

    if (this.eventPublisher != null) {
        eventPublisher.publishEvent(new InteractiveAuthenticationSuccessEvent(authResult, this.getClass()));
    }

    removeJSessionIdCookie(request, response);

    //        successHandler.onAuthenticationSuccess(request, response, authResult);
}

From source file:ubic.gemma.security.authentication.ManualAuthenticationServiceImpl.java

/**
 * @param authResult/*from  www . j  a  v a2 s.  com*/
 * @throws IOException
 */
protected void successfulAuthentication(Authentication authResult) {
    if (log.isDebugEnabled()) {
        log.debug("Authentication success: " + authResult.toString());
    }

    // Fire event
    assert context != null;

    if (this.context != null) {
        context.publishEvent(new InteractiveAuthenticationSuccessEvent(authResult, this.getClass()));
    } else {
        log.fatal("No context in which to place the authentication object");
    }
}