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

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

Introduction

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

Prototype

public OAuth2Request(Map<String, String> requestParameters, String clientId,
            Collection<? extends GrantedAuthority> authorities, boolean approved, Set<String> scope,
            Set<String> resourceIds, String redirectUri, Set<String> responseTypes,
            Map<String, Serializable> extensionProperties) 

Source Link

Usage

From source file:com.cedac.security.oauth2.provider.RequestTokenFactory.java

public static OAuth2Request createOAuth2Request(Map<String, String> requestParameters, String clientId,
        Collection<? extends GrantedAuthority> authorities, boolean approved, Collection<String> scope,
        Set<String> resourceIds, String redirectUri, Set<String> responseTypes,
        Map<String, Serializable> extensionProperties) {
    return new OAuth2Request(requestParameters, clientId, authorities, approved,
            scope == null ? null : new LinkedHashSet<String>(scope), resourceIds, redirectUri, responseTypes,
            extensionProperties);//from   w w  w.j  a v a 2s  .com
}

From source file:oauth2.authentication.tokens.RequestTokenFactory.java

public static OAuth2Request createOAuth2Request(Map<String, String> requestParameters, String clientId,
        Collection<? extends GrantedAuthority> authorities, boolean approved, Collection<String> scope,
        Set<String> resourceIds, String redirectUri, Set<String> responseTypes,
        Map<String, Serializable> extensionProperties) {
    return new OAuth2Request(requestParameters, clientId, authorities, approved,
            scope == null ? null : new LinkedHashSet<>(scope), resourceIds, redirectUri, responseTypes,
            extensionProperties);// www  . jav a  2s . com
}

From source file:components.OAuth2AuthenticationReadConverter.java

@Override
public OAuth2Authentication convert(DBObject source) {
    DBObject storedRequest = (DBObject) source.get("storedRequest");
    OAuth2Request oAuth2Request = new OAuth2Request(
            (Map<String, String>) storedRequest.get("requestParameters"),
            (String) storedRequest.get("clientId"), null, true, new HashSet((List) storedRequest.get("scope")),
            null, null, null, null);//from   w w  w . ja v a  2 s.  c  o m
    DBObject userAuthorization = (DBObject) source.get("userAuthentication");
    Object principal = getPrincipalObject(userAuthorization.get("principal"));
    Authentication userAuthentication = new UsernamePasswordAuthenticationToken(principal,
            (String) userAuthorization.get("credentials"),
            getAuthorities((List) userAuthorization.get("authorities")));
    OAuth2Authentication authentication = new OAuth2Authentication(oAuth2Request, userAuthentication);
    return authentication;
}

From source file:com.example.oauth.Authentication.java

private OAuth2Request request() {
    final ClientApplicationEntity clientApplication = accessTokenEntity.getClientApplication();
    return new OAuth2Request(Collections.emptyMap(), Long.toHexString(clientApplication.getId()),
            resourceUserAuthentication.getAuthorities(), true, accessToken.getScope(),
            Collections.singleton(ResourceConfig.RESOURCE_ID), clientApplication.getRedirectUri(),
            Collections.emptySet(), Collections.emptyMap());
}

From source file:org.zalando.stups.oauth2.spring.server.AbstractAuthenticationExtractor.java

@Override
public OAuth2Authentication extractAuthentication(final Map<String, Object> map, final String clientId) {
    UsernamePasswordAuthenticationToken user = new UsernamePasswordAuthenticationToken(getPrincipal(map), "N/A",
            AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
    user.setDetails(map);/*from w  w w  .  j av  a2s  .  co m*/

    // at the moment there is other way
    Set<String> scopes = resolveScopes(map);

    //
    OAuth2Request request = new OAuth2Request(null, clientId, null, true, scopes, null, null, null, null);
    return new OAuth2Authentication(request, user);
}

From source file:org.mitre.oauth2.assertion.impl.DirectCopyRequestFactory.java

@Override
public OAuth2Request createOAuth2Request(ClientDetails client, TokenRequest tokenRequest, JWT assertion) {

    try {//  w ww  .j a v a2  s  .c o m
        JWTClaimsSet claims = assertion.getJWTClaimsSet();
        Set<String> scope = OAuth2Utils.parseParameterList(claims.getStringClaim("scope"));

        Set<String> resources = Sets.newHashSet(claims.getAudience());

        return new OAuth2Request(tokenRequest.getRequestParameters(), client.getClientId(),
                client.getAuthorities(), true, scope, resources, null, null, null);
    } catch (ParseException e) {
        return null;
    }

}

From source file:com.golonzovsky.oauth2.google.security.GoogleAccessTokenConverter.java

public OAuth2Authentication extractAuthentication(Map<String, ?> map) {
    Map<String, String> parameters = new HashMap<>();
    Set<String> scope = parseScopes(map);
    Authentication user = userTokenConverter.extractAuthentication(map);
    String clientId = (String) map.get(CLIENT_ID);
    parameters.put(CLIENT_ID, clientId);
    Set<String> resourceIds = new LinkedHashSet<>(
            map.containsKey(AUD) ? (Collection<String>) map.get(AUD) : Collections.<String>emptySet());
    OAuth2Request request = new OAuth2Request(parameters, clientId, null, true, scope, resourceIds, null, null,
            null);//from  w w w. ja v  a2  s .co  m
    return new OAuth2Authentication(request, user);
}

From source file:com.ggk.hrms.authentication.CustomAccessTokenConverter.java

public OAuth2Authentication extractAuthentication(Map<String, ?> map) {
    Map<String, String> parameters = new HashMap<String, String>();
    Set<String> scope = parseScopes(map);
    Authentication user = userTokenConverter.extractAuthentication(map);
    String clientId = (String) map.get(CLIENT_ID);
    parameters.put(CLIENT_ID, clientId);
    Set<String> resourceIds = new LinkedHashSet<String>(
            map.containsKey(AUD) ? (Collection<String>) map.get(AUD) : Collections.<String>emptySet());
    OAuth2Request request = new OAuth2Request(parameters, clientId, null, true, scope, resourceIds, null, null,
            null);//  www.  j a  va2s.com
    return new OAuth2Authentication(request, user);
}

From source file:org.osiam.resource_server.security.authorization.AccessTokenValidationService.java

@Override
public OAuth2Authentication loadAuthentication(String token) {
    AccessToken accessToken = validateAccessToken(token);

    Set<String> scopes = new HashSet<String>();
    if (accessToken.getScopes() != null) {
        for (Scope scope : accessToken.getScopes()) {
            scopes.add(scope.toString());
        }/*from   w w w .  j  a  v  a 2s . com*/
    }

    // TODO, need more params
    OAuth2Request authRequest = new OAuth2Request(null, accessToken.getClientId(), null, true, scopes, null,
            null, null, null);

    Authentication auth = null;

    if (!accessToken.isClientOnly()) {
        User authUser = new User.Builder(accessToken.getUserName()).setId(accessToken.getUserId()).build();

        auth = new UsernamePasswordAuthenticationToken(authUser, null, new ArrayList<GrantedAuthority>());
    }

    return new OAuth2Authentication(authRequest, auth);
}

From source file:com.emergya.spring.security.oauth.google.GoogleAccessTokenConverter.java

/**
 * Creates an OAuth2Authentication object from the info recieved form the OAuth endpoint in a map.
 *
 * @param map the map containing authentication info
 * @return the encapsulated data/* w ww.j  ava2 s  .  co  m*/
 */
@Override
public final OAuth2Authentication extractAuthentication(final Map<String, ?> map) {
    Map<String, String> parameters = new HashMap<>();
    Set<String> scope = parseScopes(map);
    Authentication user = userTokenConverter.extractAuthentication(map);
    String clientId = (String) map.get(CLIENT_ID);
    parameters.put(CLIENT_ID, clientId);
    Set<String> resourceIds;
    if (map.containsKey(AUD)) {
        resourceIds = new LinkedHashSet<>((Collection<String>) map.get(AUD));
    } else {
        resourceIds = new LinkedHashSet<>(Collections.<String>emptySet());
    }
    OAuth2Request request = new OAuth2Request(parameters, clientId, null, true, scope, resourceIds, null, null,
            null);

    return new OAuth2Authentication(request, user);
}