Example usage for org.springframework.security.oauth2.common DefaultExpiringOAuth2RefreshToken getValue

List of usage examples for org.springframework.security.oauth2.common DefaultExpiringOAuth2RefreshToken getValue

Introduction

In this page you can find the example usage for org.springframework.security.oauth2.common DefaultExpiringOAuth2RefreshToken getValue.

Prototype

@JsonValue
    public String getValue() 

Source Link

Usage

From source file:org.osiam.auth.token.OsiamCompositeTokenGranter.java

public OAuth2AccessToken grant(String grantType, AuthorizationRequest authorizationRequest) {
    OAuth2AccessToken grant = super.grant(grantType, authorizationRequest);
    if (grant != null) {
        DefaultOAuth2AccessToken token = (DefaultOAuth2AccessToken) grant;
        Map<String, Object> additionalInformation = new HashMap<String, Object>();
        additionalInformation.put("access_token", token.getValue());
        additionalInformation.put("expires_at", token.getExpiration());

        StringBuilder scopes = new StringBuilder();
        for (String scopeString : token.getScope()) {
            scopes.append(scopeString).append(" ");
        }/* ww  w .  j  a v a  2s .c o m*/
        additionalInformation.put("scopes", scopes);

        if (token.getRefreshToken() != null) {
            DefaultExpiringOAuth2RefreshToken refreshToken = (DefaultExpiringOAuth2RefreshToken) token
                    .getRefreshToken();
            additionalInformation.put("refresh_token", refreshToken.getValue());
            additionalInformation.put("refresh_token_expires_at", refreshToken.getExpiration());
        }

        additionalInformation.put("token_type", token.getTokenType());
        additionalInformation.put("client_id", authorizationRequest.getClientId());

        OAuth2Authentication auth = tokenServices.loadAuthentication(token.getValue());

        if (auth.getUserAuthentication() != null && auth.getPrincipal() instanceof User) {
            User user = (User) auth.getPrincipal();
            additionalInformation.put("user_name", user.getUserName());
            additionalInformation.put("user_id", user.getId());
        }

        token.setAdditionalInformation(additionalInformation);
    }
    return grant;
}