Results 1 to 2 of 2

Thread: Authentication from java code

  1. #1
    Join Date
    Mar 2007
    Posts
    10

    Default Authentication from java code

    We have two web applications. One of them implements an OAuth 1.0 server, the other one is the consumer. I'm designing some JUnit tests to run out of the box, from Java code, without using filters from OAuth for Spring Security, as I'm not in a web application environment. I've reading the introduction (https://github.com/SpringSource/spri...th/wiki/oauth1) and the api documentation, but I cannot figure out how to do that. I need a request token to access a protected resource in the server from my tests.

    I need to create an OAuthSecurityContextHolder to be able to perform restful calls from my test cases:

    Code:
    	@Before
    	public void onSetup() {
    		OAuthSecurityContextImpl context = new OAuthSecurityContextImpl();
    		Map<String, OAuthConsumerToken> accessTokens = new TreeMap<String, OAuthConsumerToken>();
    
    		OAuthConsumerToken token = new OAuthConsumerToken();
    		token.setAccessToken(true);
    		token.setResourceId(TOKEN_RESOURCE_ID);
    		token.setSecret(TOKEN_SECRET);
    		token.setValue(TOKEN_VALUE);
    
    		accessTokens.put(TOKEN_RESOURCE_ID, token);
    
    		context.setAccessTokens(accessTokens);
    
    		OAuthSecurityContextHolder.setContext(context);
    	}
    At the moment, I am getting a 401 unauthorized http error. How can I get a token from my server?

  2. #2
    Join Date
    May 2008
    Location
    Salt Lake City
    Posts
    167

    Default

    This spring-security-oauth library isn't designed to be a self-contained client at the moment. Spring Social has some self-contained oauth client code that you can use. Someday, we're hoping to converge the two code bases. There are other oauth client libraries that can be used, too.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •