Java Code Examples for org.springframework.security.authentication.event.AuthenticationSuccessEvent#getAuthentication()
The following examples show how to use
org.springframework.security.authentication.event.AuthenticationSuccessEvent#getAuthentication() .
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: BaeldungPasswordEncoderSetup.java From tutorials with MIT License | 6 votes |
@Bean public ApplicationListener<AuthenticationSuccessEvent> authenticationSuccessListener(final PasswordEncoder encoder) { return (AuthenticationSuccessEvent event) -> { final Authentication auth = event.getAuthentication(); if (auth instanceof UsernamePasswordAuthenticationToken && auth.getCredentials() != null) { final CharSequence clearTextPass = (CharSequence) auth.getCredentials(); // 1 final String newPasswordHash = encoder.encode(clearTextPass); // 2 LOG.info("New password hash {} for user {}", newPasswordHash, auth.getName()); ((UsernamePasswordAuthenticationToken) auth).eraseCredentials(); // 3 } }; }
Example 2
Source File: AuthenticationSuccessEventListener.java From cola with MIT License | 5 votes |
@Override public void onApplicationEvent(AuthenticationSuccessEvent event) { if (event.getClass().equals(AuthenticationSuccessEvent.class)) { Authentication authentication = event.getAuthentication(); this.userService.processLoginSuccess(authentication.getName(), null, null); log.info("Authentication success:" + authentication.getName() + " ," + AuthenticationSuccessEvent.class); } }
Example 3
Source File: SpringEventListener.java From ranger with Apache License 2.0 | 5 votes |
protected void process(AuthenticationSuccessEvent authSuccessEvent) { Authentication auth = authSuccessEvent.getAuthentication(); WebAuthenticationDetails details = (WebAuthenticationDetails) auth .getDetails(); String remoteAddress = details != null ? details.getRemoteAddress() : ""; String sessionId = details != null ? details.getSessionId() : ""; Calendar cal = Calendar.getInstance(); logger.info("Login Successful:" + auth.getName() + " | Ip Address:" + remoteAddress + " | sessionId=" + sessionId + " | Epoch=" +cal.getTimeInMillis() ); // success logins are processed further in // AKASecurityContextFormationFilter }