本文整理匯總了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;
}
示例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;
}
示例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;
}
};
}
示例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;
}
示例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;
}
};
}
示例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;
}
示例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());
}
示例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());
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
示例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;
}