當前位置: 首頁>>代碼示例>>Java>>正文


Java OAuth2Authentication.getDetails方法代碼示例

本文整理匯總了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;
}
 
開發者ID:xm-online,項目名稱:xm-commons,代碼行數:17,代碼來源:TokenUtils.java

示例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;
}
 
開發者ID:xm-online,項目名稱:xm-ms-entity,代碼行數:27,代碼來源:TenantInterceptor.java

示例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;
}
 
開發者ID:DataAgg,項目名稱:DAFramework,代碼行數:23,代碼來源:OAuth2Util.java

示例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;
}
 
開發者ID:xm-online,項目名稱:xm-uaa,代碼行數:13,代碼來源:ProxyFilter.java

示例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;
}
 
開發者ID:xm-online,項目名稱:xm-uaa,代碼行數:11,代碼來源:ProxyFilter.java

示例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);
}
 
開發者ID:xm-online,項目名稱:xm-uaa,代碼行數:10,代碼來源:DomainJwtAccessTokenConverter.java

示例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);
}
 
開發者ID:scionaltera,項目名稱:emergentmud,代碼行數:8,代碼來源:WebSocketResource.java

示例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;
}
 
開發者ID:xm-online,項目名稱:xm-commons,代碼行數:10,代碼來源:TimelineInterceptor.java

示例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();
}
 
開發者ID:xm-online,項目名稱:xm-gate,代碼行數:16,代碼來源:SecurityUtils.java

示例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);
}
 
開發者ID:tadeucruz,項目名稱:spring-oauth2-jwt,代碼行數:10,代碼來源:EndPoint.java

示例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);
}
 
開發者ID:tadeucruz,項目名稱:spring-oauth2-jwt,代碼行數:10,代碼來源:EndPoint.java

示例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;
}
 
開發者ID:xm-online,項目名稱:xm-ms-config,代碼行數:34,代碼來源:TenantInterceptor.java

示例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";
}
 
開發者ID:bijukunjummen,項目名稱:oauth-uaa-sample,代碼行數:12,代碼來源:SampleController.java


注:本文中的org.springframework.security.oauth2.provider.OAuth2Authentication.getDetails方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。