Package org.springframework.security.oauth.examples.tonr

Source Code of org.springframework.security.oauth.examples.tonr.ResourceOwnerPasswordGrantTests

package org.springframework.security.oauth.examples.tonr;


import static org.junit.Assert.assertEquals;

import java.util.Arrays;

import org.junit.Rule;
import org.junit.Test;
import org.springframework.security.oauth2.client.OAuth2RestTemplate;
import org.springframework.security.oauth2.client.token.grant.password.ResourceOwnerPasswordResourceDetails;

/**
* @author Dave Syer
*/
public class ResourceOwnerPasswordGrantTests {

  @Rule
  public ServerRunning serverRunning = ServerRunning.isRunning();

  @Test
  public void testConnectDirectlyToResourceServer() throws Exception {

    ResourceOwnerPasswordResourceDetails resource = new ResourceOwnerPasswordResourceDetails();

    resource.setAccessTokenUri(serverRunning.getUrl("/sparklr2/oauth/token"));
    resource.setClientId("my-trusted-client");
    resource.setId("sparklr");
    resource.setScope(Arrays.asList("trust"));
    resource.setUsername("marissa");
    resource.setPassword("koala");

    OAuth2RestTemplate template = new OAuth2RestTemplate(resource);
    String result = template.getForObject(serverRunning.getUrl("/sparklr2/photos/user/message"), String.class);
    // System.err.println(result);
    assertEquals("Hello, Trusted User marissa", result);

  }

}
TOP

Related Classes of org.springframework.security.oauth.examples.tonr.ResourceOwnerPasswordGrantTests

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.