I have a requirement from a customer to use an Oauth2 client not only for resource access but also as a single sign on mechanism. I'm using Spring 3.1.1, Security 3.1.0, and OAuth 1.0.0.M6. The sample application Tonr helped me with a general configuration of an authorization_code resource.
At first, I thought it should be as simple as changing my security configuration toeffectively triggering the OAuth2ClientContextFilter for all requestes. The filter fires correctly and the exception is caught.Code:intercept-url pattern="/**"
The problem is the in memory OAuth2ProtectedResourceDetails is never created. Instead, a runtime exception is thrown, redirecting the user to the configured application login page and not to the protected resource's login page. The expected exception is AccessTokenRequiredException but ex is type org.springframework.security.access.AccessDeniedEx ception, causing it to just be re thrown.Code:... try { chain.doFilter(servletRequest, servletResponse); } catch (Exception ex) { OAuth2ProtectedResourceDetails resourceThatNeedsAuthorization = checkForResourceThatNeedsAuthorization(ex); ...
What I'm trying to do is authenticate a user on the resource server and upon successful authentication, create a user on our client user system (for stats and other functions), using a OAuth2RestTemplate to retrieve user data from the resource server.Code:protected OAuth2ProtectedResourceDetails checkForResourceThatNeedsAuthorization(Exception ex) throws ServletException, IOException { Throwable[] causeChain = throwableAnalyzer.determineCauseChain(ex); AccessTokenRequiredException ase = (AccessTokenRequiredException) throwableAnalyzer.getFirstThrowableOfType( AccessTokenRequiredException.class, causeChain); OAuth2ProtectedResourceDetails resourceThatNeedsAuthorization; if (ase != null) { resourceThatNeedsAuthorization = ase.getResource(); if (resourceThatNeedsAuthorization == null) { throw new OAuth2AccessDeniedException(ase.getMessage()); } } else { // Rethrow ServletExceptions and RuntimeExceptions as-is ...
Any suggestions??


Reply With Quote
