Search in sources :

Example 1 with AuthenticationSuccessEvent

use of org.springframework.security.authentication.event.AuthenticationSuccessEvent in project pentaho-platform by pentaho.

the class PentahoAuthenticationSuccessListener method onApplicationEvent.

// ~ Methods
// =========================================================================================================
public void onApplicationEvent(final ApplicationEvent event) {
    if (event instanceof AuthenticationSuccessEvent) {
        // $NON-NLS-1$
        logger.debug("received " + event.getClass().getSimpleName());
        // $NON-NLS-1$
        logger.debug("synchronizing current IPentahoSession with SecurityContext");
        try {
            Authentication authentication = ((AbstractAuthenticationEvent) event).getAuthentication();
            IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
            Assert.notNull(pentahoSession, "PentahoSessionHolder doesn't have a session");
            pentahoSession.setAuthenticated(authentication.getName());
            pentahoSession.setAttribute(IPentahoSession.SESSION_ROLES, authentication.getAuthorities());
            // audit session creation
            AuditHelper.audit(pentahoSession.getId(), pentahoSession.getName(), pentahoSession.getActionName(), pentahoSession.getObjectName(), "", MessageTypes.SESSION_START, "", "", 0, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            null);
            logger.info("The user \"" + pentahoSession.getName() + "\"" + " connected to server with session ID " + pentahoSession.getId());
        } catch (Exception e) {
            logger.error(e.getLocalizedMessage(), e);
        }
    }
}
Also used : Authentication(org.springframework.security.core.Authentication) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) AuthenticationSuccessEvent(org.springframework.security.authentication.event.AuthenticationSuccessEvent) AbstractAuthenticationEvent(org.springframework.security.authentication.event.AbstractAuthenticationEvent)

Example 2 with AuthenticationSuccessEvent

use of org.springframework.security.authentication.event.AuthenticationSuccessEvent in project webanno by webanno.

the class SuccessfulLoginListener method onApplicationEvent.

@Override
public void onApplicationEvent(ApplicationEvent aEvent) {
    if (aEvent instanceof AuthenticationSuccessEvent) {
        AuthenticationSuccessEvent event = (AuthenticationSuccessEvent) aEvent;
        User user = userRepository.get(event.getAuthentication().getName());
        user.setLastLogin(new Date(event.getTimestamp()));
        userRepository.update(user);
    }
}
Also used : User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) AuthenticationSuccessEvent(org.springframework.security.authentication.event.AuthenticationSuccessEvent) Date(java.util.Date)

Example 3 with AuthenticationSuccessEvent

use of org.springframework.security.authentication.event.AuthenticationSuccessEvent in project spring-security-oauth by spring-projects.

the class OAuth2ClientAuthenticationProcessingFilter method attemptAuthentication.

@Override
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException {
    OAuth2AccessToken accessToken;
    try {
        accessToken = restTemplate.getAccessToken();
    } catch (OAuth2Exception e) {
        BadCredentialsException bad = new BadCredentialsException("Could not obtain access token", e);
        publish(new OAuth2AuthenticationFailureEvent(bad));
        throw bad;
    }
    try {
        OAuth2Authentication result = tokenServices.loadAuthentication(accessToken.getValue());
        if (authenticationDetailsSource != null) {
            request.setAttribute(OAuth2AuthenticationDetails.ACCESS_TOKEN_VALUE, accessToken.getValue());
            request.setAttribute(OAuth2AuthenticationDetails.ACCESS_TOKEN_TYPE, accessToken.getTokenType());
            result.setDetails(authenticationDetailsSource.buildDetails(request));
        }
        publish(new AuthenticationSuccessEvent(result));
        return result;
    } catch (InvalidTokenException e) {
        BadCredentialsException bad = new BadCredentialsException("Could not obtain user details from token", e);
        publish(new OAuth2AuthenticationFailureEvent(bad));
        throw bad;
    }
}
Also used : InvalidTokenException(org.springframework.security.oauth2.common.exceptions.InvalidTokenException) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) OAuth2Authentication(org.springframework.security.oauth2.provider.OAuth2Authentication) AuthenticationSuccessEvent(org.springframework.security.authentication.event.AuthenticationSuccessEvent) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException) OAuth2Exception(org.springframework.security.oauth2.common.exceptions.OAuth2Exception)

Example 4 with AuthenticationSuccessEvent

use of org.springframework.security.authentication.event.AuthenticationSuccessEvent in project opennms by OpenNMS.

the class SecurityAuthenticationEventOnmsEventBuilderTest method testAuthenticationSuccessEventWithEverything.

public void testAuthenticationSuccessEventWithEverything() throws Exception {
    String userName = "bar";
    String ip = "1.2.3.4";
    String sessionId = "it tastes just like our regular coffee";
    HttpServletRequest request = createMock(HttpServletRequest.class);
    HttpSession session = createMock(HttpSession.class);
    expect(request.getRemoteAddr()).andReturn(ip);
    expect(request.getSession(false)).andReturn(session);
    expect(session.getId()).andReturn(sessionId);
    replay(request, session);
    WebAuthenticationDetails details = new WebAuthenticationDetails(request);
    verify(request, session);
    org.springframework.security.core.Authentication authentication = new TestingDetailsAuthenticationToken(userName, "cheesiness", new GrantedAuthority[0], details);
    AuthenticationSuccessEvent authEvent = new AuthenticationSuccessEvent(authentication);
    SecurityAuthenticationEventOnmsEventBuilder builder = new SecurityAuthenticationEventOnmsEventBuilder();
    builder.setEventProxy(m_eventProxy);
    builder.afterPropertiesSet();
    EventBuilder eventBuilder = new EventBuilder(SecurityAuthenticationEventOnmsEventBuilder.SUCCESS_UEI, "OpenNMS.WebUI");
    eventBuilder.addParam("user", userName);
    eventBuilder.addParam("ip", ip);
    Event expectedEvent = eventBuilder.getEvent();
    // Make sure the timestamps are synchronized
    expectedEvent.setTime(new Date(authEvent.getTimestamp()));
    m_eventProxy.send(EventEquals.eqEvent(eventBuilder.getEvent()));
    m_mocks.replayAll();
    builder.onApplicationEvent(authEvent);
    m_mocks.verifyAll();
}
Also used : HttpSession(javax.servlet.http.HttpSession) AuthenticationSuccessEvent(org.springframework.security.authentication.event.AuthenticationSuccessEvent) Date(java.util.Date) HttpServletRequest(javax.servlet.http.HttpServletRequest) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) WebAuthenticationDetails(org.springframework.security.web.authentication.WebAuthenticationDetails) AuthenticationSuccessEvent(org.springframework.security.authentication.event.AuthenticationSuccessEvent) ApplicationEvent(org.springframework.context.ApplicationEvent) Event(org.opennms.netmgt.xml.event.Event) AuthenticationFailureBadCredentialsEvent(org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent)

Example 5 with AuthenticationSuccessEvent

use of org.springframework.security.authentication.event.AuthenticationSuccessEvent in project pentaho-platform by pentaho.

the class PentahoBasicProcessingFilter method onSuccessfulAuthentication.

@Override
protected void onSuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, Authentication authResult) throws IOException {
    super.onSuccessfulAuthentication(request, response, authResult);
    request.getSession().setAttribute("BasicAuth", "true");
    if (applicationEventPublisher != null) {
        applicationEventPublisher.publishEvent(new AuthenticationSuccessEvent(authResult));
    }
}
Also used : AuthenticationSuccessEvent(org.springframework.security.authentication.event.AuthenticationSuccessEvent)

Aggregations

AuthenticationSuccessEvent (org.springframework.security.authentication.event.AuthenticationSuccessEvent)12 Date (java.util.Date)3 AbstractAuthenticationFailureEvent (org.springframework.security.authentication.event.AbstractAuthenticationFailureEvent)3 InteractiveAuthenticationSuccessEvent (org.springframework.security.authentication.event.InteractiveAuthenticationSuccessEvent)3 Test (org.junit.jupiter.api.Test)2 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)2 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)2 AbstractAuthenticationEvent (org.springframework.security.authentication.event.AbstractAuthenticationEvent)2 Authentication (org.springframework.security.core.Authentication)2 LoginEvent (com.dappermoose.stsimplefinance.data.LoginEvent)1 LoginUser (com.dappermoose.stsimplefinance.data.LoginUser)1 User (de.tudarmstadt.ukp.clarin.webanno.security.model.User)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpSession (javax.servlet.http.HttpSession)1 Transactional (javax.transaction.Transactional)1 Event (org.opennms.netmgt.xml.event.Event)1 OrcidProfileUserDetails (org.orcid.core.oauth.OrcidProfileUserDetails)1 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)1 IBackingRepositoryLifecycleManager (org.pentaho.platform.api.repository2.unified.IBackingRepositoryLifecycleManager)1 AuditApplicationEvent (org.springframework.boot.actuate.audit.listener.AuditApplicationEvent)1