Example usage for org.springframework.security.oauth2.client.token.grant.password ResourceOwnerPasswordResourceDetails setScope

List of usage examples for org.springframework.security.oauth2.client.token.grant.password ResourceOwnerPasswordResourceDetails setScope

Introduction

In this page you can find the example usage for org.springframework.security.oauth2.client.token.grant.password ResourceOwnerPasswordResourceDetails setScope.

Prototype

public void setScope(List<String> scope) 

Source Link

Usage

From source file:com.companyname.plat.commons.client.Oauth2Operation.java

public static OAuth2ProtectedResourceDetails readOnlyResourceDetails() {
    ResourceOwnerPasswordResourceDetails details = new ResourceOwnerPasswordResourceDetails();
    details.setClientId("my-client-with-registered-redirect");
    details.setClientSecret("somesecret");
    details.setScope(Arrays.asList("read"));
    details.setId("dmApp/trusted");
    details.setUsername("marissa");
    details.setPassword("koala");
    details.setAccessTokenUri(URLProvider.getUrl("/sparklr2/oauth/token"));
    return details;
}

From source file:com.bcknds.demo.oauth2.util.AuthenticationUtil.java

/**
 * Gets an OAuth2RestTemplate with the password configuration setup and ready to use.
 * /*from  w  w w. j ava 2  s  . c  o m*/
 * @return
 */
public static OAuth2RestTemplate getPasswordCredentials(final String username, final String password) {
    SSLCertificateValidation.disable();
    ResourceOwnerPasswordResourceDetails resource = new ResourceOwnerPasswordResourceDetails();
    resource.setClientAuthenticationScheme(AuthenticationScheme.header);
    resource.setClientId(BaseTest.PASSWORD_CLIENTID);
    resource.setScope(BaseTest.PASSWORD_SCOPE);
    resource.setId(BaseTest.PASSWORD_RESOURCEID);
    resource.setUsername(username);
    resource.setPassword(password);
    resource.setClientSecret(BaseTest.PASSWORD_SECRET);
    resource.setAccessTokenUri(BaseTest.ACCESS_TOKEN_URI);
    return new OAuth2RestTemplate(resource);
}

From source file:org.shaigor.rest.retro.client.oauth.OAuthPostAuthListener.java

@Override
public void onApplicationEvent(AbstractAuthenticationEvent event) {
    Authentication authentication = event.getAuthentication();

    if (event instanceof AuthenticationSuccessEvent) {
        ResourceOwnerPasswordResourceDetails resource = getResourceOwnerPasswordResourceDetails();
        resource.setScope(Arrays.asList("words"));
        resource.setUsername(authentication.getName());
        resource.setPassword(authentication.getCredentials().toString());

        try {//from w w  w .j a v  a  2 s . c  om
            OAuth2AccessToken accessToken = accessTokenProvider.obtainAccessToken(resource,
                    new DefaultAccessTokenRequest());
            log.debug("Access token request succeeded for user: '{}', new token is '{}'",
                    resource.getUsername(), accessToken.getValue());
            if (authentication instanceof AbstractAuthenticationToken
                    && authentication.getDetails() instanceof CustomAuthenticationDetails) {
                ((CustomAuthenticationDetails) ((AbstractAuthenticationToken) authentication).getDetails())
                        .setBearer(accessToken.getValue());
                log.debug("Access token was added to authentication as details");
            } else if (log.isDebugEnabled()) {
                log.debug("Access token could not be added to authentication as details");
            }
        } catch (Exception e) {
            log.error("Access token request failed for user: '" + resource.getUsername() + "'", e);
        }
    }
    if (authentication instanceof CredentialsContainer) {
        // Authentication is complete. Remove credentials and other secret data from authentication
        ((CredentialsContainer) authentication).eraseCredentials();
    }

}

From source file:com.create.application.configuration.ResourceOwnerPasswordResourceDetailsBuilder.java

public ResourceOwnerPasswordResourceDetails build() {
    ResourceOwnerPasswordResourceDetails resourceOwnerPasswordResourceDetails = new ResourceOwnerPasswordResourceDetails();
    resourceOwnerPasswordResourceDetails.setUsername(username);
    resourceOwnerPasswordResourceDetails.setPassword(password);
    resourceOwnerPasswordResourceDetails.setId(id);
    resourceOwnerPasswordResourceDetails.setGrantType(grantType);
    resourceOwnerPasswordResourceDetails.setClientId(clientId);
    resourceOwnerPasswordResourceDetails.setAccessTokenUri(accessTokenUri);
    resourceOwnerPasswordResourceDetails.setScope(scope);
    resourceOwnerPasswordResourceDetails.setClientSecret(clientSecret);
    resourceOwnerPasswordResourceDetails.setClientAuthenticationScheme(clientAuthenticationScheme);
    resourceOwnerPasswordResourceDetails.setTokenName(tokenName);
    return resourceOwnerPasswordResourceDetails;
}

From source file:org.cloudfoundry.identity.uaa.integration.UaaTestAccounts.java

@Override
public ResourceOwnerPasswordResourceDetails getResourceOwnerPasswordResource(String[] scope, String clientId,
        String clientSecret, String username, String password) {

    ResourceOwnerPasswordResourceDetails resource = new ResourceOwnerPasswordResourceDetails();
    resource.setClientId(clientId);//from w w w.j av a2 s.co  m
    resource.setClientSecret(clientSecret);
    resource.setId(clientId);
    resource.setScope(Arrays.asList(scope));
    Map<String, String> parameters = new LinkedHashMap<String, String>();
    parameters.put("username", username);
    parameters.put("password", password);
    resource.setUsername(username);
    resource.setPassword(password);
    resource.setClientAuthenticationScheme(AuthenticationScheme.header);
    resource.setAccessTokenUri(server.getAccessTokenUri());
    return resource;
}

From source file:org.cloudfoundry.identity.uaa.test.UaaTestAccounts.java

@Override
public ResourceOwnerPasswordResourceDetails getResourceOwnerPasswordResource(String[] scope, String clientId,
        String clientSecret, String username, String password) {

    ResourceOwnerPasswordResourceDetails resource = new ResourceOwnerPasswordResourceDetails();
    resource.setClientId(clientId);/*from   www  .  j a  v a 2s.c o m*/
    resource.setClientSecret(clientSecret);
    resource.setId(clientId);
    resource.setScope(Arrays.asList(scope));
    resource.setUsername(username);
    resource.setPassword(password);
    resource.setClientAuthenticationScheme(AuthenticationScheme.header);
    resource.setAccessTokenUri(server.getAccessTokenUri());
    return resource;
}