本文整理汇总了Java中org.springframework.security.authentication.event.AbstractAuthenticationEvent类的典型用法代码示例。如果您正苦于以下问题:Java AbstractAuthenticationEvent类的具体用法?Java AbstractAuthenticationEvent怎么用?Java AbstractAuthenticationEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AbstractAuthenticationEvent类属于org.springframework.security.authentication.event包,在下文中一共展示了AbstractAuthenticationEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onApplicationEvent
import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入依赖的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.AbstractAuthenticationEvent; //导入依赖的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: extractUserName
import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入依赖的package包/类
private String extractUserName(AbstractAuthenticationEvent appEvent) {
if (appEvent.getSource() != null && appEvent.getSource() instanceof InternalAuthentication) {
InternalAuthentication internalAuth = (InternalAuthentication) appEvent.getSource();
if (internalAuth.getPrincipal() != null) {
if (internalAuth.getPrincipal() instanceof User) {
User user = (User) internalAuth.getPrincipal();
return user.getUserName();
}
if (internalAuth.getPrincipal() instanceof String) {
return (String) internalAuth.getPrincipal();
}
}
}
return null;
}
示例4: onApplicationEvent
import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(AbstractAuthenticationEvent event) {
final StringBuilder builder = new StringBuilder();
builder.append("Authentication event ");
builder.append(event.getClass().getSimpleName());
builder.append(": ");
builder.append(event.getAuthentication().getName());
builder.append("; details: ");
builder.append(event.getAuthentication().getDetails());
if (event instanceof AbstractAuthenticationFailureEvent) {
builder.append("; exception: ");
builder.append(((AbstractAuthenticationFailureEvent) event)
.getException().getMessage());
}
LOG.warn(builder.toString());
}
示例5: onApplicationEvent
import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入依赖的package包/类
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void onApplicationEvent(AbstractAuthenticationEvent event) {
logToAuditService(event);
emitLogMessage(event);
storeLogMessage(event);
}
示例6: emitLogMessage
import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入依赖的package包/类
private static void emitLogMessage(AbstractAuthenticationEvent event) {
final StringBuilder builder = new StringBuilder();
builder.append("Authentication event ");
builder.append(ClassUtils.getShortName(event.getClass()));
builder.append(": ");
builder.append(event.getAuthentication().getName());
if (event instanceof AbstractAuthenticationFailureEvent) {
builder.append("; exception: ");
builder.append(((AbstractAuthenticationFailureEvent) event).getException().getMessage());
}
LOG.warn(builder.toString());
}
示例7: storeLogMessage
import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入依赖的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);
}
}
示例8: logToAuditService
import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入依赖的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());
}
}
示例9: onApplicationEvent
import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入依赖的package包/类
@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);
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:AuthenticationAuditListener.java
示例10: process
import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入依赖的package包/类
public void process(AuthenticationAuditListener listener,
AbstractAuthenticationEvent input) {
if (listener != null) {
AuthenticationSwitchUserEvent event = (AuthenticationSwitchUserEvent) input;
Map<String, Object> data = new HashMap<String, Object>();
if (event.getAuthentication().getDetails() != null) {
data.put("details", event.getAuthentication().getDetails());
}
data.put("target", event.getTargetUser().getUsername());
listener.publish(new AuditEvent(event.getAuthentication().getName(),
"AUTHENTICATION_SWITCH", data));
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:15,代码来源:AuthenticationAuditListener.java
示例11: onApplicationEvent
import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入依赖的package包/类
@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);
}
}
示例12: onApplicationEvent
import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入依赖的package包/类
@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 {
onAuthenticationEvent(event);
}
}
示例13: onAuthenticationEvent
import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入依赖的package包/类
private void onAuthenticationEvent(AbstractAuthenticationEvent 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));
}
示例14: onApplicationEvent
import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入依赖的package包/类
@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);
}
}
示例15: onApplicationEvent
import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入依赖的package包/类
@Override
public void onApplicationEvent(AbstractAuthenticationEvent event) {
Authentication authentication = event.getAuthentication();
if (event instanceof AuthenticationSuccessEvent) {
ResourceOwnerPasswordResourceDetails resource = getResourceOwnerPasswordResourceDetails();
resource.setScope(Arrays.asList("words"));
resource.setUsername(authentication.getName());
resource.setPassword(authentication.getCredentials().toString());
try {
OAuth2AccessToken accessToken = accessTokenProvider.obtainAccessToken(resource, new DefaultAccessTokenRequest());
log.debug("Access token request succeeded for user: '{}', new token is '{}'"
, resource.getUsername()
, accessToken.getValue());
if (authentication instanceof AbstractAuthenticationToken && authentication.getDetails() instanceof CustomAuthenticationDetails) {
((CustomAuthenticationDetails) ((AbstractAuthenticationToken) authentication).getDetails())
.setBearer(accessToken.getValue());
log.debug("Access token was added to authentication as details");
} else if (log.isDebugEnabled()) {
log.debug("Access token could not be added to authentication as details");
}
} catch (Exception e) {
log.error("Access token request failed for user: '" + resource.getUsername() + "'", e);
}
}
if (authentication instanceof CredentialsContainer) {
// Authentication is complete. Remove credentials and other secret data from authentication
((CredentialsContainer)authentication).eraseCredentials();
}
}