本文整理汇总了Java中org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken类的典型用法代码示例。如果您正苦于以下问题:Java DefaultOAuth2RefreshToken类的具体用法?Java DefaultOAuth2RefreshToken怎么用?Java DefaultOAuth2RefreshToken使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultOAuth2RefreshToken类属于org.springframework.security.oauth2.common包,在下文中一共展示了DefaultOAuth2RefreshToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createRefreshToken
import org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken; //导入依赖的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);
}
示例2: retrieveToken
import org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken; //导入依赖的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;
}
示例3: deserialize
import org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken; //导入依赖的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: testStoreRefreshToken
import org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken; //导入依赖的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()));
}
示例5: oAuth2AccessTokenMapper
import org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken; //导入依赖的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;
}
};
}
示例6: beforeEachTest
import org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken; //导入依赖的package包/类
@Before
public void beforeEachTest() {
this.mongoDBTokenStore =
new MongoDbTokenStore(oAuth2AccessTokenRepository, oAuth2RefreshTokenRepository);
OAuth2Request storedRequest = new OAuth2Request(new HashMap<>(), "clientId", new ArrayList<>(),
true, new HashSet<>(), new HashSet<>(), "/", new HashSet<>(), new HashMap<>());
UsernamePasswordAuthenticationToken userAuthentication =
new UsernamePasswordAuthenticationToken("principal",
new UsernamePasswordCredentials("username", "password"));
this.authentication = new OAuth2Authentication(storedRequest, userAuthentication);
this.refreshToken = new DefaultOAuth2RefreshToken("refreshToken");
this.accessToken = new DefaultOAuth2AccessToken("accessToken");
this.accessToken.setRefreshToken(this.refreshToken);
this.mongoDBTokenStore.storeAccessToken(this.accessToken, this.authentication);
this.mongoDBTokenStore.storeRefreshToken(this.refreshToken, this.authentication);
}
示例7: DefaultOAuth2RefreshToken
import org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken; //导入依赖的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()));
}
示例8: getResponseExtractor
import org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken; //导入依赖的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;
}
};
}
示例9: testRefreshTokenIsNotStoredDuringAccessToken
import org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken; //导入依赖的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"));
}
示例10: getAccessTokenByAuthCode
import org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken; //导入依赖的package包/类
/**
* Receive oauth2 token from authentication server and store it in the session context
*
* @param authorizationCode from authentication server
* @return oauth2 token
* @throws IOException
*/
@Override
public OAuth2AccessToken getAccessTokenByAuthCode(String authorizationCode) throws ParseException {
LOGGER.info("get oauth2 access token", TokenServiceImpl.class);
OAuthRequest oAuthRequest = new OAuthRequest(Verb.POST, ACCESS_TOKEN_URI);
oAuthRequest.addHeader("Content-Type", HEADER_CONTENT_TYPE);
oAuthRequest.addHeader("Authorization", HEADER_AUTHORIZATION_TYPE + Base64.encodeBase64String(new String(CLIENT_ID + ":" + CLIENT_SECRET).getBytes()));
oAuthRequest.setCharset(HEADER_CHAR_SET_TYPE);
oAuthRequest.addBodyParameter("grant_type", AUTHORIZATION_CODE_GRANT_TYPE);
oAuthRequest.addBodyParameter("code", authorizationCode);
LOGGER.info("send request for access token", TokenServiceImpl.class);
String accessTokenResponse = oAuthRequest.send().getBody();
if (accessTokenResponse != null) {
LOGGER.info("successfully received authorization token");
// store accessToken in session context
this.accessToken = new DefaultOAuth2AccessToken(new JSONObject(accessTokenResponse).get("access_token").toString());
((DefaultOAuth2AccessToken) this.accessToken).setRefreshToken(new DefaultOAuth2RefreshToken(new JSONObject(accessTokenResponse).get("refresh_token").toString()));
((DefaultOAuth2AccessToken) this.accessToken).setExpiration((new Date(System.currentTimeMillis() + (Long
.valueOf(new JSONObject(accessTokenResponse).get("expires_in").toString()) * 60000))));
String idToken = new JSONObject(accessTokenResponse).get("id_token").toString();
this.jwtDTO = parseJWTToken(idToken);
this.userId = this.jwtDTO.getUserId();
} else {
LOGGER.warn("failed to get authorization token", TokenServiceImpl.class);
}
return accessToken;
}
示例11: testRefreshTokenIsNotStoredDuringAccessToken
import org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken; //导入依赖的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"));
}
示例12: convertToExternal
import org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken; //导入依赖的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;
}
示例13: before
import org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken; //导入依赖的package包/类
@Before
public void before() throws Exception {
converter = new JaxbOAuth2AccessTokenMessageConverter();
accessToken = new DefaultOAuth2AccessToken("SlAV32hkKG");
accessToken.setExpiration(expiration);
accessToken.setRefreshToken(new DefaultOAuth2RefreshToken("8xLOxBtZp8"));
}
示例14: testSunnyDayWIthExpiredTokenAndValidRefreshToken
import org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken; //导入依赖的package包/类
@Test
public void testSunnyDayWIthExpiredTokenAndValidRefreshToken() throws Exception {
AccessTokenProviderChain chain = new AccessTokenProviderChain(Arrays.asList(new StubAccessTokenProvider()));
accessToken.setExpiration(new Date(System.currentTimeMillis() - 1000));
accessToken.setRefreshToken(new DefaultOAuth2RefreshToken("EXP"));
AccessTokenRequest request = new DefaultAccessTokenRequest();
request.setExistingToken(accessToken);
SecurityContextHolder.getContext().setAuthentication(user);
OAuth2AccessToken token = chain.obtainAccessToken(resource, request);
assertNotNull(token);
}
示例15: testSunnyDayWIthExpiredTokenAndExpiredRefreshToken
import org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken; //导入依赖的package包/类
@Test(expected = InvalidTokenException.class)
public void testSunnyDayWIthExpiredTokenAndExpiredRefreshToken() throws Exception {
AccessTokenProviderChain chain = new AccessTokenProviderChain(Arrays.asList(new StubAccessTokenProvider()));
accessToken.setExpiration(new Date(System.currentTimeMillis() - 1000));
DefaultOAuth2RefreshToken refreshToken = new DefaultExpiringOAuth2RefreshToken("EXP", new Date(
System.currentTimeMillis() - 1000));
accessToken.setRefreshToken(refreshToken);
AccessTokenRequest request = new DefaultAccessTokenRequest();
request.setExistingToken(accessToken);
SecurityContextHolder.getContext().setAuthentication(user);
OAuth2AccessToken token = chain.obtainAccessToken(resource, request);
assertNotNull(token);
}