Results 1 to 2 of 2

Thread: No OAuth 2 security context has been established. Unable to access resource...

  1. #1
    Join Date
    Mar 2012
    Posts
    9

    Default No OAuth 2 security context has been established. Unable to access resource...

    When I attempt to use a oauth rest template, I get:

    No OAuth 2 security context has been established. Unable to access resource...

    At:

    org.springframework.security.oauth2.client.http.OA uth2ClientHttpRequestFactory.createRequest(OAuth2C lientHttpRequestFactory.java:55)
    org.springframework.http.client.support.HttpAccess or.createRequest(HttpAccessor.java:76)
    org.springframework.web.client.RestTemplate.doExec ute(RestTemplate.java:434)
    org.springframework.web.client.RestTemplate.execut e(RestTemplate.java:401)
    org.springframework.web.client.RestTemplate.getFor Entity(RestTemplate.java:221)


    I've looked through the archives & found tried some of the fixes for what is the identical issue, but they haven't worked for me, most specifically the custom filter mentioned in the documents and several threads. According to my debug logs on the provider side, no authentication is ever attempted.

    The seemingly relevant configuration in what is a very simple roo web app set up to test only oauth2 client connectivity looks like:

    Code:
    <http access-denied-page="/spring_security_login?authorization_error=true" use-expressions="true"
     xmlns="http://www.springframework.org/schema/security">
            <intercept-url pattern="/**" access="isAuthenticated()" />
            <form-login/>
            <logout logout-url="/resources/j_spring_security_logout"/>        
    		<anonymous />
    		<custom-filter ref="oauth2ClientFilter" after="EXCEPTION_TRANSLATION_FILTER" />
    </http>
    <oauth:client id="oauth2ClientFilter" redirect-on-error="${redirectOnError:true}" />
    
    <oauth:resource id="readWriteClient" type="authorization_code" client-id="CredentialServicesSite" client-secret="secret"
    		access-token-uri="${accessTokenUri}" user-authorization-uri="${userAuthorizationUri}" scope="read,write" />
    
    <bean id="sigkatService" class="com.credder.services.SigkatService">
    	<property name="sigkatRestTemplate">
    		<bean class="org.springframework.security.oauth2.client.OAuth2RestTemplate">
    			<constructor-arg ref="readWriteClient" />
    		</bean>
    	</property>
    </bean>
    And then the controller code, which is:

    Code:
    @RequestMapping()
    public String post(ModelMap modelMap, HttpServletRequest request, HttpServletResponse response) {
            String body="Hello redirecturi<p>";
        	body+=sigkatService.getSigkatRestTemplate().getForEntity("http://localhost:8080/okat/api/model",String.class);
        	modelMap.addAttribute("body", "Hello redirecturi");
        	return "redirecturi/index";
    }
    Via other tests, everything seems fine on the provider end, but in any event, it isn't even getting that far.

    FWIW, I've tried it with both the redirect on error set to both true/false...

    Any help on this would be appreciated.

    Jay Roberts
    Last edited by robatsu; Mar 18th, 2012 at 06:10 PM.

  2. #2
    Join Date
    Mar 2012
    Posts
    9

    Default

    Ok, never mind. This thread had the fix.

Posting Permissions

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