2016-09-10 11 views
0

まず、I無効ベーシック認証:春のセキュリティのOAuth2:InsufficientAuthenticationExceptionすべての

org.springframework.security.authentication.InsufficientAuthenticationException: User must be authenticated with Spring Security before authorization can be completed. 
    at org.springframework.security.oauth2.provider.endpoint.AuthorizationEndpoint.authorize(AuthorizationEndpoint.java:138) ~[spring-security-oauth2-2.0.10.RELEASE.jar:na] 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_45] 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_45] 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45] 
    at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_45] 
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) ~[spring-web-4.2.7.RELEASE.jar:4.2.7.RELEASE] 
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) ~[spring-web-4.2.7.RELEASE.jar:4.2.7.RELEASE] 
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) ~[spring-webmvc-4.2.7.RELEASE.jar:4.2.7.RELEASE] 
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:832) ~[spring-webmvc-4.2.7.RELEASE.jar:4.2.7.RELEASE] 
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:743) ~[spring-webmvc-4.2.7.RELEASE.jar:4.2.7.RELEASE] 
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.2.7.RELEASE.jar:4.2.7.RELEASE] 
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:961) ~[spring-webmvc-4.2.7.RELEASE.jar:4.2.7.RELEASE] 
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:895) ~[spring-webmvc-4.2.7.RELEASE.jar:4.2.7.RELEASE] 
    at ... 

http://localhost:8080/oauth/authorize?client_id=client&response_type=code&redirect_uri=http://www.baidu.com 

私は例外次しまった。その後

security.basic.enabled=false 

は、私が承認ページにアクセス私はなぜOAuthの前に認証をしなければならないのか分かりません。

答えて

3

認証コード付与の流れはこのように書きます:

  1. クライアントは、認証サーバーの認証ページにユーザーをリダイレクトします。したがって、http://localhost:8080/oauth/authorize?client_id=client&response_type=code&redirect_uri=http://www.baidu.com
  2. ユーザーが既にログインしている場合、ユーザーは承認要求を承認できる承認ページがすぐに表示されます。 ユーザがまだログインしていない場合は、最初にログインページにリダイレクトして、を認証して、誰が認可しているのかをSpring Securityに知らせる必要があります。あなたはおそらく行うに必要なもの

XMLでこのように付与されたロールを要求することにより、認可エンドポイントを確保である:

<security:http disable-url-rewriting="true" 
       use-expressions="true" 
       entry-point-ref="loginEntryPoint"> 
    ... 

    <security:intercept-url pattern="/oauth/authorize" access="hasRole('ROLE_USER')"/> 
    ... 
</security:http> 

ユーザーがまだログインしていない場合、これはリダイレクトするために春のセキュリティをトリガーしますloginEntryPointに設定されているようにログインするユーザー。通常は、ユーザーをログインページにリダイレクトします。認証に成功すると、ユーザーは認証エンドポイントに戻ります。

関連する問題