2015-12-30 7 views
5

मेरे पास एक स्प्रिंग सुरक्षा OAuth2 आधारित रीस्टफुल एप्लिकेशन है। मैं एक्सएमएल से JSON तक डिफ़ॉल्ट स्प्रिंग सुरक्षा संदेश प्रारूपों को बदलने की कोशिश कर रहा हूं और ऐसा करने में आंशिक रूप से सफल रहा हूं।वसंत सुरक्षा OAuth2 जेएसओएन त्रुटि प्रतिक्रिया प्रारूप बदलें

उदाहरण के लिए - मैं पता लगा प्रतिक्रिया स्वरूप बदलने के लिए कैसे जब अनुरोध बियरर टोकन शामिल नहीं है (निम्न पंक्ति यह होता है)

<bean id="oauthAuthenticationEntryPoint" class ="c.s.m.security.CustomAuthenticationEntryPoint" /> 

लेकिन मैं यह पता लगाने की कैसे/परिवर्तन को पकड़ने के लिए सक्षम नहीं हूँ नीचे दो वस्तुओं का प्रारूप।

  1. अमान्य टोकन सुरक्षित URL में पारित कर दिया जा रहा है, वसंत सुरक्षा वर्तमान में वापस फेंकता है। मैं इस प्रारूप को कहां बदलूं?

    {"error": "invalid_token","error_description": "Invalid access token: 144285e3-9563-420e-8ce"} 
    
  2. मैं कैसे BadCredentialsException JSON प्रारूप बदल सकता हूँ? वर्तमान में यह उपरोक्त के समान JSON लौटाता है?

नीचे मेरी applicationContext.xml

<sec:http pattern="/oauth/token" create-session="stateless" 
    use-expressions="true" authentication-manager-ref="authenticationManager"> 
    <sec:csrf disabled="true" /> 
    <sec:anonymous enabled="false" /> 
    <sec:http-basic entry-point-ref="clientAuthenticationEntryPoint" /> 
    <sec:custom-filter ref="clientCredentialsTokenEndpointFilter" before="BASIC_AUTH_FILTER" /> 
    <sec:access-denied-handler ref="oauthAccessDeniedHandler" /> 
</sec:http> 
<sec:authentication-manager alias="authenticationManager" 
    erase-credentials="false"> 
    <sec:authentication-provider user-service-ref="clientDetailsUserService" /> 
</sec:authentication-manager> 

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

<!-- Entry point - Entry point Filter for token server --> 

<bean id="clientAuthenticationEntryPoint" class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint"> 
    <property name="realmName" value="Oauth 2 security" /> 
    <property name="typeName" value="Basic" /> 
</bean> 

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

<!-- Oauth handler Access Denied Handler --> 

<bean id="oauthAccessDeniedHandler" class="c.s.m.security.CustomAccessDeniedHandler" /> 
    <!-- class="org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler" /> --> 

<!-- Server resource --> 

<sec:http pattern="/api/**" create-session="never" 
    entry-point-ref="oauthAuthenticationEntryPoint" use-expressions="true" > 
    <sec:csrf disabled="true" /> 
    <sec:anonymous enabled="false" /> 
    <sec:intercept-url pattern="/api/**" access="hasRole('ROLE_ADMIN')" /> 
    <sec:custom-filter ref="resourceServerFilter" 
     before="PRE_AUTH_FILTER" /> 
    <sec:access-denied-handler ref="oauthAccessDeniedHandler" /> 
</sec:http> 

<!-- Entry point resource --> 

<bean id="oauthAuthenticationEntryPoint" class ="c.s.m.security.CustomAuthenticationEntryPoint" />   

<oauth:resource-server id="resourceServerFilter" resource-id="springsec" token-services-ref="tokenServices" /> 

<bean id="tokenServices" 
    class="org.springframework.security.oauth2.provider.token.DefaultTokenServices" > 
    <property name="tokenStore" ref="tokenStore" /> 
    <property name="supportRefreshToken" value="true" /> 
    <property name="accessTokenValiditySeconds" value="300000" /> 
    <property name="clientDetailsService" ref="clientDetails" /> 
</bean>  
<bean id="tokenStore" class="org.springframework.security.oauth2.provider.token.store.JdbcTokenStore"> 
    <constructor-arg ref="dataSource" /> 
</bean> 
<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 authentication-manager-ref="userAuthenticationManager" /> 
</oauth:authorization-server> 

<sec:authentication-manager id="userAuthenticationManager"> 
    <sec:authentication-provider ref="customUserDetailsService" /> 
</sec:authentication-manager> 

उत्तर

0

अनुरोध हेडर समस्या का समाधान होगा में Accept: application/json भेजें है।

संबंधित मुद्दे