2014-12-12 2 views
0

웹 응용 프로그램 보안을 설정하고 제공된 사용자 자격 증명으로 신뢰할 수있는 클라이언트 만 응용 프로그램에 액세스 할 수 있도록 허용하려면 oauth2 구성을 가져 오려고합니다.토큰 URL이 봄 보안과 함께 실패합니다 oauth2

이것은 내가 지금까지

<?xml version="1.0" encoding="UTF-8" ?> 
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:oauth="http://www.springframework.org/schema/security/oauth2" xmlns:sec="http://www.springframework.org/schema/security" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation="http://www.springframework.org/schema/security/oauth2 http://www.springframework.org/schema/security/spring-security-oauth2-1.0.xsd 
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 
    http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd 
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"> 


    <http pattern="/oauth/token" create-session="stateless" authentication-manager-ref="clientAuthenticationManager" 
    xmlns="http://www.springframework.org/schema/security"> 
     <intercept-url pattern="/oauth/token" access="IS_AUTHENTICATED_FULLY" /> 
     <anonymous enabled="false" /> 
     <http-basic entry-point-ref="clientAuthenticationEntryPoint" /> 
     <!-- include this only if you need to authenticate clients via request parameters --> 
     <custom-filter ref="clientCredentialsTokenEndpointFilter" after="BASIC_AUTH_FILTER" /> 
     <access-denied-handler ref="oauthAccessDeniedHandler" /> 
    </http> 

    <!-- The OAuth2 protected resources are separated out into their own block so we can deal with authorization and error handling 
separately. This isn't mandatory, but it makes it easier to control the behaviour. --> 
    <http request-matcher="regex" create-session="stateless" entry-point-ref="oauthAuthenticationEntryPoint" 
     xmlns="http://www.springframework.org/schema/security"> 
     <!-- <anonymous enabled="false" /> --> 
     <intercept-url pattern="/api/register/.*" access="ROLE_CLIENT" /> 
     <intercept-url pattern="/api/.*" access="ROLE_USER" /> 
     <access-denied-handler ref="oauthAccessDeniedHandler" /> 
     <expression-handler ref="oauthWebExpressionHandler" /> 
    </http> 

    <bean id="oauthAuthenticationEntryPoint" class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint"> 
     <property name="realmName" value="qeep" /> 
    </bean> 

    <bean id="clientAuthenticationEntryPoint" class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint"> 
     <property name="realmName" value="qeep/client" /> 
    </bean> 

    <bean id="oauthAccessDeniedHandler" class="org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler" />  

    <authentication-manager alias="authenticationManager" xmlns="http://www.springframework.org/schema/security"> 
     <authentication-provider user-service-ref="qeepUserDetailsService" /> 
    </authentication-manager> 

    <bean id="myUserDetailsService" class="com.example.core.web.rest.auth.QeepUserDetailsService"/> 

    <bean id="tokenStore" class="com.example.core.web.rest.auth.QeepTokenStore" /> 

    <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="clientDetails" /> 
    </bean> 

    <authentication-manager id="clientAuthenticationManager" xmlns="http://www.springframework.org/schema/security"> 
     <authentication-provider user-service-ref="clientDetailsUserService" /> 
    </authentication-manager> 

    <bean id="clientDetailsUserService" class="org.springframework.security.oauth2.provider.client.ClientDetailsUserDetailsService"> 
     <constructor-arg ref="clientDetails" /> 
    </bean> 

    <bean id="clientCredentialsTokenEndpointFilter" class="org.springframework.security.oauth2.provider.client.ClientCredentialsTokenEndpointFilter"> 
     <property name="authenticationManager" ref="clientAuthenticationManager" /> 
    </bean>     

    <oauth:client-details-service id="clientDetails"> 
     <oauth:client client-id="my-trusted-client-with-secret" authorized-grant-types="password,authorization_code,refresh_token,implicit" 
        secret="somesecret" authorities="ROLE_CLIENT, ROLE_TRUSTED_CLIENT" /> 
    </oauth:client-details-service> 

    <oauth:authorization-server client-details-service-ref="clientDetails" token-services-ref="tokenServices"> 
     <oauth:authorization-code /> 
     <oauth:implicit /> 
     <oauth:refresh-token /> 
     <oauth:client-credentials /> 
     <oauth:password /> 
    </oauth:authorization-server> 

    <sec:global-method-security pre-post-annotations="enabled" proxy-target-class="true"> 
     <!--you could also wire in the expression handler up at the layer of the http filters. See https://jira.springsource.org/browse/SEC-1452 --> 
    <sec:expression-handler ref="oauthExpressionHandler" /> 
    </sec:global-method-security> 

    <oauth:expression-handler id="oauthExpressionHandler" /> 

    <oauth:web-expression-handler id="oauthWebExpressionHandler" /> 
</beans> 

나는 컬을 사용하여 /oauth/token에 액세스하는 경우, 내가 구성된 클라이언트 자격 증명을 사용하여 통과 클라이언트 인증 요청을 얻을 수있을 것입니다. 그러나이 후에 /oauth/token404 - Not found만을 반환합니다. 나는 지난 시간 동안 다른 일을 시도하지 않았다.

나는 우리가 아직 봄 3.2에 있기 때문에 내가 사용한 oauth2 1.0.5의 sparklr/tonr 샘플에서 구성을 추출했다.

동일한 테스트가 sparklr-Sample-webapp에서 제대로 작동합니다.

편집

실제 컬 URL이 다음과 같다 : 내가 구성된 클라이언트 인증을 요구하는 (401)를 얻을 권한 부여 헤더없이

curl -v -H "Authorization: Basic bXktdHJ1c3RlZC1jbGllbnQtd2l0aC1zZWNyZXQ6c29tZXNlY3JldA==" "http://localhost:8084/core/oauth/token" 

("내 신뢰 - 클라이언트 - with-secret "및"somesecret ")하지만 권한 부여 헤더가 추가되어 방금 404가 표시됩니다. 필자가 sparklr-Sample을 테스트 할 때 위와 같은 Basic-Auth-Header를 추가 한 후에 grant-type을 묻는 중 오류가 발생합니다.

조금 더 명확하게되기를 바랍니다.

내 구성에 어떤 문제가 있습니까?

+0

나는 따라 가지 않습니다. 당신은 어떻게 컬을 할 수 있고 그것이 작동하면 404를 얻게됩니까? 우리가 한 일과 실패한 일에 대해 좀 더 자세한 설명이 필요하다고 생각합니다. 어쩌면 실제 컬 명령 (문제가있는 경우)? –

+0

위의 편집을 참조하십시오. – HefferWolf

+1

'DispatcherServlet'은 어떻게 매핑 되나요 (web.xml)? –

답변

0

DispatcherServlet이 잘못된 URL로 매핑되었으므로 먼저 문제를 해결하는 동안 문제가 발생했습니다. Dispatcher-Servlet은 core/api에 매핑되고 토큰 서비스는 처음에 core/api/oauth/token으로 매핑되었으며 나중에 core/oauth/token으로 변경되었지만 DispatcherServlet을 변경하는 것을 잊었습니다. 고마워, 데이브는 힌트를!