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


Java DefaultOAuth2AccessToken.setExpiration方法代碼示例

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


在下文中一共展示了DefaultOAuth2AccessToken.setExpiration方法的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: extractAccessToken

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
public OAuth2AccessToken extractAccessToken(String value, Map<String, ?> map) {
	DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(value);
	Map<String, Object> info = new HashMap<String, Object>(map);
	info.remove(EXP);
	info.remove(AUD);
	info.remove(CLIENT_ID);
	info.remove(SCOPE);
	if (map.containsKey(EXP)) {
		token.setExpiration(new Date((Integer) map.get(EXP) * 1000L));
	}
	if (map.containsKey(JTI)) {
		info.put(JTI, map.get(JTI));
	}
	@SuppressWarnings("unchecked")
	Collection<String> scope = (Collection<String>) map.get(SCOPE);
	if (scope != null) {
		token.setScope(new HashSet<String>(scope));
	}
	token.setAdditionalInformation(info);
	return token;
}
 
開發者ID:jungyang,項目名稱:oauth-client-master,代碼行數:22,代碼來源:DefaultAccessTokenConverter.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: 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: 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

示例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
			.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

示例7: testTokenIsResetIfInvalid

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Test
public void testTokenIsResetIfInvalid() throws Exception {
	DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken("TEST");
	token.setExpiration(new Date(System.currentTimeMillis() - 1000));
	restTemplate.getOAuth2ClientContext().setAccessToken(token);
	restTemplate.setAccessTokenProvider(new StubAccessTokenProvider() {
		@Override
		public OAuth2AccessToken obtainAccessToken(OAuth2ProtectedResourceDetails details,
				AccessTokenRequest parameters) throws UserRedirectRequiredException, AccessDeniedException {
			throw new UserRedirectRequiredException("http://foo.com", Collections.<String, String> emptyMap());
		}
	});
	try {
		OAuth2AccessToken newToken = restTemplate.getAccessToken();
		assertNotNull(newToken);
		fail("Expected UserRedirectRequiredException");
	}
	catch (UserRedirectRequiredException e) {
		// planned
	}
	// context token should be reset as it clearly is invalid at this point
	assertNull(restTemplate.getOAuth2ClientContext().getAccessToken());
}
 
開發者ID:jungyang,項目名稱:oauth-client-master,代碼行數:24,代碼來源:OAuth2RestTemplateTests.java

示例8: testExpiredRefreshTokenIsRenewedWithNewAccessToken

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Test
public void testExpiredRefreshTokenIsRenewedWithNewAccessToken() throws Exception {
	OAuth2Authentication expectedAuthentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request(null, "id", null, false, Collections.singleton("read"), null, null, null, null), new TestAuthentication("test2", false));
	DefaultOAuth2AccessToken firstAccessToken = (DefaultOAuth2AccessToken) getTokenServices().createAccessToken(
			expectedAuthentication);
	assertNotNull(firstAccessToken.getRefreshToken());
	// Make it expire (and rely on mutable state in volatile token store)
	ReflectionTestUtils.setField(firstAccessToken.getRefreshToken(), "expiration",
			new Date(System.currentTimeMillis() - 1000));
	firstAccessToken.setExpiration(new Date(System.currentTimeMillis() - 1000));
	DefaultOAuth2AccessToken secondAccessToken = (DefaultOAuth2AccessToken) getTokenServices().createAccessToken(
			expectedAuthentication);
	ExpiringOAuth2RefreshToken refreshToken = (ExpiringOAuth2RefreshToken) secondAccessToken.getRefreshToken();
	assertNotNull(refreshToken);
	assertTrue(refreshToken.getExpiration().getTime() > System.currentTimeMillis());
}
 
開發者ID:jungyang,項目名稱:oauth-client-master,代碼行數:17,代碼來源:DefaultTokenServicesWithInMemoryTests.java

示例9: 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

示例10: getAccessToken

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Override
public OAuth2AccessToken getAccessToken(OAuth2ProtectedResourceDetails resource, Authentication authentication) {
    ClientUser clientUser = getClientUser(authentication);

    if (clientUser.accessToken == null) return null;

    DefaultOAuth2AccessToken oAuth2AccessToken = new DefaultOAuth2AccessToken(clientUser.accessToken);
    oAuth2AccessToken.setAdditionalInformation(clientUser.additionalInformation);
    oAuth2AccessToken.setExpiration(new Date(clientUser.expirationTime));

    return oAuth2AccessToken;
}
 
開發者ID:PacktPublishing,項目名稱:OAuth-2.0-Cookbook,代碼行數:13,代碼來源:OAuth2ClientTokenSevices.java

示例11: getAccessToken

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Override
public OAuth2AccessToken getAccessToken(OAuth2ProtectedResourceDetails resource, Authentication authentication) {
    ClientUser clientUser = getClientUser(authentication);

    String accessToken = clientUser.getAccessToken();
    Calendar expirationDate = clientUser.getAccessTokenValidity();

    if (accessToken == null) return null;

    DefaultOAuth2AccessToken oAuth2AccessToken = new DefaultOAuth2AccessToken(accessToken);
    oAuth2AccessToken.setExpiration(expirationDate.getTime());

    return oAuth2AccessToken;
}
 
開發者ID:PacktPublishing,項目名稱:OAuth-2.0-Cookbook,代碼行數:15,代碼來源:OAuth2ClientTokenSevices.java

示例12: createToken

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public static OAuth2AccessToken createToken(String tokenString) {
    Map<String, Object> tokenInfo = getTokenInfo(tokenString);
    List<String> scope = (List<String>) tokenInfo.get("scope");
    Integer exp = (Integer) tokenInfo.get("exp");
    if (scope == null || exp == null) {
        return null;
    }
    DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(tokenString);
    token.setExpiration(new Date(exp.longValue() * 1000));
    token.setScope(new HashSet<String>(scope));
    token.setAdditionalInformation(tokenInfo);
    return token;
}
 
開發者ID:SAP,項目名稱:cf-mta-deploy-service,代碼行數:15,代碼來源:TokenUtil.java

示例13: createDummyToken

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
public static OAuth2AccessToken createDummyToken(String userName, String clientId) {
    List<String> scope = Arrays.asList(SCOPE_CC_READ, SCOPE_CC_WRITE, SCOPE_CC_ADMIN, SCOPE_SCIM_USERIDS, SCOPE_PASSWORD_WRITE,
        SCOPE_OPENID);
    Map<String, Object> tokenInfo = new HashMap<>();
    tokenInfo.put("scope", scope);
    tokenInfo.put("exp", Long.MAX_VALUE / 1000);
    tokenInfo.put("user_name", userName);
    tokenInfo.put("user_id", DUMMY_UUID.toString());
    tokenInfo.put("client_id", clientId);
    DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(DUMMY_TOKEN);
    token.setExpiration(new Date(Long.MAX_VALUE));
    token.setScope(new HashSet<String>(scope));
    token.setAdditionalInformation(tokenInfo);
    return token;
}
 
開發者ID:SAP,項目名稱:cf-mta-deploy-service,代碼行數:16,代碼來源:TokenUtil.java

示例14: testRetrieveAccessToken

import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Test
public void testRetrieveAccessToken() {
    //Test approved request
    OAuth2Request storedOAuth2Request = RequestTokenFactory.createOAuth2Request("id", true);
    OAuth2Authentication authentication = new OAuth2Authentication(storedOAuth2Request,
            new TestAuthentication("test2", true));
    DefaultOAuth2AccessToken expectedOAuth2AccessToken = new DefaultOAuth2AccessToken("testToken");
    expectedOAuth2AccessToken.setExpiration(new Date(Long.MAX_VALUE - 1));
    getTokenStore().storeAccessToken(expectedOAuth2AccessToken, authentication);

    //Test unapproved request
    storedOAuth2Request = RequestTokenFactory.createOAuth2Request("id", false);
    authentication = new OAuth2Authentication(storedOAuth2Request, new TestAuthentication("test2", true));
    OAuth2AccessToken actualOAuth2AccessToken = getTokenStore().getAccessToken(authentication);
    assertEquals(expectedOAuth2AccessToken, actualOAuth2AccessToken);
    assertEquals(authentication.getUserAuthentication(),
            getTokenStore().readAuthentication(expectedOAuth2AccessToken.getValue()).getUserAuthentication());
    // The authorizationRequest does not match because it is unapproved, but the token was granted to an approved request
    assertFalse(storedOAuth2Request
            .equals(getTokenStore().readAuthentication(expectedOAuth2AccessToken.getValue()).getOAuth2Request()));
    actualOAuth2AccessToken = getTokenStore().getAccessToken(authentication);
    assertEquals(expectedOAuth2AccessToken, actualOAuth2AccessToken);
    getTokenStore().removeAccessToken(expectedOAuth2AccessToken);
    assertNull(getTokenStore().readAccessToken("testToken"));
    assertNull(getTokenStore().readAuthentication(expectedOAuth2AccessToken.getValue()));
    assertNull(getTokenStore().getAccessToken(authentication));
}
 
開發者ID:cedac-software,項目名稱:spring-security-mongodb,代碼行數:28,代碼來源:TokenStoreBaseTests.java

示例15: 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


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