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


Java OAuth2AuthenticationDetails.getTokenValue方法代码示例

本文整理汇总了Java中org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails.getTokenValue方法的典型用法代码示例。如果您正苦于以下问题:Java OAuth2AuthenticationDetails.getTokenValue方法的具体用法?Java OAuth2AuthenticationDetails.getTokenValue怎么用?Java OAuth2AuthenticationDetails.getTokenValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails的用法示例。


在下文中一共展示了OAuth2AuthenticationDetails.getTokenValue方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: oauth2ClientContext

import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入方法依赖的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: getWebSocketHttpHeaders

import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入方法依赖的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

示例3: apply

import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入方法依赖的package包/类
@Override
public void apply(HttpClientRequest<ByteBuf> request, Authentication auth) {
	logger.info("OAuth2TokenStrategy called for auth: " + auth + " and request: " + request);
	if (auth != null) {
		if (auth instanceof OAuth2Authentication) {
			Object details = auth.getDetails();
			if (details instanceof OAuth2AuthenticationDetails) {
				logger.info("OAuth2 authentication details found");
				OAuth2AuthenticationDetails oauth = (OAuth2AuthenticationDetails) details;
				String accessToken = oauth.getTokenValue();
				String tokenType = oauth.getTokenType() == null ? "Bearer" : oauth.getTokenType();
				request.withHeader("Authorization", tokenType + " " + accessToken);
			} else {
				logger.info("No OAuth2 authentication details found");
			}
		}
	} else {
		logger.warn("OAuth2TokenStrategy enabled, but inbound request does not contain a Spring Security Authentication context");
	}
}
 
开发者ID:ordina-jworks,项目名称:microservices-dashboard-server,代码行数:21,代码来源:OAuth2TokenStrategy.java

示例4: copyToken

import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入方法依赖的package包/类
/**
 * Attempt to copy an access token from the security context into the oauth2 context.
 * 
 * @return true if the token was copied
 */
public boolean copyToken() {
	if (context.getAccessToken() == null) {
		Authentication authentication = SecurityContextHolder.getContext()
				.getAuthentication();
		if (authentication != null) {
			Object details = authentication.getDetails();
			if (details instanceof OAuth2AuthenticationDetails) {
				OAuth2AuthenticationDetails holder = (OAuth2AuthenticationDetails) details;
				String token = holder.getTokenValue();
				DefaultOAuth2AccessToken accessToken = new DefaultOAuth2AccessToken(
						token);
				String tokenType = holder.getTokenType();
				if (tokenType != null) {
					accessToken.setTokenType(tokenType);
				}
				context.setAccessToken(accessToken);
				return true;
			}
		}
	}
	return false;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-security,代码行数:28,代码来源:AccessTokenContextRelay.java

示例5: authCode

import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入方法依赖的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

示例6: getOAuth2AccessToken

import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入方法依赖的package包/类
@Bean
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public OAuth2AccessToken getOAuth2AccessToken() {
    OAuth2Authentication oAuth2Authentication = (OAuth2Authentication) SecurityContextHolder.getContext().getAuthentication();
    final OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) oAuth2Authentication.getDetails();
    return new DefaultOAuth2AccessToken(details.getTokenValue());
}
 
开发者ID:cloudfoundry-community,项目名称:oauth-register-broker,代码行数:8,代码来源:UaaConfig.java

示例7: intercept

import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入方法依赖的package包/类
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
		throws IOException {
	final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

	if (authentication != null && authentication instanceof OAuth2Authentication) {
		final OAuth2Authentication auth2Authentication = (OAuth2Authentication) authentication;

		final String token;
		if (auth2Authentication.getDetails() instanceof OAuth2AuthenticationDetails) {
			final OAuth2AuthenticationDetails auth2AuthenticationDetails =
				(OAuth2AuthenticationDetails) auth2Authentication.getDetails();
			token = auth2AuthenticationDetails.getTokenValue();
		}
		else if (auth2Authentication.getDetails() instanceof ManualOAuthAuthenticationDetails) {
			ManualOAuthAuthenticationDetails manualOAuthAuthenticationDetails =
				(ManualOAuthAuthenticationDetails) auth2Authentication.getDetails();
			token = manualOAuthAuthenticationDetails.getAccessToken().getValue();
		}
		else {
			token = null;
		}

		if (token != null) {
			request.getHeaders().add(HttpHeaders.AUTHORIZATION, OAuth2AccessToken.BEARER_TYPE + " " + token);
		}
	}
	return execution.execute(request, body);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-dataflow,代码行数:30,代码来源:OAuth2AccessTokenProvidingClientHttpRequestInterceptor.java

示例8: getOAuth2AccessToken

import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入方法依赖的package包/类
@Bean
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public OAuth2AccessToken getOAuth2AccessToken() {
    if (!(SecurityContextHolder.getContext().getAuthentication() instanceof OAuth2Authentication)) {
        return null;
    }
    OAuth2Authentication oAuth2Authentication = (OAuth2Authentication) SecurityContextHolder.getContext().getAuthentication();
    final OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) oAuth2Authentication.getDetails();
    return new DefaultOAuth2AccessToken(details.getTokenValue());
}
 
开发者ID:orange-cloudfoundry,项目名称:db-dumper-service,代码行数:11,代码来源:UaaConfig.java

示例9: getToken

import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入方法依赖的package包/类
private String getToken() {
  OAuth2AuthenticationDetails details =
      (OAuth2AuthenticationDetails) SecurityContextHolder.getContext().getAuthentication().getDetails();

  return details.getTokenValue();
}
 
开发者ID:TulevaEE,项目名称:onboarding-service,代码行数:7,代码来源:EpisService.java

示例10: getToken

import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入方法依赖的package包/类
public static String getToken() {
    OAuth2AuthenticationDetails details = getTokenDetails();
    return details != null ? details.getTokenValue() : null;
}
 
开发者ID:GoldRenard,项目名称:JuniperBotJ,代码行数:5,代码来源:SecurityUtils.java

示例11: createUserContext

import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入方法依赖的package包/类
public UserContext createUserContext(OAuth2Authentication authentication, String token) {
  OAuth2Request oauth2Request = authentication.getOAuth2Request();
  String clientId = oauth2Request.getClientId();
  String grantType = oauth2Request.getGrantType();
  String userId = null;
  String userName = null;
  String issuer = null;
  long validFrom = 0;
  long validUntil = 0;
  String scope = null;

  if (token == null) {
    OAuth2AuthenticationDetails authDetails = (OAuth2AuthenticationDetails) authentication
        .getDetails();
    token = authDetails.getTokenValue();
  }

  OAuth2AccessToken accessToken;
  accessToken = resourceServerTokenServices.readAccessToken(token);


  if (accessToken != null) {
    Set<String> scopes = accessToken.getScope();
    scope = scopes == null ? null : String.join(",", scopes);

    Map<String, Object> additionalInformation = accessToken.getAdditionalInformation();
    userName = (String) additionalInformation.get("user_name");
    userId = (String) additionalInformation.get("user_id");
    issuer = (String) additionalInformation.get("iss");
    validFrom = claimValueAsLong(additionalInformation);
    validUntil = accessToken.getExpiration().toInstant().getEpochSecond();
  }

  return new UserContext(
      userId,
      userName,
      issuer,
      validFrom,
      validUntil,
      clientId,
      scope,
      grantType,
      UserContext.AUTH_METHOD_UAA
  );
}
 
开发者ID:cloudfoundry-incubator,项目名称:credhub,代码行数:46,代码来源:UserContextFactory.java

示例12: apply

import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入方法依赖的package包/类
@Override
public String apply(Authentication authentication) {
    OAuth2Authentication oauth2 = (OAuth2Authentication) authentication;
    OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) oauth2.getDetails();
    return details.getTokenValue();
}
 
开发者ID:trustedanalytics,项目名称:h2o-model-catalog,代码行数:7,代码来源:OAuth2TokenExtractor.java

示例13: getAuthToken

import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails; //导入方法依赖的package包/类
@Override public String getAuthToken(Authentication auth) {
    OAuth2Authentication oauth2 = (OAuth2Authentication) auth;
    OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) oauth2.getDetails();
    return details.getTokenValue();
}
 
开发者ID:trustedanalytics,项目名称:cf-client,代码行数:6,代码来源:OAuth2TokenRetriever.java


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