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


Java DefaultOAuth2AccessToken.setTokenType方法代碼示例

本文整理匯總了Java中org.springframework.security.oauth2.common.DefaultOAuth2AccessToken.setTokenType方法的典型用法代碼示例。如果您正苦於以下問題:Java DefaultOAuth2AccessToken.setTokenType方法的具體用法?Java DefaultOAuth2AccessToken.setTokenType怎麽用?Java DefaultOAuth2AccessToken.setTokenType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.security.oauth2.common.DefaultOAuth2AccessToken的用法示例。


在下文中一共展示了DefaultOAuth2AccessToken.setTokenType方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: convert

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
private OAuth2AccessToken convert(io.gravitee.am.repository.oauth2.model.OAuth2AccessToken _oAuth2AccessToken) {
    DefaultOAuth2AccessToken oAuth2AccessToken = new DefaultOAuth2AccessToken(_oAuth2AccessToken.getValue());
    oAuth2AccessToken.setAdditionalInformation(_oAuth2AccessToken.getAdditionalInformation());
    oAuth2AccessToken.setExpiration(_oAuth2AccessToken.getExpiration());
    oAuth2AccessToken.setScope(_oAuth2AccessToken.getScope());
    oAuth2AccessToken.setTokenType(_oAuth2AccessToken.getTokenType());

    // refresh token
    io.gravitee.am.repository.oauth2.model.OAuth2RefreshToken _oAuth2RefreshToken = _oAuth2AccessToken.getRefreshToken();
    if (_oAuth2RefreshToken != null) {
        DefaultExpiringOAuth2RefreshToken oAuth2RefreshToken =
                new DefaultExpiringOAuth2RefreshToken(_oAuth2AccessToken.getRefreshToken().getValue(), _oAuth2AccessToken.getRefreshToken().getExpiration());
        oAuth2AccessToken.setRefreshToken(oAuth2RefreshToken);
    }

    return oAuth2AccessToken;
}
 
開發者ID:gravitee-io,項目名稱:graviteeio-access-management,代碼行數:18,代碼來源:RepositoryTokenStore.java

示例2: testClientCredentialsRestTemplate

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Test
public void testClientCredentialsRestTemplate() throws Exception {

    ClientCredentialsResourceDetails details = new ClientCredentialsResourceDetails();
     details.setId("4");
    details.setClientId(client_id);
    details.setClientSecret(client_secret);
    details.setAccessTokenUri(access_token_uri);
   // details.setScope(Arrays.asList("read write"));
    OAuth2RestTemplate operations = new OAuth2RestTemplate(details,new DefaultOAuth2ClientContext());
   // OAuth2RestTemplate oAuth2RestTemplate = new OAuth2RestTemplate(resourceDetails);
    operations.setAccessTokenProvider(new ClientCredentialsAccessTokenProvider());

  //  OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resourceDetails(),oAuth2ClientContext());
    DefaultOAuth2AccessToken token=(DefaultOAuth2AccessToken)operations.getAccessToken();
    token.setTokenType("Bearer");

    System.out.println("client_id : " + client_id);
    System.out.println("source_url : " + source_url);

  //  OAuth2RestOperations operations = restTemplate.clientCredentialsRestTemplate(client_id, client_secret, access_token_uri, scopes);  // getForObject 發送 get 方法
    System.out.println(JSON.toJSONString(operations.getForObject(source_url, JsonNode.class)));  // getForObject 發送 get 方法

}
 
開發者ID:h819,項目名稱:spring-boot,代碼行數:25,代碼來源:Oauth2ClientRestTemplateTest.java

示例3: getMap

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@SuppressWarnings({ "unchecked" })
private Map<String, Object> getMap(String path, String accessToken) {
	this.logger.info("Getting user info from: " + path);
	try {
		OAuth2RestOperations restTemplate = this.restTemplate;
		if (restTemplate == null) {
			BaseOAuth2ProtectedResourceDetails resource = new BaseOAuth2ProtectedResourceDetails();
			resource.setClientId(this.clientId);
			restTemplate = new OAuth2RestTemplate(resource);
		}
		DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(accessToken);
		token.setTokenType(this.tokenType);
		restTemplate.getOAuth2ClientContext().setAccessToken(token);
		return restTemplate.getForEntity(path, Map.class).getBody();
	}
	catch (Exception ex) {
		this.logger.info("Could not fetch user details: " + ex.getClass() + ", "
				+ ex.getMessage());
		return Collections.<String, Object>singletonMap("error",
				"Could not fetch user details");
	}
}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:23,代碼來源:UserInfoTokenServices.java

示例4: readAccessToken

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Override
public OAuth2AccessToken readAccessToken(String token) {
    AccessToken accessToken = validateAccessToken(token);

    Set<String> scopes = new HashSet<>();
    for (Scope scope : accessToken.getScopes()) {
        scopes.add(scope.toString());
    }

    DefaultOAuth2AccessToken oAuth2AccessToken = new DefaultOAuth2AccessToken(token);
    oAuth2AccessToken.setScope(scopes);
    oAuth2AccessToken.setExpiration(accessToken.getExpiresAt());
    oAuth2AccessToken.setTokenType(DefaultOAuth2AccessToken.BEARER_TYPE);

    return oAuth2AccessToken;
}
 
開發者ID:osiam,項目名稱:resource-server,代碼行數:17,代碼來源:AccessTokenValidationService.java

示例5: copyToken

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的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

示例6: getMap

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@SuppressWarnings({ "unchecked" })
private Map<String, Object> getMap(String path, String accessToken) {
	this.logger.debug("Getting user info from: " + path);
	try {
		OAuth2RestOperations restTemplate = this.restTemplate;
		if (restTemplate == null) {
			BaseOAuth2ProtectedResourceDetails resource = new BaseOAuth2ProtectedResourceDetails();
			resource.setClientId(this.clientId);
			restTemplate = new OAuth2RestTemplate(resource);
		}
		OAuth2AccessToken existingToken = restTemplate.getOAuth2ClientContext()
				.getAccessToken();
		if (existingToken == null || !accessToken.equals(existingToken.getValue())) {
			DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(
					accessToken);
			token.setTokenType(this.tokenType);
			restTemplate.getOAuth2ClientContext().setAccessToken(token);
		}
		return restTemplate.getForEntity(path, Map.class).getBody();
	}
	catch (Exception ex) {
		this.logger.info("Could not fetch user details: " + ex.getClass() + ", "
				+ ex.getMessage());
		return Collections.<String, Object>singletonMap("error",
				"Could not fetch user details");
	}
}
 
開發者ID:dins-heisenbug-2016,項目名稱:piggymetrics,代碼行數:28,代碼來源:CustomUserInfoTokenServices.java

示例7: getMap

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@SuppressWarnings({ "unchecked" })
private Map<String, Object> getMap(String path, String accessToken) {
	this.logger.info("Getting user info from {} with access token {}", path, accessToken);
	try {
		OAuth2RestOperations restTemplate = this.restTemplate;
		if (restTemplate == null) {
			BaseOAuth2ProtectedResourceDetails resource = new BaseOAuth2ProtectedResourceDetails();
			resource.setClientId(this.clientId);
			restTemplate = new OAuth2RestTemplate(resource);
		}
		OAuth2AccessToken existingToken = restTemplate.getOAuth2ClientContext()
				.getAccessToken();
		if (existingToken == null || !accessToken.equals(existingToken.getValue())) {
			DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(
					accessToken);
			token.setTokenType(this.tokenType);
			logger.info("==========================================================");
			logger.info("USER INFO FETCH, using NEW access token: {}", accessToken);
			logger.info("==========================================================");
			restTemplate.getOAuth2ClientContext().setAccessToken(token);
		} else {
			logger.info("==========================================================");
			logger.info("USER INFO FETCH, using EXISTING access token: {}", existingToken.getValue());
			logger.info("==========================================================");
		}
		return restTemplate.getForEntity(path, Map.class).getBody();
	}
	catch (Exception ex) {
		this.logger.info("Could not fetch user details: " + ex.getClass() + ", "
				+ ex.getMessage());
		return Collections.<String, Object>singletonMap("error",
				"Could not fetch user details");
	}
}
 
開發者ID:nicodewet,項目名稱:template-spring-boot-oauth2-wso2-is,代碼行數:35,代碼來源:AppUserInfoTokenServices.java

示例8: getMap

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@SuppressWarnings({ "unchecked" })
private Map<String, Object> getMap(String path, String accessToken) {
	this.logger.info("Getting user info from: " + path);
	try {
		OAuth2RestOperations restTemplate = this.restTemplate;
		if (restTemplate == null) {
			BaseOAuth2ProtectedResourceDetails resource = new BaseOAuth2ProtectedResourceDetails();
			resource.setClientId(this.clientId);
			restTemplate = new OAuth2RestTemplate(resource);
		}
		OAuth2AccessToken existingToken = restTemplate.getOAuth2ClientContext()
				.getAccessToken();
		if (existingToken == null || !accessToken.equals(existingToken.getValue())) {
			DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(
					accessToken);
			token.setTokenType(this.tokenType);
			restTemplate.getOAuth2ClientContext().setAccessToken(token);
		}
		return restTemplate.getForEntity(path, Map.class).getBody();
	}
	catch (Exception ex) {
		this.logger.info("Could not fetch user details: " + ex.getClass() + ", "
				+ ex.getMessage());
		return Collections.<String, Object>singletonMap("error",
				"Could not fetch user details");
	}
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:28,代碼來源:UserInfoTokenServices.java

示例9: testNonBearerToken

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Test
public void testNonBearerToken() throws Exception {
	DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken("12345");
	token.setTokenType("MINE");
	restTemplate.getOAuth2ClientContext().setAccessToken(token);
	ClientHttpRequest http = restTemplate.createRequest(URI.create("https://nowhere.com/api/crap"), HttpMethod.GET);
	String auth = http.getHeaders().getFirst("Authorization");
	assertTrue(auth.startsWith("MINE "));
}
 
開發者ID:jungyang,項目名稱:oauth-client-master,代碼行數:10,代碼來源:OAuth2RestTemplateTests.java

示例10: testCustomAuthenticator

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Test
public void testCustomAuthenticator() throws Exception {
	DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken("12345");
	token.setTokenType("MINE");
	restTemplate.setAuthenticator(new OAuth2RequestAuthenticator() {
		@Override
		public void authenticate(OAuth2ProtectedResourceDetails resource, OAuth2ClientContext clientContext, ClientHttpRequest req) {
			req.getHeaders().set("X-Authorization", clientContext.getAccessToken().getTokenType() + " " + "Nah-nah-na-nah-nah");
		}
	});
	restTemplate.getOAuth2ClientContext().setAccessToken(token);
	ClientHttpRequest http = restTemplate.createRequest(URI.create("https://nowhere.com/api/crap"), HttpMethod.GET);
	String auth = http.getHeaders().getFirst("X-Authorization");
	assertEquals("MINE Nah-nah-na-nah-nah", auth);
}
 
開發者ID:jungyang,項目名稱:oauth-client-master,代碼行數:16,代碼來源:OAuth2RestTemplateTests.java


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