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


Java DefaultOAuth2AccessToken.setRefreshToken方法代碼示例

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


在下文中一共展示了DefaultOAuth2AccessToken.setRefreshToken方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: retrieveToken

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
public OAuth2AccessToken retrieveToken(URI target) {
    TargetInfos targetInfos = getTokensFromFile();

    if (targetInfos == null) {
        return null;
    }

    HashMap<String, String> targetInfo = targetInfos.get(target);

    if (targetInfo == null) {
        return null;
    }

    DefaultOAuth2RefreshToken refreshToken = targetInfos.getRefreshToken(targetInfo);
    DefaultOAuth2AccessToken token = targetInfos.getToken(targetInfo);
    token.setRefreshToken(refreshToken);

    return token;
}
 
開發者ID:SAP,項目名稱:cf-java-client-sap,代碼行數:20,代碼來源:TokensFile.java

示例3: oAuth2AccessTokenMapper

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
/**
 * Convert IDN_OAUTH2_ACCESS_TOKEN table
 * @return
 */
public static RowMapper<OAuth2AccessToken> oAuth2AccessTokenMapper() {
    return new RowMapper<OAuth2AccessToken>() {
        @Override
        public OAuth2AccessToken mapRow(final ResultSet rs, int rowNum) throws SQLException {
            DefaultOAuth2AccessToken defaultOAuth2AccessToken = new DefaultOAuth2AccessToken(rs.getString(1));
            defaultOAuth2AccessToken.setRefreshToken(new DefaultOAuth2RefreshToken(rs.getString(3)));
            Set<String> scope = new HashSet<String>();
            scope.add(rs.getString(2));
            defaultOAuth2AccessToken.setScope(scope);
            Timestamp date = rs.getTimestamp(4);
            Calendar calendar = new GregorianCalendar();
            calendar.setTimeInMillis(date.getTime());
            calendar.add(Calendar.MILLISECOND, rs.getInt(5));
            defaultOAuth2AccessToken.setExpiration(calendar.getTime());
            return defaultOAuth2AccessToken;
        }
    };
}
 
開發者ID:angel-git,項目名稱:wso2is-springoauth,代碼行數:23,代碼來源:Wso2RowMapper.java

示例4: getResponseExtractor

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Override
protected ResponseExtractor<OAuth2AccessToken> getResponseExtractor() {

    return new ResponseExtractor<OAuth2AccessToken>() {

        @Override
        public OAuth2AccessToken extractData(ClientHttpResponse response) throws IOException {

            JsonNode node = new ObjectMapper().readTree(response.getBody());
            String token = Preconditions
                    .checkNotNull(node.path("AccessToken").textValue(), "Missing access token: %s", node);
            String refreshToken = Preconditions
                    .checkNotNull(node.path("RefreshToken").textValue(), "Missing refresh token: %s" + node);
            String userId =
                    Preconditions.checkNotNull(node.path("UserID").textValue(), "Missing UserID: %s", node);
            long expiresIn = node.path("Expires").longValue() * 1000;
            Preconditions.checkArgument(expiresIn > 0, "Missing Expires: %s", node);

            DefaultOAuth2AccessToken accessToken = new DefaultOAuth2AccessToken(token);
            accessToken.setExpiration(new Date(System.currentTimeMillis() + expiresIn));
            accessToken.setRefreshToken(new DefaultOAuth2RefreshToken(refreshToken));
            accessToken.setAdditionalInformation(ImmutableMap.<String, Object>of("UserID", userId));
            return accessToken;
        }
    };
}
 
開發者ID:openmhealth,項目名稱:shimmer,代碼行數:27,代碼來源:IHealthShim.java

示例5: createAccessToken

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
private OAuth2AccessToken createAccessToken(
		OAuth2Authentication authentication, OAuth2RefreshToken refreshToken) {
	DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(UUID
			.randomUUID().toString());
	int validitySeconds = getAccessTokenValiditySeconds(authentication
			.getOAuth2Request());
	if (validitySeconds > 0) {
		token.setExpiration(new Date(System.currentTimeMillis()
				+ (validitySeconds * 1000L)));
	}
	token.setRefreshToken(refreshToken);
	token.setScope(authentication.getOAuth2Request().getScope());

	return accessTokenEnhancer != null ? accessTokenEnhancer.enhance(token,
			authentication) : token;
}
 
開發者ID:jungyang,項目名稱:oauth-client-master,代碼行數:17,代碼來源:DefaultTokenServices.java

示例6: createAccessToken

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
private OAuth2AccessToken createAccessToken(OAuth2Authentication authentication, OAuth2RefreshToken refreshToken) {
    DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(UUID.randomUUID().toString());
    int validitySeconds = getAccessTokenValiditySeconds(authentication);
    if (validitySeconds > 0) {
        token.setExpiration(new Date(System.currentTimeMillis() + (validitySeconds * 1000L)));
    }
    token.setRefreshToken(refreshToken);
    token.setScope(authentication.getOAuth2Request().getScope());

    return accessTokenEnhancer != null ? accessTokenEnhancer.enhance(token, authentication) : token;
}
 
開發者ID:xm-online,項目名稱:xm-uaa,代碼行數:12,代碼來源:DomainTokenServices.java

示例7: withRestTemplate

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Test
public void withRestTemplate() {
	OAuth2ProtectedResourceDetails resource = new AuthorizationCodeResourceDetails();
	OAuth2ClientContext context = new DefaultOAuth2ClientContext();
	DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken("FOO");
	token.setRefreshToken(new DefaultExpiringOAuth2RefreshToken("BAR", new Date(0L)));
	context.setAccessToken(token);
	this.services.setRestTemplate(new OAuth2RestTemplate(resource, context));
	assertThat(this.services.loadAuthentication("FOO").getName()).isEqualTo("me");
	assertThat(context.getAccessToken().getValue()).isEqualTo("FOO");
	// The refresh token is still intact
	assertThat(context.getAccessToken().getRefreshToken())
			.isEqualTo(token.getRefreshToken());
}
 
開發者ID:spring-projects,項目名稱:spring-security-oauth2-boot,代碼行數:15,代碼來源:UserInfoTokenServicesRefreshTokenTests.java

示例8: testRefreshTokenIsNotStoredDuringAccessToken

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Test
public void testRefreshTokenIsNotStoredDuringAccessToken() {
	OAuth2Authentication expectedAuthentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request("id", false), new TestAuthentication("test2", false));
	DefaultOAuth2AccessToken expectedOAuth2AccessToken = new DefaultOAuth2AccessToken("testToken");
	expectedOAuth2AccessToken.setRefreshToken(new DefaultOAuth2RefreshToken("refreshToken"));
	getTokenStore().storeAccessToken(expectedOAuth2AccessToken, expectedAuthentication);

	OAuth2AccessToken actualOAuth2AccessToken = getTokenStore().readAccessToken("testToken");
	assertNotNull(actualOAuth2AccessToken.getRefreshToken());
	
	assertNull(getTokenStore().readRefreshToken("refreshToken"));
}
 
開發者ID:Mert-Z,項目名稱:spring-oauth2-cassandra-token-store,代碼行數:13,代碼來源:TokenStoreBaseTests.java

示例9: testRefreshTokenIsNotStoredDuringAccessToken

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Test
public void testRefreshTokenIsNotStoredDuringAccessToken() {
    OAuth2Authentication expectedAuthentication = new OAuth2Authentication(
            RequestTokenFactory.createOAuth2Request("id", false), new TestAuthentication("test2", false));
    DefaultOAuth2AccessToken expectedOAuth2AccessToken = new DefaultOAuth2AccessToken("testToken");
    expectedOAuth2AccessToken.setRefreshToken(new DefaultOAuth2RefreshToken("refreshToken"));
    getTokenStore().storeAccessToken(expectedOAuth2AccessToken, expectedAuthentication);

    OAuth2AccessToken actualOAuth2AccessToken = getTokenStore().readAccessToken("testToken");
    assertNotNull(actualOAuth2AccessToken.getRefreshToken());

    assertNull(getTokenStore().readRefreshToken("refreshToken"));
}
 
開發者ID:cedac-software,項目名稱:spring-security-mongodb,代碼行數:14,代碼來源:TokenStoreBaseTests.java

示例10: build

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
public OAuth2AccessToken build() {
    final DefaultOAuth2AccessToken oAuth2AccessToken = new DefaultOAuth2AccessToken(token);
    oAuth2AccessToken.setExpiration(expiration.toDate());
    oAuth2AccessToken.setRefreshToken(oAuth2RefreshToken);
    oAuth2AccessToken.setScope(scope);
    oAuth2AccessToken.setAdditionalInformation(additionalInformation);
    return oAuth2AccessToken;
}
 
開發者ID:caelwinner,項目名稱:spring-security-mongo,代碼行數:9,代碼來源:OAuth2AccessTokenBuilder.java

示例11: convertToExternal

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
protected OAuth2AccessToken convertToExternal(JaxbOAuth2AccessToken jaxbAccessToken) {
	DefaultOAuth2AccessToken accessToken = new DefaultOAuth2AccessToken(jaxbAccessToken.getAccessToken());
	String refreshToken = jaxbAccessToken.getRefreshToken();
	if(refreshToken != null) {
		accessToken.setRefreshToken(new DefaultOAuth2RefreshToken(refreshToken));
	}
	Date expiration = jaxbAccessToken.getExpiration();
	if(expiration != null) {
		accessToken.setExpiration(expiration);
	}
	return accessToken;
}
 
開發者ID:jungyang,項目名稱:oauth-client-master,代碼行數:13,代碼來源:JaxbOAuth2AccessTokenMessageConverter.java

示例12: refreshAccessToken

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
public OAuth2AccessToken refreshAccessToken(String refreshTokenValue, TokenRequest request)
		throws AuthenticationException {

	if (!supportRefreshToken) {
		throw new InvalidGrantException("Invalid refresh token: " + refreshTokenValue);
	}

	OAuth2Authentication authentication = loadAuthentication(refreshTokenValue);
	String clientId = authentication.getOAuth2Request().getClientId();
	if (clientId == null || !clientId.equals(request.getClientId())) {
		throw new InvalidGrantException("Wrong client for this refresh token: " + refreshTokenValue);
	}

	OAuth2AccessToken refreshTokenData = readAccessToken(refreshTokenValue);
	if (isExpired(refreshTokenData)) {
		throw new InvalidTokenException("Invalid refresh token (expired): " + refreshTokenValue);
	}

	authentication = createRefreshedAuthentication(authentication, request.getScope());

	OAuth2AccessToken accessToken = createAccessToken(authentication);
	if (!reuseRefreshToken) {
		OAuth2RefreshToken refreshToken = createRefreshToken(authentication);
		DefaultOAuth2AccessToken result = new DefaultOAuth2AccessToken(accessToken);
		result.setRefreshToken(refreshToken);
	}

	return accessToken;
}
 
開發者ID:jungyang,項目名稱:oauth-client-master,代碼行數:30,代碼來源:JwtTokenServices.java

示例13: grant

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Override
public OAuth2AccessToken grant(String grantType, TokenRequest tokenRequest) {
	OAuth2AccessToken token = super.grant(grantType, tokenRequest);
	if (token != null) {
		DefaultOAuth2AccessToken norefresh = new DefaultOAuth2AccessToken(token);
		// The spec says that client credentials should not be allowed to get a refresh token
		if (!allowRefresh) {
			norefresh.setRefreshToken(null);
		}
		token = norefresh;
	}
	return token;
}
 
開發者ID:jungyang,項目名稱:oauth-client-master,代碼行數:14,代碼來源:ClientCredentialsTokenGranter.java

示例14: before

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Before
public void before() throws Exception {
	converter = new JaxbOAuth2AccessTokenMessageConverter();
	accessToken = new DefaultOAuth2AccessToken("SlAV32hkKG");
	accessToken.setExpiration(expiration);
	accessToken.setRefreshToken(new DefaultOAuth2RefreshToken("8xLOxBtZp8"));
}
 
開發者ID:jungyang,項目名稱:oauth-client-master,代碼行數:8,代碼來源:JaxbOAuth2AccessTokenMessageConverterTests.java

示例15: testRefreshTokenIsNotStoredDuringAccessToken

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Test
public void testRefreshTokenIsNotStoredDuringAccessToken() {
	OAuth2Authentication expectedAuthentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request(null, "id", null, false, null, null, null, null, null), new TestAuthentication("test2", false));
	DefaultOAuth2AccessToken expectedOAuth2AccessToken = new DefaultOAuth2AccessToken("testToken");
	expectedOAuth2AccessToken.setRefreshToken(new DefaultOAuth2RefreshToken("refreshToken"));
	getTokenStore().storeAccessToken(expectedOAuth2AccessToken, expectedAuthentication);

	OAuth2AccessToken actualOAuth2AccessToken = getTokenStore().readAccessToken("testToken");
	assertNotNull(actualOAuth2AccessToken.getRefreshToken());
	
	assertNull(getTokenStore().readRefreshToken("refreshToken"));
}
 
開發者ID:jungyang,項目名稱:oauth-client-master,代碼行數:13,代碼來源:TokenStoreBaseTests.java


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