本文整理匯總了Java中org.springframework.security.oauth2.common.DefaultOAuth2AccessToken.setAdditionalInformation方法的典型用法代碼示例。如果您正苦於以下問題:Java DefaultOAuth2AccessToken.setAdditionalInformation方法的具體用法?Java DefaultOAuth2AccessToken.setAdditionalInformation怎麽用?Java DefaultOAuth2AccessToken.setAdditionalInformation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.security.oauth2.common.DefaultOAuth2AccessToken
的用法示例。
在下文中一共展示了DefaultOAuth2AccessToken.setAdditionalInformation方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: enhance
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Override
public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
if (!(accessToken instanceof DefaultOAuth2AccessToken)) {
throw new IllegalArgumentException("Token must be a DefaultOAuth2AccessToken");
}
DefaultOAuth2AccessToken token = (DefaultOAuth2AccessToken) accessToken;
UserDetails user = (UserDetails) authentication.getPrincipal();
Map<String, Object> additionalInformation = new HashMap<>();
additionalInformation.put("user_name", user.getUsername());
List<String> roles = user.getAuthorities()
.stream()
.map(GrantedAuthority::getAuthority)
.collect(Collectors.toList());
additionalInformation.put("user_roles", roles);
token.setAdditionalInformation(additionalInformation);
return token;
}
示例2: 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;
}
示例3: 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;
}
示例4: enhance
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Override
public OAuth2AccessToken enhance(
OAuth2AccessToken accessToken,
OAuth2Authentication authentication) {
Map<String, Object> additional = new HashMap<>();
ResourceOwnerUserDetails user = (ResourceOwnerUserDetails)
authentication.getPrincipal();
additional.put("email", user.getEmail());
DefaultOAuth2AccessToken token = (DefaultOAuth2AccessToken) accessToken;
token.setAdditionalInformation(additional);
return accessToken;
}
示例5: enhance
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
private Collection<OAuth2AccessToken> enhance(Collection<OAuth2AccessToken> tokens) {
Collection<OAuth2AccessToken> result = new ArrayList<OAuth2AccessToken>();
for (OAuth2AccessToken prototype : tokens) {
DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken(prototype);
OAuth2Authentication authentication = tokenStore.readAuthentication(token);
if (authentication == null) {
continue;
}
String userName = authentication.getName();
if (StringUtils.isEmpty(userName)) {
userName = "Unknown";
}
Map<String, Object> map = new HashMap<String, Object>(token.getAdditionalInformation());
map.put("user_name", userName);
token.setAdditionalInformation(map);
result.add(token);
}
return result;
}
示例6: enhance
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Override
public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
Map<String, String> requestParameters = authentication.getOAuth2Request().getRequestParameters();
Map<String, Object> additionalInfos = null;
for (Map.Entry<String, String> entry : requestParameters.entrySet()) {
if (entry.getKey().startsWith(EXTENDED_DETAILS_ATTRIBUTE_PREFIX)) {
String detailsKey = entry.getKey().substring(EXTENDED_DETAILS_ATTRIBUTE_PREFIX.length());
if (additionalInfos == null) {
additionalInfos = new HashMap<>();
}
additionalInfos.put(detailsKey, entry.getValue());
}
}
if (additionalInfos != null) {
additionalInfos.putAll(accessToken.getAdditionalInformation());
DefaultOAuth2AccessToken mutableAccessToken = (DefaultOAuth2AccessToken) accessToken;
mutableAccessToken.setAdditionalInformation(additionalInfos);
}
return accessToken;
}
示例7: enhance
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Override
public OAuth2AccessToken enhance(final OAuth2AccessToken accessToken, final OAuth2Authentication authentication) {
DefaultOAuth2AccessToken token = (DefaultOAuth2AccessToken) accessToken;
Map<String, Object> additionalInformation = new HashMap<>();
additionalInformation.put("expires_at", token.getExpiration());
if (token.getRefreshToken() != null) {
DefaultExpiringOAuth2RefreshToken refreshToken =
(DefaultExpiringOAuth2RefreshToken) token.getRefreshToken();
additionalInformation.put("refresh_token_expires_at", refreshToken.getExpiration());
}
additionalInformation.put("client_id", authentication.getOAuth2Request().getClientId());
if (authentication.getUserAuthentication() != null && authentication.getPrincipal() instanceof User) {
User user = (User) authentication.getPrincipal();
additionalInformation.put("user_name", user.getUserName());
additionalInformation.put("user_id", user.getId());
}
token.setAdditionalInformation(additionalInformation);
return accessToken;
}
示例8: 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;
}
};
}
示例9: enhance
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Override
public OAuth2AccessToken enhance(
OAuth2AccessToken accessToken,
OAuth2Authentication authentication) {
Map<String, Object> additional = new HashMap<>();
String publicKey = authentication.getOAuth2Request().getRequestParameters().get("public_key");
additional.put("public_key", publicKey);
DefaultOAuth2AccessToken defaultAccessToken = (DefaultOAuth2AccessToken) accessToken;
defaultAccessToken.setAdditionalInformation(additional);
return accessToken;
}
示例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: enhance
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Override
public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
DefaultOAuth2AccessToken result = new DefaultOAuth2AccessToken(accessToken);
Map<String, Object> info = new LinkedHashMap<>(accessToken.getAdditionalInformation());
String tokenId = result.getValue();
if (!info.containsKey(TOKEN_ID)) {
info.put(TOKEN_ID, tokenId);
}
result.setAdditionalInformation(info);
result.setValue(encode(result, authentication));
return result;
}
示例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: enhance
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
/**
* Values placed into the map will be included in the JWT token and the OAuth 2 response itself.
*/
@Override
public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
DefaultOAuth2AccessToken customAccessToken = new DefaultOAuth2AccessToken(accessToken);
Map<String, Object> map = new LinkedHashMap<String, Object>(accessToken.getAdditionalInformation());
map.put("sub", authentication.getOAuth2Request().getClientId());
map.put("iss", issuer);
map.put("iat", new Date().getTime() / 1000);
Authentication userAuthentication = authentication.getUserAuthentication();
if (userAuthentication == null) {
customAccessToken.setAdditionalInformation(map);
return super.enhance(customAccessToken, authentication);
}
AuthenticatedAccount account = getUser(userAuthentication);
if (account == null) {
customAccessToken.setAdditionalInformation(map);
return super.enhance(customAccessToken, authentication);
}
map.put("sub", account.getIdentfifier());
customAccessToken.setAdditionalInformation(map);
return super.enhance(customAccessToken, authentication);
}
示例15: enhance
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; //導入方法依賴的package包/類
@Override
public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
Map<String, Object> info = new LinkedHashMap<>(accessToken.getAdditionalInformation());
info.put("user_id", ((UserCredentials) authentication.getPrincipal()).getUser().getId());
DefaultOAuth2AccessToken customAccessToken = new DefaultOAuth2AccessToken(accessToken);
customAccessToken.setAdditionalInformation(info);
return super.enhance(customAccessToken, authentication);
}