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);
}
}
}
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);
}
}
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;
}
}
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();
}
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));
}
}
Aggregations