Hi,
I am building a simple OAuth2 provider using spring-security-oauth 1.0.2.RELEASE. My XML configuration is:
And my access confirmation controller:Code:<http auto-config='true' xmlns="http://www.springframework.org/schema/security"> <intercept-url pattern="/**" access="ROLE_USER" /> </http> <authentication-manager xmlns="http://www.springframework.org/schema/security"> <authentication-provider> <user-service> <user name="a" password="a" authorities="ROLE_USER" /> </user-service> </authentication-provider> </authentication-manager> <!-- OAuth Provider Configuration --> <oauth2:authorization-server client-details-service-ref="clientDetailsService" token-services-ref="tokenServices" user-approval-handler-ref="userApprovalHandler"> <oauth2:authorization-code /> <oauth2:implicit /> <oauth2:refresh-token /> <oauth2:client-credentials /> <oauth2:password /> </oauth2:authorization-server> <bean id="userApprovalHandler" class="org.springframework.security.oauth2.provider.approval.TokenServicesUserApprovalHandler"> <property name="tokenServices" ref="tokenServices" /> </bean> <oauth2:client-details-service id="clientDetailsService"> <oauth2:client client-id="test-client" secret="123456" authorized-grant-types="authorization_code" /> </oauth2:client-details-service> <bean id="tokenServices" class="org.springframework.security.oauth2.provider.token.DefaultTokenServices"> <property name="tokenStore" ref="tokenStore" /> <property name="supportRefreshToken" value="true" /> <property name="clientDetailsService" ref="clientDetailsService" /> </bean> <bean id="tokenStore" class="org.springframework.security.oauth2.provider.token.InMemoryTokenStore"></bean>
I also write a simple test client to test it. But I got a "java.lang.NullPointerException" in "ClientDetails client = clientDetailsService.loadClientByClientId(clientAu th.getClientId());" when I logged in the server and try to get user's authorization in the /oauth/confirm_access.Code:@Controller @SessionAttributes("authorizationRequest") public class ConfirmationController { private ClientDetailsService clientDetailsService; @RequestMapping("/oauth/confirm_access") public ModelAndView getAccessConfirmation(Map<String, Object> model) throws Exception { AuthorizationRequest clientAuth = (AuthorizationRequest) model.remove("authorizationRequest"); ClientDetails client = clientDetailsService.loadClientByClientId(clientAuth.getClientId()); model.put("auth_request", clientAuth); model.put("client", client); return new ModelAndView("access_confirmation", model); } @RequestMapping("/oauth/error") public String handleError(Map<String,Object> model) throws Exception { // We can add more stuff to the model here for JSP rendering. If the client was a machine then // the JSON will already have been rendered. model.put("message", "There was a problem with the OAuth2 protocol"); return "oauth_error"; } @Autowired public void setClientDetailsService(ClientDetailsService clientDetailsService) { this.clientDetailsService = clientDetailsService; } }
After I searched solution for this, I add " create-session=“stateless” " in the XML configuration file, I can't even log in the server before entering the ConfirmationController.
Any solution for this?
Thank you very much in advance!


Reply With Quote
