本文整理汇总了Java中org.springframework.security.authentication.event.AuthenticationSuccessEvent类的典型用法代码示例。如果您正苦于以下问题:Java AuthenticationSuccessEvent类的具体用法?Java AuthenticationSuccessEvent怎么用?Java AuthenticationSuccessEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AuthenticationSuccessEvent类属于org.springframework.security.authentication.event包,在下文中一共展示了AuthenticationSuccessEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onApplicationEvent
import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
@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());
}
}
示例2: onApplicationEvent
import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
@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());
}
}
示例3: attemptAuthentication
import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
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;
}
}
示例4: attemptAuthentication
import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
@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;
}
}
示例5: onApplicationEvent
import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
@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 );
}
}
示例6: handleAuthenticationSuccessEvent
import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
/**
* Обрабатывает событие успешной аутентификации
*
* @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);
}
}
示例7: onApplicationEvent
import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
@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();
}
}
示例8: attemptAuthentication
import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
@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;
}
}
示例9: onApplicationEvent
import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
/**
* 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());
}
示例10: storeLogMessage
import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
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);
}
}
示例11: logToAuditService
import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
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());
}
}
示例12: auditLoginSuccessEvent
import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
@Transactional
public void auditLoginSuccessEvent(AuthenticationSuccessEvent successEvent) {
final AccountActivityMessage message = createLogMessage(
null, successEvent.getAuthentication(),
AccountActivityMessage.ActivityType.LOGIN_SUCCESS);
logMessageRepository.save(message);
}
示例13: testAuditLogin_success
import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
@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);
}
示例14: onApplicationEvent
import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
@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);
}
}
示例15: handle
import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入依赖的package包/类
@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);
}
}