Announcement Announcement Module
Collapse
No announcement yet.
Authentication from java code Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment

    Working...
    X