Example usage for org.springframework.security.oauth2.provider OAuth2Request getResourceIds

List of usage examples for org.springframework.security.oauth2.provider OAuth2Request getResourceIds

Introduction

In this page you can find the example usage for org.springframework.security.oauth2.provider OAuth2Request getResourceIds.

Prototype

public Set<String> getResourceIds() 

Source Link

Usage

From source file:org.mitre.oauth2.model.AuthenticationHolderEntity.java

public void setAuthentication(OAuth2Authentication authentication) {

    // pull apart the request and save its bits
    OAuth2Request o2Request = authentication.getOAuth2Request();
    setAuthorities(o2Request.getAuthorities());
    setClientId(o2Request.getClientId());
    setExtensions(o2Request.getExtensions());
    setRedirectUri(o2Request.getRedirectUri());
    setRequestParameters(o2Request.getRequestParameters());
    setResourceIds(o2Request.getResourceIds());
    setResponseTypes(o2Request.getResponseTypes());
    setScope(o2Request.getScope());
    setApproved(o2Request.isApproved());

    if (authentication.getUserAuthentication() != null) {
        this.userAuth = new SavedUserAuthentication(authentication.getUserAuthentication());
    } else {//from w  w  w  .  ja v a2s.c om
        this.userAuth = null;
    }
}

From source file:no.imr.common.security.jwt.DefaultAccessTokenConverter.java

public Map<String, ?> convertAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication) {
    Map<String, Object> response = new HashMap<String, Object>();
    OAuth2Request clientToken = authentication.getOAuth2Request();

    if (!authentication.isClientOnly()) {
        response.putAll(userTokenConverter.convertUserAuthentication(authentication.getUserAuthentication()));
    } else {// w w  w  .  j  a v  a 2 s. c  om
        if (clientToken.getAuthorities() != null && !clientToken.getAuthorities().isEmpty()) {
            response.put(UserAuthenticationConverter.AUTHORITIES,
                    AuthorityUtils.authorityListToSet(clientToken.getAuthorities()));
        }
    }

    if (token.getScope() != null) {
        response.put(SCOPE, token.getScope());
    }
    if (token.getAdditionalInformation().containsKey(JTI)) {
        response.put(JTI, token.getAdditionalInformation().get(JTI));
    }

    if (token.getExpiration() != null) {
        response.put(EXP, token.getExpiration().getTime() / 1000);
    }

    if (includeGrantType && authentication.getOAuth2Request().getGrantType() != null) {
        response.put(GRANT_TYPE, authentication.getOAuth2Request().getGrantType());
    }

    response.putAll(token.getAdditionalInformation());

    response.put(CLIENT_ID, clientToken.getClientId());
    if (clientToken.getResourceIds() != null && !clientToken.getResourceIds().isEmpty()) {
        response.put(AUD, clientToken.getResourceIds());
    }
    return response;
}

From source file:org.opentestsystem.shared.security.oauth.resource.SbacTokenConverter.java

@Override
public Map<String, ?> convertAccessToken(final OAuth2AccessToken token,
        final OAuth2Authentication authentication) {
    final Map<String, Object> response = Maps.newHashMap();
    final OAuth2Request clientToken = authentication.getOAuth2Request();

    if (!authentication.isClientOnly()) {
        response.putAll(/*w ww .  j a  va2 s  .  c om*/
                this.userTokenConverter.convertUserAuthentication(authentication.getUserAuthentication()));
    }

    if (token.getScope() != null) {
        response.put(SCOPE, token.getScope());
    }

    if (token.getExpiration() != null) {
        response.put(EXPIRES, token.getExpiration().getTime() / 1000);
    }

    response.putAll(token.getAdditionalInformation());

    response.put(CLIENT_ID, clientToken.getClientId());
    if (clientToken.getResourceIds() != null && !clientToken.getResourceIds().isEmpty()) {
        response.put(AUD, clientToken.getResourceIds());
    }
    return response;
}

From source file:org.orcid.core.oauth.service.OrcidTokenStoreServiceImpl.java

private OrcidOauth2TokenDetail populatePropertiesFromTokenAndAuthentication(OAuth2AccessToken token,
        OAuth2Authentication authentication, OrcidOauth2TokenDetail detail) {
    OAuth2Request authorizationRequest = authentication.getOAuth2Request();
    if (detail == null) {
        detail = new OrcidOauth2TokenDetail();
    }/*  w w w  .j  a va  2 s . c  o  m*/
    String clientId = authorizationRequest.getClientId();
    String authKey = KEY_GENERATOR.extractKey(authentication);
    detail.setAuthenticationKey(authKey);
    detail.setClientDetailsId(clientId);

    OAuth2RefreshToken refreshToken = token.getRefreshToken();
    if (refreshToken != null && StringUtils.isNotBlank(refreshToken.getValue())) {
        if (refreshToken instanceof ExpiringOAuth2RefreshToken) {
            // Override the refresh token expiration from the client
            // details, and make it the same as the token itself
            detail.setRefreshTokenExpiration(token.getExpiration());
        }
        detail.setRefreshTokenValue(refreshToken.getValue());
    }
    if (!authentication.isClientOnly()) {
        Object principal = authentication.getPrincipal();
        if (principal instanceof ProfileEntity) {
            ProfileEntity profileEntity = (ProfileEntity) authentication.getPrincipal();
            profileEntity = profileEntityCacheManager.retrieve(profileEntity.getId());
            detail.setProfile(profileEntity);
        }
    }

    detail.setTokenValue(token.getValue());
    detail.setTokenType(token.getTokenType());
    detail.setTokenExpiration(token.getExpiration());
    detail.setApproved(authorizationRequest.isApproved());
    detail.setRedirectUri(authorizationRequest.getRedirectUri());

    Set<String> resourceIds = authorizationRequest.getResourceIds();
    if (resourceIds == null || resourceIds.isEmpty()) {
        ClientDetailsEntity clientDetails = clientDetailsEntityCacheManager.retrieve(clientId);
        resourceIds = clientDetails.getResourceIds();
    }

    detail.setResourceId(OAuth2Utils.formatParameterList(resourceIds));
    detail.setResponseType(OAuth2Utils.formatParameterList(authorizationRequest.getResponseTypes()));
    detail.setScope(OAuth2Utils.formatParameterList(authorizationRequest.getScope()));

    Map<String, Object> additionalInfo = token.getAdditionalInformation();
    if (additionalInfo != null) {
        if (additionalInfo.containsKey(OrcidOauth2Constants.TOKEN_VERSION)) {
            String sVersion = String.valueOf(additionalInfo.get(OrcidOauth2Constants.TOKEN_VERSION));
            detail.setVersion(Long.valueOf(sVersion));
        } else {
            // TODO: As of Jan 2015 all tokens will be new tokens, so, we
            // will have to remove the token version code and
            // treat all tokens as new tokens
            detail.setVersion(Long.valueOf(OrcidOauth2Constants.PERSISTENT_TOKEN));
        }

        if (additionalInfo.containsKey(OrcidOauth2Constants.PERSISTENT)) {
            boolean isPersistentKey = (Boolean) additionalInfo.get(OrcidOauth2Constants.PERSISTENT);
            detail.setPersistent(isPersistentKey);
        } else {
            detail.setPersistent(false);
        }
    } else {
        detail.setPersistent(false);
    }

    return detail;
}