本文整理匯總了Java中org.springframework.security.oauth2.common.DefaultOAuth2AccessToken.valueOf方法的典型用法代碼示例。如果您正苦於以下問題:Java DefaultOAuth2AccessToken.valueOf方法的具體用法?Java DefaultOAuth2AccessToken.valueOf怎麽用?Java DefaultOAuth2AccessToken.valueOf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.security.oauth2.common.DefaultOAuth2AccessToken
的用法示例。
在下文中一共展示了DefaultOAuth2AccessToken.valueOf方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: refreshAccessToken
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
private OAuth2AccessToken refreshAccessToken(String refreshToken) {
MultiValueMap<String, String> formData = new LinkedMultiValueMap<String, String>();
formData.add("grant_type", "refresh_token");
formData.add("client_id", "my-trusted-client");
formData.add("refresh_token", refreshToken);
@SuppressWarnings("rawtypes")
ResponseEntity<Map> response = serverRunning.postForMap("/sparklr2/oauth/token", formData);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertTrue("Wrong cache control: " + response.getHeaders().getFirst("Cache-Control"), response.getHeaders().getFirst("Cache-Control").contains("no-store"));
@SuppressWarnings("unchecked")
OAuth2AccessToken newAccessToken = DefaultOAuth2AccessToken.valueOf(response.getBody());
return newAccessToken;
}
示例2: read
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Override
public OAuth2AccessToken read(Type type, Class<?> contextClass, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
Charset charset = getContentTypeCharset(inputMessage.getHeaders().getContentType());
String tokenResult = StreamUtils.copyToString(inputMessage.getBody(), charset);
log.info("tokenResult:{}", tokenResult);
String[] results = tokenResult.split("&");
if (results.length == 3) {
Map<String, String> tokenParams = new HashMap<>();
tokenParams.put(ACCESS_TOKEN, results[0].replace("access_token=", ""));
tokenParams.put(EXPIRES_IN, results[1].replace("expires_in=", ""));
tokenParams.put(REFRESH_TOKEN, results[2].replace("refresh_token=", ""));
return DefaultOAuth2AccessToken.valueOf(tokenParams);
}
return null;
}
示例3: interceptCall
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
ServerCall<ReqT, RespT> call,
final Metadata requestHeaders,
ServerCallHandler<ReqT, RespT> next) {
String token = requestHeaders.get(authKey);
String principal = null;
if (StringUtils.isEmpty(token))
{
logger.warn("Failed to find token");
}
else
{
Map<String,String> tokenParams = new HashMap<>();
tokenParams.put(OAuth2AccessToken.ACCESS_TOKEN,token);
OAuth2AccessToken otoken = DefaultOAuth2AccessToken.valueOf(tokenParams);
OAuth2Authentication auth = server.getTokenStore().readAuthentication(otoken);
if (auth != null && auth.isAuthenticated())
{
logger.debug("Principal:"+auth.getPrincipal());
principal = auth.getPrincipal().toString();
}
else
{
logger.warn("Failed to authenticate token "+token);
}
}
return new MessagePrincipalListener<ReqT>(next.startCall(call, requestHeaders),principal,server);
}
示例4: extractData
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
public OAuth2AccessToken extractData(ClientHttpResponse response) throws IOException {
// TODO: this should actually be a 401 if the request asked for JSON
URI location = response.getHeaders().getLocation();
if (location == null) {
return null;
}
String fragment = location.getFragment();
OAuth2AccessToken accessToken = DefaultOAuth2AccessToken.valueOf(OAuth2Utils.extractMap(fragment));
if (accessToken.getValue() == null) {
throw new UserRedirectRequiredException(location.toString(), Collections.<String, String> emptyMap());
}
return accessToken;
}
示例5: getAccessToken
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
private OAuth2AccessToken getAccessToken(String scope, String clientId) throws Exception {
MultiValueMap<String, String> formData = getTokenFormData(scope, clientId);
@SuppressWarnings("rawtypes")
ResponseEntity<Map> response = serverRunning.postForMap("/sparklr2/oauth/token", formData);
assertEquals(HttpStatus.OK, response.getStatusCode());
assertTrue("Wrong cache control: " + response.getHeaders().getFirst("Cache-Control"), response.getHeaders().getFirst("Cache-Control").contains("no-store"));
@SuppressWarnings("unchecked")
OAuth2AccessToken accessToken = DefaultOAuth2AccessToken.valueOf(response.getBody());
return accessToken;
}
示例6: readInternal
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Override
protected OAuth2AccessToken readInternal(Class<? extends OAuth2AccessToken> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
MultiValueMap<String, String> data = delegateMessageConverter.read(null, inputMessage);
return DefaultOAuth2AccessToken.valueOf(data.toSingleValueMap());
}