本文整理汇总了Java中org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent.getAuthentication方法的典型用法代码示例。如果您正苦于以下问题:Java AuthenticationFailureBadCredentialsEvent.getAuthentication方法的具体用法?Java AuthenticationFailureBadCredentialsEvent.getAuthentication怎么用?Java AuthenticationFailureBadCredentialsEvent.getAuthentication使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent
的用法示例。
在下文中一共展示了AuthenticationFailureBadCredentialsEvent.getAuthentication方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: logBadCredential
import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent; //导入方法依赖的package包/类
public void logBadCredential(ApplicationEvent event) throws Exception {
AuthenticationFailureBadCredentialsEvent authenticationFailureBadCredentialsEvent = (AuthenticationFailureBadCredentialsEvent) event;
Authentication authentication = authenticationFailureBadCredentialsEvent
.getAuthentication();
logger.info("{}", authentication);
String tenantId = this.getTenantId(authentication);
Object principal = authentication.getPrincipal();
String userId = null;
if (principal instanceof SpringSecurityUserAuth) {
userId = ((SpringSecurityUserAuth) principal).getId();
} else {
userId = authentication.getName();
}
AuditDTO auditDto = new AuditDTO();
auditDto.setUserId(userId);
auditDto.setAuditTime(new Date());
auditDto.setAction("login");
auditDto.setResult("failure");
auditDto.setApplication("lemon");
auditDto.setClient(getUserIp(authentication));
auditDto.setServer(InetAddress.getLocalHost().getHostAddress());
auditDto.setDescription(authenticationFailureBadCredentialsEvent
.getException().getMessage());
auditDto.setTenantId(tenantId);
auditConnector.log(auditDto);
ctx.publishEvent(new LoginEvent(authentication, userId, this
.getSessionId(authentication), "badCredentials", "default",
tenantId));
}
示例2: onApplicationEvent
import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent; //导入方法依赖的package包/类
@Override
public void onApplicationEvent(AuthenticationFailureBadCredentialsEvent event) {
Authentication authentication = event.getAuthentication();
saveEvent(loginlogService, authentication);
}