本文整理汇总了Java中org.springframework.security.authentication.event.AbstractAuthenticationEvent.getAuthentication方法的典型用法代码示例。如果您正苦于以下问题:Java AbstractAuthenticationEvent.getAuthentication方法的具体用法?Java AbstractAuthenticationEvent.getAuthentication怎么用?Java AbstractAuthenticationEvent.getAuthentication使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.security.authentication.event.AbstractAuthenticationEvent
的用法示例。
在下文中一共展示了AbstractAuthenticationEvent.getAuthentication方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
}
示例2: 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);
}
}
示例3: 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();
}
}
示例4: 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();
}
}
示例5: createEvent
import org.springframework.security.authentication.event.AbstractAuthenticationEvent; //导入方法依赖的package包/类
private EventBuilder createEvent(String uei, AbstractAuthenticationEvent authEvent) {
EventBuilder builder = new EventBuilder(uei, "OpenNMS.WebUI");
builder.setTime(new Date(authEvent.getTimestamp()));
org.springframework.security.core.Authentication auth = authEvent.getAuthentication();
if (auth != null && auth.getName() != null) {
builder.addParam("user", WebSecurityUtils.sanitizeString(auth.getName()));
}
if (auth != null && auth.getDetails() != null && auth.getDetails() instanceof WebAuthenticationDetails) {
WebAuthenticationDetails webDetails = (WebAuthenticationDetails) auth.getDetails();
if (webDetails.getRemoteAddress() != null) {
builder.addParam("ip", webDetails.getRemoteAddress());
}
}
return builder;
}