本文整理汇总了Java中org.springframework.security.oauth2.provider.OAuth2Authentication.getDetails方法的典型用法代码示例。如果您正苦于以下问题:Java OAuth2Authentication.getDetails方法的具体用法?Java OAuth2Authentication.getDetails怎么用?Java OAuth2Authentication.getDetails使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.security.oauth2.provider.OAuth2Authentication
的用法示例。
在下文中一共展示了OAuth2Authentication.getDetails方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: oauth2ClientContext
import org.springframework.security.oauth2.provider.OAuth2Authentication; //导入方法依赖的package包/类
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public DefaultOAuth2ClientContext oauth2ClientContext() {
DefaultOAuth2ClientContext context = new DefaultOAuth2ClientContext(
new DefaultAccessTokenRequest());
Authentication principal = SecurityContextHolder.getContext()
.getAuthentication();
if (principal instanceof OAuth2Authentication) {
OAuth2Authentication authentication = (OAuth2Authentication) principal;
Object details = authentication.getDetails();
if (details instanceof OAuth2AuthenticationDetails) {
OAuth2AuthenticationDetails oauthsDetails = (OAuth2AuthenticationDetails) details;
String token = oauthsDetails.getTokenValue();
context.setAccessToken(new DefaultOAuth2AccessToken(token));
}
}
return context;
}
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:19,代码来源:OAuth2RestOperationsConfiguration.java
示例2: extractCurrentToken
import org.springframework.security.oauth2.provider.OAuth2Authentication; //导入方法依赖的package包/类
public static String extractCurrentToken() {
final OAuth2Authentication auth = getAuthentication();
if (auth == null) {
throw new IllegalStateException("Cannot get current authentication object");
}
if (auth.getDetails() == null) {
return null;
}
if (auth.getDetails() instanceof OAuth2AuthenticationDetails) {
return (OAuth2AuthenticationDetails.class.cast(auth.getDetails())).getTokenValue();
}
if (auth.getDetails() instanceof String) {
return String.valueOf(auth.getDetails());
}
return null;
}
示例3: setUserTenantContext
import org.springframework.security.oauth2.provider.OAuth2Authentication; //导入方法依赖的package包/类
private String setUserTenantContext(HttpServletRequest request) {
String tenant;
final OAuth2Authentication auth = getAuthentication();
if (auth == null) {
tenant = request.getHeader(HEADER_TENANT);
TenantContext.setCurrent(tenant);
} else {
Map<String, String> details = null;
if (auth.getDetails() != null) {
details = Map.class.cast(OAuth2AuthenticationDetails.class.cast(auth.getDetails())
.getDecodedDetails());
}
details = firstNonNull(details, new HashMap<>());
tenant = details.getOrDefault(AUTH_TENANT_KEY, "");
String xmUserKey = details.getOrDefault(AUTH_USER_KEY, "");
String userLogin = (String) auth.getPrincipal();
TenantContext.setCurrent(new TenantInfo(tenant, userLogin, xmUserKey));
}
return tenant;
}
示例4: fetch
import org.springframework.security.oauth2.provider.OAuth2Authentication; //导入方法依赖的package包/类
public static EAccessToken fetch(OAuth2Authentication oAuth2Authentication, OAuth2AccessToken accessToken){
EAccessToken eAccessToken = new EAccessToken();
eAccessToken.setOpenUser(fetch(oAuth2Authentication));
Object details = oAuth2Authentication.getDetails();
if(details instanceof OAuth2AuthenticationDetails){
OAuth2AuthenticationDetails details1 = (OAuth2AuthenticationDetails) details;
eAccessToken.setRemoteAddress(details1.getRemoteAddress());
eAccessToken.setSessionId(details1.getSessionId());
}
eAccessToken.setTokenType(accessToken.getTokenType());
eAccessToken.setTokenValue(accessToken.getValue());
eAccessToken.setExpiresIn(accessToken.getExpiresIn());
if (accessToken.getRefreshToken() != null) {
eAccessToken.setRefreshToken(accessToken.getRefreshToken().getValue());
}
if (accessToken.getScope() != null) {
String scopes = Strings.join2("|", accessToken.getScope().toArray(new String[]{}));
eAccessToken.setScopes(scopes);
}
return eAccessToken;
}
示例5: getWebSocketHttpHeaders
import org.springframework.security.oauth2.provider.OAuth2Authentication; //导入方法依赖的package包/类
@Override
public WebSocketHttpHeaders getWebSocketHttpHeaders(final WebSocketSession userAgentSession) {
WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
Principal principal = userAgentSession.getPrincipal();
if (principal != null && OAuth2Authentication.class.isAssignableFrom(principal.getClass())) {
OAuth2Authentication oAuth2Authentication = (OAuth2Authentication) principal;
OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) oAuth2Authentication.getDetails();
String accessToken = details.getTokenValue();
headers.put(HttpHeaders.AUTHORIZATION, Collections.singletonList("Bearer " + accessToken));
if(logger.isDebugEnabled()) {
logger.debug("Added Oauth2 bearer token authentication header for user " +
principal.getName() + " to web sockets http headers");
}
}
else {
if(logger.isDebugEnabled()) {
logger.debug("Skipped adding basic authentication header since user session principal is null");
}
}
return headers;
}
开发者ID:mthizo247,项目名称:spring-cloud-netflix-zuul-websocket,代码行数:22,代码来源:OAuth2BearerPrincipalHeadersCallback.java
示例6: getTenant
import org.springframework.security.oauth2.provider.OAuth2Authentication; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static String getTenant(HttpServletRequest request) {
final OAuth2Authentication auth = getAuthentication();
if (auth == null) {
return request.getHeader(HEADER_TENANT);
} else if (auth.getDetails() != null) {
Map<String, String> details = firstNonNull((Map)(((OAuth2AuthenticationDetails) auth.getDetails())
.getDecodedDetails()), new HashMap<>());
return details.getOrDefault(AUTH_TENANT_KEY, "");
}
return null;
}
示例7: getUserKey
import org.springframework.security.oauth2.provider.OAuth2Authentication; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private String getUserKey() {
final OAuth2Authentication auth = getAuthentication();
if (auth != null && auth.getDetails() != null) {
Map<String, String> details = firstNonNull((Map)(((OAuth2AuthenticationDetails) auth.getDetails())
.getDecodedDetails()), new HashMap<>());
return details.getOrDefault(AUTH_USER_KEY, "");
}
return null;
}
示例8: enhance
import org.springframework.security.oauth2.provider.OAuth2Authentication; //导入方法依赖的package包/类
@Override
public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
@SuppressWarnings("unchecked") final Map<String, Object> authDetails = (Map<String, Object>) authentication
.getDetails();
if (authDetails != null) {
((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(authDetails);
}
return super.enhance(accessToken, authentication);
}
示例9: getSessionFromPrincipal
import org.springframework.security.oauth2.provider.OAuth2Authentication; //导入方法依赖的package包/类
private Session getSessionFromPrincipal(Principal principal) {
OAuth2Authentication oauth2Authentication = (OAuth2Authentication)principal;
OAuth2AuthenticationDetails oAuth2AuthenticationDetails = (OAuth2AuthenticationDetails)oauth2Authentication.getDetails();
String sessionId = oAuth2AuthenticationDetails.getSessionId();
return sessionRepository.getSession(sessionId);
}
示例10: getUserDetails
import org.springframework.security.oauth2.provider.OAuth2Authentication; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private Map<String, String> getUserDetails(OAuth2Authentication auth) {
Map<String, String> details = null;
if (auth.getDetails() != null) {
details = Map.class.cast(OAuth2AuthenticationDetails.class.cast(auth.getDetails()).getDecodedDetails());
}
details = firstNonNull(details, new HashMap<>());
return details;
}
示例11: extractCurrentToken
import org.springframework.security.oauth2.provider.OAuth2Authentication; //导入方法依赖的package包/类
/**
* Get the authentication token of the current user.
*
* @return the token of the current user
*/
public static String extractCurrentToken() {
final OAuth2Authentication auth = getAuthentication();
if (auth == null) {
throw new IllegalStateException("Cannot get current authentication object");
}
if (auth.getDetails() == null) {
return null;
}
return (OAuth2AuthenticationDetails.class.cast(auth.getDetails())).getTokenValue();
}
示例12: endPointUser
import org.springframework.security.oauth2.provider.OAuth2Authentication; //导入方法依赖的package包/类
@PreAuthorize("hasRole('ROLE_USER')")
@RequestMapping(value = "/endpointuser", method = RequestMethod.GET)
public ResponseEntity<String> endPointUser(OAuth2Authentication authentication) {
OAuth2AuthenticationDetails oAuth2AuthenticationDetails = (OAuth2AuthenticationDetails) authentication.getDetails();
Map<String, Object> additionalInfo = tokenServices.readAccessToken(oAuth2AuthenticationDetails.getTokenValue()).getAdditionalInformation();
return new ResponseEntity<String>("Your UUID: " + additionalInfo.get("uuid").toString()
+ " , your username: " + authentication.getPrincipal() + " and your role USER",
HttpStatus.OK);
}
示例13: endPointAdmin
import org.springframework.security.oauth2.provider.OAuth2Authentication; //导入方法依赖的package包/类
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/endpointadmin", method = RequestMethod.GET)
public ResponseEntity<String> endPointAdmin(OAuth2Authentication authentication) {
OAuth2AuthenticationDetails oAuth2AuthenticationDetails = (OAuth2AuthenticationDetails) authentication.getDetails();
Map<String, Object> additionalInfo = tokenServices.readAccessToken(oAuth2AuthenticationDetails.getTokenValue()).getAdditionalInformation();
return new ResponseEntity<String>("Your UUID: " + additionalInfo.get("uuid").toString()
+ " , your username: " + authentication.getPrincipal() + " and your role ADMIN",
HttpStatus.OK);
}
示例14: setUserTenantContext
import org.springframework.security.oauth2.provider.OAuth2Authentication; //导入方法依赖的package包/类
private String setUserTenantContext(HttpServletRequest request) {
String tenant;
final OAuth2Authentication auth = getAuthentication();
if (auth == null) {
tenant = request.getHeader(Constants.HEADER_TENANT);
TenantContext.setCurrent(tenant);
} else {
Map<String, String> details = null;
if (auth.getDetails() != null) {
details = Map.class.cast(OAuth2AuthenticationDetails.class.cast(auth.getDetails())
.getDecodedDetails());
}
details = firstNonNull(details, new HashMap<>());
tenant = details.getOrDefault(AUTH_TENANT_KEY, "");
String xmToken = details.getOrDefault(AUTH_XM_TOKEN_KEY, "");
String xmCookie = details.getOrDefault(AUTH_XM_COOKIE_KEY, "");
String xmUserId = details.getOrDefault(AUTH_XM_USERID_KEY, "");
String xmLocale = details.getOrDefault(AUTH_XM_LOCALE_KEY, "");
String xmUserLogin = (String) auth.getPrincipal();
TenantContext.setCurrent(new TenantInfo(tenant, xmToken, xmCookie, xmUserId, xmLocale, xmUserLogin));
Locale locale = LocaleUtils.getLocaleFromString(xmLocale);
if (locale != null) {
LocaleContextHolder.setLocale(locale);
}
}
return tenant;
}
示例15: authCode
import org.springframework.security.oauth2.provider.OAuth2Authentication; //导入方法依赖的package包/类
@RequestMapping("/secured/show_token")
public String authCode(Model model, HttpServletRequest request) throws Exception {
OAuth2Authentication auth = (OAuth2Authentication)SecurityContextHolder.getContext().getAuthentication();
OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails)auth.getDetails();
String tokenValue = details.getTokenValue();
if (tokenValue != null) {
model.addAttribute("access_token", tokenBeautifier.formatJwtToken(tokenValue));
}
return "show_token";
}