当前位置: 首页>>代码示例>>Java>>正文


Java AbstractAuthenticationEvent.getAuthentication方法代码示例

本文整理汇总了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());
    }
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:12,代码来源:AuthenticationAuditEventListener.java

示例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);
	}
}
 
开发者ID:openanalytics,项目名称:shinyproxy,代码行数:13,代码来源:UserService.java

示例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();
       }
	
}
 
开发者ID:ishaigor,项目名称:rest-retro-sample,代码行数:33,代码来源:OAuthPostAuthListener.java

示例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();
       }
	
}
 
开发者ID:ishaigor,项目名称:rest-retro-sample,代码行数:33,代码来源:OAuthPostAuthListener.java

示例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;
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:16,代码来源:SecurityAuthenticationEventOnmsEventBuilder.java


注:本文中的org.springframework.security.authentication.event.AbstractAuthenticationEvent.getAuthentication方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。