public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response)
throws AuthenticationException, IOException, ServletException {
try {
OAuth2AccessToken accessToken = restTemplate.getAccessToken();
FacebookUser facebookUser = userIdentity.findOrCreateFrom(accessToken);
repository.save(facebookUser);
Authentication authentication = new UsernamePasswordAuthenticationToken(
facebookUser, null, Arrays.asList(new SimpleGrantedAuthority("ROLE_USER")));
publish(new AuthenticationSuccessEvent(authentication));
return authentication;
} catch (OAuth2Exception e) {
BadCredentialsException error = new BadCredentialsException(
"Cannot retrieve the access token", e);
publish(new OAuth2AuthenticationFailureEvent(error));
throw error;
}
}
java类org.springframework.security.authentication.event.AuthenticationSuccessEvent的实例源码
FacebookLoginFilter.java 文件源码
项目:OAuth-2.0-Cookbook
阅读 39
收藏 0
点赞 0
评论 0
OpenIdConnectFilter.java 文件源码
项目:OAuth-2.0-Cookbook
阅读 27
收藏 0
点赞 0
评论 0
@Override
public Authentication attemptAuthentication(
HttpServletRequest request, HttpServletResponse response)
throws AuthenticationException, IOException, ServletException {
try {
OAuth2AccessToken accessToken = restTemplate.getAccessToken();
Claims claims = Claims.createFrom(jsonMapper, accessToken);
GoogleUser googleUser = userIdentity.findOrCreateFrom(claims);
repository.save(googleUser);
Authentication authentication = new UsernamePasswordAuthenticationToken(
googleUser, null, googleUser.getAuthorities());
publish(new AuthenticationSuccessEvent(authentication));
return authentication;
} catch (OAuth2Exception e) {
BadCredentialsException error = new BadCredentialsException(
"Cannot retrieve the access token", e);
publish(new OAuth2AuthenticationFailureEvent(error));
throw error;
}
}
LoggerListener.java 文件源码
项目:document-management-system
阅读 28
收藏 0
点赞 0
评论 0
@Override
public void onApplicationEvent(AbstractAuthenticationEvent event) {
if (event instanceof AuthenticationSuccessEvent) {
log.debug("Authentication OK: {}", event.getAuthentication().getName());
// Activity log
Object details = event.getAuthentication().getDetails();
String params = null;
if (details instanceof WebAuthenticationDetails) {
WebAuthenticationDetails wad = (WebAuthenticationDetails) details;
params = wad.getRemoteAddress();
} else if (GenericHolder.get() != null) {
params = (String) GenericHolder.get();
}
UserActivity.log(event.getAuthentication().getName(), "LOGIN", null, null, params);
} else if (event instanceof AuthenticationFailureBadCredentialsEvent) {
log.info("Authentication ERROR: {}", event.getAuthentication().getName());
}
}
AuthenticationListener.java 文件源码
项目:dhis2-core
阅读 35
收藏 0
点赞 0
评论 0
@Override
public void onApplicationEvent( final AuthenticationSuccessEvent authenticationSuccessEvent )
{
final String username = authenticationSuccessEvent.getAuthentication().getName();
UserCredentials credentials = userService.getUserCredentialsByUsername( username );
boolean readOnly = config.isReadOnlyMode();
if ( Objects.nonNull( credentials ) && !readOnly )
{
credentials.updateLastLogin();
userService.updateUserCredentials( credentials );
}
if ( credentials != null )
{
securityService.registerSuccessfulLogin( username );
}
}
InternalAuthenticationProvider.java 文件源码
项目:auth-server
阅读 36
收藏 0
点赞 0
评论 0
@Override
public void onApplicationEvent(AbstractAuthenticationEvent appEvent) {
String currentUserName = extractUserName(appEvent);
if (currentUserName == null || isLockMechanismDisabled()) {
return;
}
if (appEvent instanceof AuthenticationSuccessEvent &&
accessCounter.containsKey(currentUserName) &&
accessCounter.get(currentUserName) < maxLoginFailures) {
accessCounter.remove(currentUserName);
lastFailedLogin.remove(currentUserName);
}
if (appEvent instanceof AuthenticationFailureBadCredentialsEvent) {
if (accessCounter.containsKey(currentUserName)) {
accessCounter.put(currentUserName, accessCounter.get(currentUserName) + 1);
} else {
accessCounter.put(currentUserName, 1);
}
lastFailedLogin.put(currentUserName, new Date());
}
}
InternalAuthenticationProvider.java 文件源码
项目:osiam
阅读 34
收藏 0
点赞 0
评论 0
@Override
public void onApplicationEvent(AbstractAuthenticationEvent appEvent) {
String currentUserName = extractUserName(appEvent);
if (currentUserName == null || isLockMechanismDisabled()) {
return;
}
if (appEvent instanceof AuthenticationSuccessEvent &&
accessCounter.containsKey(currentUserName) &&
accessCounter.get(currentUserName) < maxLoginFailures) {
accessCounter.remove(currentUserName);
lastFailedLogin.remove(currentUserName);
}
if (appEvent instanceof AuthenticationFailureBadCredentialsEvent) {
if (accessCounter.containsKey(currentUserName)) {
accessCounter.put(currentUserName, accessCounter.get(currentUserName) + 1);
} else {
accessCounter.put(currentUserName, 1);
}
lastFailedLogin.put(currentUserName, new Date());
}
}
AuthenticationEventListener.java 文件源码
项目:perecoder
阅读 27
收藏 0
点赞 0
评论 0
/**
* Обрабатывает событие успешной аутентификации
*
* @param event событие
*/
private void handleAuthenticationSuccessEvent(AuthenticationSuccessEvent event) {
if (LOG.isInfoEnabled()) {
Authentication authentication = event.getAuthentication();
String commonMessage = String.format(
SUCCESS_TEMPLATE,
DateUtil.formatDateTime(new Date(event.getTimestamp())),
extractPrincipal(authentication),
StringUtils.collectionToCommaDelimitedString(authentication.getAuthorities())
);
String detailsMessage = (authentication.getDetails() != null) ? OBJECT_HEX_PATTERN.matcher(authentication.getDetails().toString()).replaceAll("") : null;
String resultMessage = StringUtils.hasText(detailsMessage) ? String.format(DETAILS_TEMPLATE, commonMessage, detailsMessage) : commonMessage;
LOG.info(resultMessage);
}
}
UserAuthenticationSuccess.java 文件源码
项目:devops-cstack
阅读 27
收藏 0
点赞 0
评论 0
@Override
public void onApplicationEvent(AuthenticationSuccessEvent event) {
try {
User user = userService.findByLogin(((UserDetails) event.getAuthentication().getPrincipal()).getUsername());
user.setLastConnection(new Date());
userService.update(user);
} catch (ServiceException e) {
e.printStackTrace();
}
}
OpenIdConnectFilter.java 文件源码
项目:OAuth-2.0-Cookbook
阅读 28
收藏 0
点赞 0
评论 0
@Override
public Authentication attemptAuthentication(
HttpServletRequest request, HttpServletResponse response)
throws AuthenticationException, IOException, ServletException {
try {
OAuth2AccessToken accessToken = restTemplate.getAccessToken();
Claims claims = Claims.createFrom(jsonMapper, accessToken);
GoogleUser googleUser = userIdentity.findOrCreateFrom(claims);
String userName = getUserNameFromUserInfo(accessToken,
googleUser.getOpenIDAuthentication().getSubject());
googleUser.getOpenIDAuthentication().setName(userName);
repository.save(googleUser);
Authentication authentication = new UsernamePasswordAuthenticationToken(
googleUser, null, googleUser.getAuthorities());
publish(new AuthenticationSuccessEvent(authentication));
return authentication;
} catch (OAuth2Exception e) {
BadCredentialsException error = new BadCredentialsException(
"Cannot retrieve the access token", e);
publish(new OAuth2AuthenticationFailureEvent(error));
throw error;
}
}
AuthenticationSuccessEventListener.java 文件源码
项目:Sound.je
阅读 31
收藏 0
点赞 0
评论 0
/**
* record successful login attempt
*
* @param e authentication success event
*/
@Override
public void onApplicationEvent(final AuthenticationSuccessEvent e) {
final WebAuthenticationDetails auth = (WebAuthenticationDetails)
e.getAuthentication().getDetails();
final String email = e.getAuthentication().getPrincipal().toString();
loginAttemptService.loginSucceeded(email, auth.getRemoteAddress());
}
AuthenticationAuditEventListener.java 文件源码
项目:oma-riista-web
阅读 32
收藏 0
点赞 0
评论 0
private void storeLogMessage(final AbstractAuthenticationEvent event) {
try {
if (event instanceof InteractiveAuthenticationSuccessEvent) {
accountAuditService.auditLoginSuccessEvent(InteractiveAuthenticationSuccessEvent.class.cast(event));
} else if (event instanceof AuthenticationSuccessEvent) {
accountAuditService.auditLoginSuccessEvent(AuthenticationSuccessEvent.class.cast(event));
} else if (event instanceof AbstractAuthenticationFailureEvent) {
accountAuditService.auditLoginFailureEvent(AbstractAuthenticationFailureEvent.class.cast(event));
}
} catch (Exception ex) {
LOG.error("Failed to audit authentication event in database", ex);
}
}
AuthenticationAuditEventListener.java 文件源码
项目:oma-riista-web
阅读 29
收藏 0
点赞 0
评论 0
private void logToAuditService(AbstractAuthenticationEvent event) {
if (event instanceof AuthenticationSuccessEvent) {
final Authentication authentication = event.getAuthentication();
final ImmutableMap.Builder<String, Object> extra = auditService.extra("remoteAddress",
getRemoteAddress(authentication));
addGrantedAuthorities(authentication, extra);
addSource(event, extra);
auditService.log("loginSuccess", authentication.getName(), extra.build());
}
}
AccountAuditService.java 文件源码
项目:oma-riista-web
阅读 28
收藏 0
点赞 0
评论 0
@Transactional
public void auditLoginSuccessEvent(AuthenticationSuccessEvent successEvent) {
final AccountActivityMessage message = createLogMessage(
null, successEvent.getAuthentication(),
AccountActivityMessage.ActivityType.LOGIN_SUCCESS);
logMessageRepository.save(message);
}
AccountAuditServiceTest.java 文件源码
项目:oma-riista-web
阅读 34
收藏 0
点赞 0
评论 0
@Test
public void testAuditLogin_success() {
final AuthenticationSuccessEvent event = new AuthenticationSuccessEvent(authMock);
auditService.auditLoginSuccessEvent(event);
verify(accountActivityMessageRepository, times(1))
.save(argThat(matches(true, username, null)));
verifyNoMoreInteractions(accountActivityMessageRepository);
}
AuthenticationSuccessListener.java 文件源码
项目:graviteeio-access-management
阅读 23
收藏 0
点赞 0
评论 0
@Override
public void onApplicationEvent(AuthenticationSuccessEvent event) {
final User principal = (User) event.getAuthentication().getPrincipal();
Map<String, String> details = (Map<String, String>) event.getAuthentication().getDetails();
try {
io.gravitee.am.model.User user = userService.loadUserByUsernameAndDomain(domain.getId(), principal.getUsername());
UpdateUser updateUser = new UpdateUser();
if (details != null) {
updateUser.setSource(details.get(RepositoryProviderUtils.SOURCE));
updateUser.setClient(details.get(OAuth2Utils.CLIENT_ID));
}
updateUser.setLoggedAt(new Date());
updateUser.setLoginsCount(user.getLoginsCount() + 1);
updateUser.setAdditionalInformation(principal.getAdditionalInformation());
userService.update(domain.getId(), user.getId(), updateUser);
} catch (UserNotFoundException unfe) {
final NewUser newUser = new NewUser();
newUser.setUsername(principal.getUsername());
if (details != null) {
newUser.setSource(details.get(RepositoryProviderUtils.SOURCE));
newUser.setClient(details.get(OAuth2Utils.CLIENT_ID));
}
newUser.setLoggedAt(new Date());
newUser.setLoginsCount(1l);
newUser.setAdditionalInformation(principal.getAdditionalInformation());
userService.create(domain.getId(), newUser);
}
}
LoginSuccessEventListener.java 文件源码
项目:pcm-api
阅读 30
收藏 0
点赞 0
评论 0
@Override
public void handle(Object event) {
AuthenticationSuccessEvent loginSuccessEvent = (AuthenticationSuccessEvent) event;
Object name = loginSuccessEvent.getAuthentication().getPrincipal();
if (name != null) {
Users user = (Users) name;
user.setFailedLoginAttemptsToZero();
usersRepository.updateUser(user);
}
}
LoginSuccessEventListenerTest.java 文件源码
项目:pcm-api
阅读 30
收藏 0
点赞 0
评论 0
@Test
public void testHandle() {
AuthenticationSuccessEvent loginSuccessEvent=mock(AuthenticationSuccessEvent.class);
Authentication authentication=mock(Authentication.class);
Users user=mock(Users.class);
when(loginSuccessEvent.getAuthentication()).thenReturn(authentication);
when(authentication.getPrincipal()).thenReturn(user);
loginSuccessEventListener.handle(loginSuccessEvent);
verify(user).setFailedLoginAttemptsToZero();
verify(usersRepository).updateUser(user);
}
AuthenticationSuccessEventListener.java 文件源码
项目:spring-boot
阅读 33
收藏 0
点赞 0
评论 0
@Override
public void onApplicationEvent(final AuthenticationSuccessEvent e) {
final WebAuthenticationDetails auth = (WebAuthenticationDetails) e.getAuthentication().getDetails();
if (auth != null) {
loginAttemptService.loginSucceeded(auth.getRemoteAddress());
}
}
AuthenticationAuditListener.java 文件源码
项目:https-github.com-g0t4-jenkins2-course-spring-boot
阅读 34
收藏 0
点赞 0
评论 0
@Override
public void onApplicationEvent(AbstractAuthenticationEvent event) {
if (event instanceof AbstractAuthenticationFailureEvent) {
onAuthenticationFailureEvent((AbstractAuthenticationFailureEvent) event);
}
else if (this.webListener != null && this.webListener.accepts(event)) {
this.webListener.process(this, event);
}
else if (event instanceof AuthenticationSuccessEvent) {
onAuthenticationSuccessEvent((AuthenticationSuccessEvent) event);
}
}
AuthenticationAuditListener.java 文件源码
项目:https-github.com-g0t4-jenkins2-course-spring-boot
阅读 85
收藏 0
点赞 0
评论 0
private void onAuthenticationSuccessEvent(AuthenticationSuccessEvent event) {
Map<String, Object> data = new HashMap<String, Object>();
if (event.getAuthentication().getDetails() != null) {
data.put("details", event.getAuthentication().getDetails());
}
publish(new AuditEvent(event.getAuthentication().getName(),
"AUTHENTICATION_SUCCESS", data));
}
UserService.java 文件源码
项目:shinyproxy
阅读 31
收藏 0
点赞 0
评论 0
@Override
public void onApplicationEvent(AbstractAuthenticationEvent event) {
Authentication source = event.getAuthentication();
if (event instanceof AbstractAuthenticationFailureEvent) {
Exception e = ((AbstractAuthenticationFailureEvent) event).getException();
log.info(String.format("Authentication failure [user: %s] [error: %s]", source.getName(), e.getMessage()));
} else if (event instanceof AuthenticationSuccessEvent) {
String userName = source.getName();
log.info(String.format("User logged in [user: %s]", userName));
eventService.post(EventType.Login.toString(), userName, null);
}
}
AuthenticationSuccessEventListener.java 文件源码
项目:spring-security-registration
阅读 35
收藏 0
点赞 0
评论 0
@Override
public void onApplicationEvent(final AuthenticationSuccessEvent e) {
// final WebAuthenticationDetails auth = (WebAuthenticationDetails) e.getAuthentication().getDetails();
// if (auth != null) {
// loginAttemptService.loginSucceeded(auth.getRemoteAddress());
// }
final String xfHeader = request.getHeader("X-Forwarded-For");
if (xfHeader == null) {
loginAttemptService.loginSucceeded(request.getRemoteAddr());
} else {
loginAttemptService.loginSucceeded(xfHeader.split(",")[0]);
}
}
AuthenticationAuditListener.java 文件源码
项目:spring-boot-concourse
阅读 43
收藏 0
点赞 0
评论 0
@Override
public void onApplicationEvent(AbstractAuthenticationEvent event) {
if (event instanceof AbstractAuthenticationFailureEvent) {
onAuthenticationFailureEvent((AbstractAuthenticationFailureEvent) event);
}
else if (this.webListener != null && this.webListener.accepts(event)) {
this.webListener.process(this, event);
}
else if (event instanceof AuthenticationSuccessEvent) {
onAuthenticationSuccessEvent((AuthenticationSuccessEvent) event);
}
}
AuthenticationAuditListener.java 文件源码
项目:spring-boot-concourse
阅读 28
收藏 0
点赞 0
评论 0
private void onAuthenticationSuccessEvent(AuthenticationSuccessEvent event) {
Map<String, Object> data = new HashMap<String, Object>();
if (event.getAuthentication().getDetails() != null) {
data.put("details", event.getAuthentication().getDetails());
}
publish(new AuditEvent(event.getAuthentication().getName(),
"AUTHENTICATION_SUCCESS", data));
}
AuthenticationSuccessListener.java 文件源码
项目:gravitee-management-rest-api
阅读 31
收藏 0
点赞 0
评论 0
@Override
public void onApplicationEvent(AuthenticationSuccessEvent event) {
final UserDetails details = (UserDetails) event.getAuthentication().getPrincipal();
try {
userService.findByName(details.getUsername(), false);
} catch (UserNotFoundException unfe) {
final NewExternalUserEntity newUser = new NewExternalUserEntity();
newUser.setUsername(details.getUsername());
newUser.setSource(details.getSource());
newUser.setSourceId(details.getSourceId());
newUser.setFirstname(details.getFirstname());
newUser.setLastname(details.getLastname());
newUser.setEmail(details.getEmail());
boolean addDefaultRole = false;
if (event.getAuthentication().getAuthorities() == null || event.getAuthentication().getAuthorities().isEmpty()) {
addDefaultRole = true;
}
userService.create(newUser, addDefaultRole);
if (!addDefaultRole) {
addRole(RoleScope.MANAGEMENT, newUser.getUsername(), event.getAuthentication().getAuthorities());
addRole(RoleScope.PORTAL, newUser.getUsername(), event.getAuthentication().getAuthorities());
}
}
userService.connect(details.getUsername());
}
SuccessfulLoginListener.java 文件源码
项目:webanno
阅读 33
收藏 0
点赞 0
评论 0
@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);
}
}
AuthenticationSuccessEventListener.java 文件源码
项目:SpringSecurity-registration-login
阅读 31
收藏 0
点赞 0
评论 0
@Override
public void onApplicationEvent(final AuthenticationSuccessEvent e) {
final WebAuthenticationDetails auth = (WebAuthenticationDetails) e.getAuthentication().getDetails();
if (auth != null) {
loginAttemptService.loginSucceeded(auth.getRemoteAddress());
}
}
UserLoginListener.java 文件源码
项目:find
阅读 34
收藏 0
点赞 0
评论 0
@Override
public void onApplicationEvent(final AuthenticationSuccessEvent authenticationSuccessEvent) {
final Object principal = authenticationSuccessEvent.getAuthentication().getPrincipal();
if (principal instanceof CommunityPrincipal) {
final CommunityPrincipal communityPrincipal = (CommunityPrincipal) principal;
final String principalUsername = communityPrincipal.getUsername();
userEntityService.getOrCreate(principalUsername);
}
}
SuccessfulAuthHandler.java 文件源码
项目:freezo
阅读 31
收藏 0
点赞 0
评论 0
@Override
@Transactional
public void onApplicationEvent(final AuthenticationSuccessEvent event)
{
final Account account = ((User) event.getAuthentication().getPrincipal()).getAccount();
account.setFailedAuthCounter(0);
account.setLastSuccessAuth(new Date());
account.setLastSuccessAuthIp(currentRequestRemoteAddr());
repository.save(account);
}
AuthenticationEventListener.java 文件源码
项目:perecoder
阅读 32
收藏 0
点赞 0
评论 0
@Override
public void onApplicationEvent(AbstractAuthenticationEvent event) {
// Authentication success
if (event instanceof AuthenticationSuccessEvent) {
handleAuthenticationSuccessEvent((AuthenticationSuccessEvent) event);
}
// Authentication failure
if (event instanceof AbstractAuthenticationFailureEvent) {
handleAuthenticationFailureEvent((AbstractAuthenticationFailureEvent) event);
}
// Authentication clear
if (event instanceof AuthenticationCleanedEvent) {
handleAuthenticationCleanedEvent((AuthenticationCleanedEvent) event);
}
}