本文整理汇总了Java中org.springframework.security.oauth2.common.OAuth2RefreshToken类的典型用法代码示例。如果您正苦于以下问题:Java OAuth2RefreshToken类的具体用法?Java OAuth2RefreshToken怎么用?Java OAuth2RefreshToken使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OAuth2RefreshToken类属于org.springframework.security.oauth2.common包,在下文中一共展示了OAuth2RefreshToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convert
import org.springframework.security.oauth2.common.OAuth2RefreshToken; //导入依赖的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: createRefreshToken
import org.springframework.security.oauth2.common.OAuth2RefreshToken; //导入依赖的package包/类
private OAuth2RefreshToken createRefreshToken(OAuth2Authentication authentication) {
if (!isSupportRefreshToken(authentication.getOAuth2Request())) {
return null;
}
int validitySeconds = getRefreshTokenValiditySeconds(authentication);
String value = UUID.randomUUID().toString();
if (validitySeconds > 0) {
return new DefaultExpiringOAuth2RefreshToken(value, new Date(System.currentTimeMillis()
+ (validitySeconds * 1000L)));
}
return new DefaultOAuth2RefreshToken(value);
}
示例3: deserialize
import org.springframework.security.oauth2.common.OAuth2RefreshToken; //导入依赖的package包/类
@Override
public OAuth2RefreshToken deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
String tokenValue = null;
Long expiration = null;
while (p.nextToken() != JsonToken.END_OBJECT) {
String name = p.getCurrentName();
p.nextToken();
if (TOKEN_VALUE.equals(name)) {
tokenValue = p.getText();
} else if (EXPIRATION.equals(name)) {
try {
expiration = p.getLongValue();
} catch (JsonParseException e) {
expiration = Long.valueOf(p.getText());
}
}
}
if (expiration != null) {
return new DefaultExpiringOAuth2RefreshToken(tokenValue, new Date(expiration));
} else {
return new DefaultOAuth2RefreshToken(tokenValue);
}
}
示例4: removeAccessTokenUsingRefreshToken
import org.springframework.security.oauth2.common.OAuth2RefreshToken; //导入依赖的package包/类
@Override
public void removeAccessTokenUsingRefreshToken(OAuth2RefreshToken refreshToken) {
String tokenValue = refreshToken.getValue();
// Lookup RefreshTokenToAccessToken table for locating access token
RefreshTokenToAccessToken refreshTokenToAccessToken = refreshTokenToAccessTokenRepository.findOne(tokenValue);
if (refreshTokenToAccessToken != null) {
String accessTokenKey = refreshTokenToAccessToken.getAccessTokenKey();
AccessToken accessToken = accessTokenRepository.findOne(accessTokenKey);
String jsonOAuth2AccessToken = accessToken.getoAuth2AccessToken();
OAuth2AccessToken oAuth2AccessToken = OAuthUtil.deserializeOAuth2AccessToken(jsonOAuth2AccessToken);
// Delete access token from all related tables
List<RegularStatement> statementList = prepareRemoveAccessTokenStatements(oAuth2AccessToken);
// Delete from RefreshTokenToAccessToken table
Delete refreshTokenToAccessTokenDelete = CassandraTemplate.createDeleteQuery(RefreshTokenToAccessToken.TABLE, refreshTokenToAccessToken, null, cassandraTemplate.getConverter());
statementList.add(refreshTokenToAccessTokenDelete);
Batch batch = QueryBuilder.batch(statementList.toArray(new RegularStatement[statementList.size()]));
cassandraTemplate.execute(batch);
}
}
示例5: testStoreRefreshToken
import org.springframework.security.oauth2.common.OAuth2RefreshToken; //导入依赖的package包/类
@Test
/**
* NB: This used to test expiring refresh tokens. That test has been moved to sub-classes since not all stores support the functionality
*/
public void testStoreRefreshToken() {
String refreshToken = "testToken" + UUID.randomUUID();
DefaultOAuth2RefreshToken expectedRefreshToken = new DefaultOAuth2RefreshToken(refreshToken);
OAuth2Authentication expectedAuthentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request("id", false), new TestAuthentication("test2", false));
getTokenStore().storeRefreshToken(expectedRefreshToken, expectedAuthentication);
OAuth2RefreshToken actualExpiringRefreshToken = getTokenStore().readRefreshToken(refreshToken);
assertEquals(expectedRefreshToken, actualExpiringRefreshToken);
assertEquals(expectedAuthentication, getTokenStore().readAuthenticationForRefreshToken(expectedRefreshToken));
getTokenStore().removeRefreshToken(expectedRefreshToken);
assertNull(getTokenStore().readRefreshToken(refreshToken));
assertNull(getTokenStore().readAuthentication(expectedRefreshToken.getValue()));
}
示例6: readRefreshToken
import org.springframework.security.oauth2.common.OAuth2RefreshToken; //导入依赖的package包/类
@Override
public OAuth2RefreshToken readRefreshToken(String tokenValue) {
LOG.debug("Call readRefreshToken, tokenValue = {}", tokenValue);
OAuth2RefreshToken refreshToken = null;
try {
final String tokenId = extractTokenKey(tokenValue);
RefreshToken refreshTokenFounded = refreshTokenRepository.findOne(tokenId);
refreshToken = refreshTokenFounded == null ? null : refreshTokenFounded.token();
} catch (IllegalArgumentException e) {
LOG.warn("Failed to deserialize refresh token for token {}", tokenValue);
removeRefreshToken(tokenValue);
}
return refreshToken;
}
示例7: createRefreshToken
import org.springframework.security.oauth2.common.OAuth2RefreshToken; //导入依赖的package包/类
@Nullable
private OAuth2RefreshToken createRefreshToken(OAuth2Authentication authentication,
@Nullable OAuth2RefreshToken refreshToken) {
OAuth2RefreshToken newRefreshToken = null;
if (refreshToken != null) {
Instant refreshTokenExpiration = getRefreshTokenExpiration(refreshToken);
Claims refreshTokenClaims = createRefreshTokenClaims(authentication, refreshToken, refreshTokenExpiration);
String encodedRefreshToken = jwtProcessor.encodeUnchecked(refreshTokenClaims);
if (refreshTokenExpiration != null) {
newRefreshToken = new ExpiringJwtOAuth2RefreshToken(encodedRefreshToken, refreshTokenClaims);
} else {
newRefreshToken = new NonExpiringJwtOAuth2RefreshToken(encodedRefreshToken, refreshTokenClaims);
}
}
return newRefreshToken;
}
示例8: createRefreshTokenClaims
import org.springframework.security.oauth2.common.OAuth2RefreshToken; //导入依赖的package包/类
@Nonnull
private Claims createRefreshTokenClaims(OAuth2Authentication authentication,
OAuth2RefreshToken refreshToken,
@Nullable Instant refreshTokenExpiration) {
ClaimsBuilder refreshTokenClaims = Jwt.claims()
.setId(refreshToken.getValue())
.setAudience("refresh")
.setSubject(authentication.getName())
.setIssuedAt(clock.instant());
JwtExtraClaims.setClientId(refreshTokenClaims, authentication.getOAuth2Request().getClientId());
JwtExtraClaims.setScope(refreshTokenClaims, authentication.getOAuth2Request().getScope());
if (refreshTokenExpiration != null) {
refreshTokenClaims.setExpiration(refreshTokenExpiration);
}
return refreshTokenClaims.build();
}
示例9: createAccessToken
import org.springframework.security.oauth2.common.OAuth2RefreshToken; //导入依赖的package包/类
private OAuth2AuthenticationAccessToken createAccessToken() {
// Arrange
OAuth2AccessToken accessToken = Mockito.mock(OAuth2AccessToken.class);
when(accessToken.getValue()).thenReturn("Value");
OAuth2RefreshToken refreshToken = Mockito.mock(OAuth2RefreshToken.class);
when(accessToken.getRefreshToken()).thenReturn(refreshToken);
when(refreshToken.getValue()).thenReturn("RefreshTokenValue");
OAuth2Authentication auth2Authentication = Mockito.mock(OAuth2Authentication.class);
when(auth2Authentication.getName()).thenReturn("Name");
OAuth2Request oAuth2Request = Mockito.mock(OAuth2Request.class);
when(auth2Authentication.getOAuth2Request()).thenReturn(oAuth2Request);
String authenticationId = "AuthenticationID";
OAuth2AuthenticationAccessToken token =
new OAuth2AuthenticationAccessToken(accessToken, auth2Authentication, authenticationId);
// Act
// Assert
assertThat(token.getAuthentication(), is(auth2Authentication));
assertThat(token.getoAuth2AccessToken(), is(accessToken));
return token;
}
示例10: createRefreshToken
import org.springframework.security.oauth2.common.OAuth2RefreshToken; //导入依赖的package包/类
private OAuth2AuthenticationRefreshToken createRefreshToken() {
// Arrange
OAuth2RefreshToken refreshToken = Mockito.mock(OAuth2RefreshToken.class);
when(refreshToken.getValue()).thenReturn("RefreshTokenValue");
OAuth2Authentication auth2Authentication = Mockito.mock(OAuth2Authentication.class);
OAuth2AuthenticationRefreshToken token =
new OAuth2AuthenticationRefreshToken(refreshToken, auth2Authentication);
// Act
// Assert
assertThat(token.getAuthentication(), is(auth2Authentication));
assertThat(token.getoAuth2RefreshToken(), is(refreshToken));
return token;
}
示例11: readRefreshToken
import org.springframework.security.oauth2.common.OAuth2RefreshToken; //导入依赖的package包/类
public OAuth2RefreshToken readRefreshToken(String token) {
OAuth2RefreshToken refreshToken = null;
try {
DBObject query = new BasicDBObject(tokenIdFieldName, extractTokenKey(token));
DBObject projection = new BasicDBObject(tokenFieldName, 1);
DBObject savedToken = getRefreshTokenCollection().findOne(query, projection);
if (savedToken != null) {
refreshToken = deserializeRefreshToken((byte[]) savedToken.get(tokenFieldName));
} else {
LOG.info("Failed to find refresh token for token {}", token);
}
} catch (IllegalArgumentException e) {
LOG.warn("Failed to deserialize refresh token for token " + token, e);
removeRefreshToken(token);
}
return refreshToken;
}
示例12: DefaultOAuth2RefreshToken
import org.springframework.security.oauth2.common.OAuth2RefreshToken; //导入依赖的package包/类
@Test
/**
* NB: This used to test expiring refresh tokens. That test has been moved to sub-classes since not all stores support the functionality
*/ public void testStoreRefreshToken() {
DefaultOAuth2RefreshToken expectedRefreshToken = new DefaultOAuth2RefreshToken("testToken");
OAuth2Authentication expectedAuthentication = new OAuth2Authentication(
RequestTokenFactory.createOAuth2Request("id", false), new TestAuthentication("test2", false));
getTokenStore().storeRefreshToken(expectedRefreshToken, expectedAuthentication);
OAuth2RefreshToken actualExpiringRefreshToken = getTokenStore().readRefreshToken("testToken");
assertEquals(expectedRefreshToken, actualExpiringRefreshToken);
assertEquals(expectedAuthentication, getTokenStore().readAuthenticationForRefreshToken(expectedRefreshToken));
getTokenStore().removeRefreshToken(expectedRefreshToken);
assertNull(getTokenStore().readRefreshToken("testToken"));
assertNull(getTokenStore().readAuthentication(expectedRefreshToken.getValue()));
}
示例13: readRefreshToken
import org.springframework.security.oauth2.common.OAuth2RefreshToken; //导入依赖的package包/类
@Override
public OAuth2RefreshToken readRefreshToken(String token) {
OAuth2RefreshToken refreshToken = null;
try {
refreshToken = oAuth2RefreshTokenService.findOne(token);
if (refreshToken == null) {
if (LOG.isInfoEnabled()) {
LOG.info("Failed to find refresh token for token " + token);
}
}
} catch (Exception e) {
LOG.warn("Failed to read refresh token for token " + token, e);
removeRefreshToken(token);
}
return refreshToken;
}
示例14: readRefreshToken
import org.springframework.security.oauth2.common.OAuth2RefreshToken; //导入依赖的package包/类
@Override
public OAuth2RefreshToken readRefreshToken(String tokenValue) {
OAuth2RefreshToken refreshToken = null;
try {
GaeOAuthRefreshToken gaeOAuthRefreshToken = refreshTokens.findByTokenId(extractTokenKey(tokenValue));
if (gaeOAuthRefreshToken != null) {
refreshToken = gaeOAuthRefreshToken.getToken();
} else {
if (LOG.isInfoEnabled()) {
LOG.info("Failed to find refresh token for token " + tokenValue);
}
}
} catch (JDOException e) {
LOG.warn("Failed to deserialize refresh token for token " + tokenValue, e);
removeRefreshToken(tokenValue);
}
return refreshToken;
}
示例15: shouldStoreRefreshToken
import org.springframework.security.oauth2.common.OAuth2RefreshToken; //导入依赖的package包/类
@Test
public void shouldStoreRefreshToken() {
//Given
final OAuth2RefreshToken oAuth2RefreshToken = OAuth2RefreshTokenBuilder.oAuth2RefreshToken().build();
//And
final OAuth2Authentication oAuth2Authentication = OAuth2AuthenticationBuilder.oAuth2AuthenticationBuilder().build();
//And
final ArgumentCaptor<MongoOAuth2RefreshToken> argumentCaptor = ArgumentCaptor.forClass(MongoOAuth2RefreshToken.class);
//When
tokenStore.storeRefreshToken(oAuth2RefreshToken, oAuth2Authentication);
//Then
verify(mongoOAuth2RefreshTokenRepository).save(argumentCaptor.capture());
final MongoOAuth2RefreshToken refreshToken = argumentCaptor.getValue();
final byte[] expectedResult = SerializationUtils.serialize(oAuth2RefreshToken);
assertThat(refreshToken.getToken()).isEqualTo(expectedResult);
}