本文整理汇总了Java中org.springframework.security.authentication.event.AuthenticationSuccessEvent.getAuthentication方法的典型用法代码示例。如果您正苦于以下问题:Java AuthenticationSuccessEvent.getAuthentication方法的具体用法?Java AuthenticationSuccessEvent.getAuthentication怎么用?Java AuthenticationSuccessEvent.getAuthentication使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.security.authentication.event.AuthenticationSuccessEvent
的用法示例。
在下文中一共展示了AuthenticationSuccessEvent.getAuthentication方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: loginSuccess
import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入方法依赖的package包/类
public void loginSuccess(AuthenticationSuccessEvent event) {
Authentication authentication = event.getAuthentication();
update(authentication.getPrincipal(), true);
}
示例3: onApplicationEvent
import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入方法依赖的package包/类
@Override
public void onApplicationEvent(ApplicationEvent event) {
if(event instanceof AuthenticationSuccessEvent) {
AuthenticationSuccessEvent successEvent =
(AuthenticationSuccessEvent) event;
final Authentication authentication = successEvent.getAuthentication();
final OpenAMUserdetails details = (OpenAMUserdetails) authentication.getDetails();
final String nickname = details.getUsername();
Query query = new Query();
query.addCriteria(Criteria.where("nickName").is(nickname));
final String surname = details.getAttributeValue("sn");
final String givenname = details.getAttributeValue("givenname");
final String email = details.getAttributeValue("mail");
Update update = new Update();
update.set("email", email);
update.set("givenName", givenname);
update.set("surName", surname);
update.set("lastLogin", new Date());
try {
update.set("gravatar", User.md5Hex(email));
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
LOGGER.error("Failed while calculating gravatar hash!");
}
final User user = mongoTemplate.findAndModify(query, update, FindAndModifyOptions.options().upsert(true).returnNew(true), User.class);
if (user != null) {
LOGGER.debug("LoginEvent for user: " + user.toString());
} else {
LOGGER.debug("Upsert didn't return new user!");
}
}
}
示例4: onApplicationEvent
import org.springframework.security.authentication.event.AuthenticationSuccessEvent; //导入方法依赖的package包/类
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof AuthenticationSuccessEvent) {
try {
AuthenticationSuccessEvent success = (AuthenticationSuccessEvent) event;
Authentication auth = success.getAuthentication();
// LOG.debug("LoginLog auth = " + auth.toString());
Object principal = auth.getPrincipal();
if (!(principal instanceof EgovUserDetails) ) {
return;
}
EgovUserDetails details = (EgovUserDetails) principal;
LoginVO loginVO = (LoginVO) details.getEgovUserVO();
String uniqId = "unknown";
String ip = "";
if( loginVO != null ) {
uniqId = loginVO.getUniqId();
ip = loginVO.getIp();
}
if( "127.0.0.1".equals(ip)) return;
if (LOG.isDebugEnabled()) {
LOG.debug("Execute login log!!");
}
LoginLogVO loginLogVO = new LoginLogVO();
loginLogVO.setLoginId(uniqId);
loginLogVO.setLoginIp(ip);
loginLogVO.setLoginMthd("I"); // 로그인:I, 로그아웃:O
loginLogVO.setErrOccrrAt("N");
loginLogVO.setErrorCode("");
loginLogService.logInsertLoginLog(loginLogVO);
} catch(Exception Ex) {
LOG.error("Error !! " + Ex.getMessage());
}
}
}