Nur mit dieser für ein paar Tage zu kämpfen, aber es hat arbeitet jetzt an neuesten Frühling OAuth2 1.0.5 .FREISETZUNG. Ich bin nicht 100% sicher, dass meine Lösung die Klasse ist (Schritt 4 im Besonderen), aber es funktioniert und ich kann weitermachen.
In meinem Fall wollte ich das /oauth
Präfix von den URLs entfernen, um nur mit /token
und /authorize
enden. Die Lösung für mich war hauptsächlich xml config, mit zwei Hacks, um die Anforderungszuordnungen zu überschreiben.
1 - Fügen Sie in App context xml authorization-endpoint-url
und token-endpoint-url
Ihrem Element <oauth:authorization-server>
hinzu.
Mine:
<oauth:authorization-server client-details-service-ref="clientDetailsService" token-services-ref="tokenServices" user-approval-handler-ref="userApprovalHandler" authorization-endpoint-url="/authorize" token-endpoint-url="/token">
2 - In App Kontext xml, entsprechend der Sicherheitsendpunkte einzustellen. Es sollte zwei geben, die jeweils die Sicherheit auf dem Token und den Authentifizierungen verwalten. Müssen die Musterstütze auf <http>
und <intercept-url>
Tags aktualisieren.
Mine:
<http pattern="/token/**" create-session="stateless" authentication-manager-ref="clientAuthenticationManager" xmlns="http://www.springframework.org/schema/security">
<intercept-url pattern="/token/**" access="IS_AUTHENTICATED_FULLY" />
...
<http pattern="/authorize/**" access-denied-page="/login.jsp?authorization_error=true" disable-url-rewriting="true" xmlns="http://www.springframework.org/schema/security">
<intercept-url pattern="/authorize/**" access="IS_AUTHENTICATED_FULLY" />
3 - (Wenn Sie die optionalen clientCreds Filter verwenden gewählt haben.) In App Kontext xml, sollten Sie bereits verdrahtet in haben die clientCredentialsTokenEndpointFilter
Bohne als <custom-filter> within your
element. So, within the filter's bean, add a
filterProcessesUrl` Eigenschaft.
Mine:
<bean id="clientCredentialsTokenEndpointFilter" class="org.springframework.security.oauth2.provider.client.ClientCredentialsTokenEndpointFilter">
<property name="authenticationManager" ref="clientAuthenticationManager" />
<property name="filterProcessesUrl" value="/token" />
</bean>
4 - Der letzte Schritt ist die Anforderungszuordnung URLs der tatsächlichen internen Endpunkt-Controller zu überschreiben. Der Frühling oauth2 Lib kommt mit zwei Klassen: AuthorizationEndpoint
und TokenEndpoint
. Jeder verwendet @RequestMapping
Typ Anmerkungen, um die URL zu binden (wie wir alle für die App-Controller unserer Projekte tun). Für mich war es eine haarsträubende Bemühung, den Wert der Anforderungszuordnungen auf irgendeine andere Weise außer dem (leider) neu zu erstellen, das Spring-Klassenpaket in meinem src-Ordner zu kopieren, die AuthorizationEndpoint- und TokenEndpoint-Klassen wörtlich in diesen Ordner zu kopieren. und bearbeiten Sie die Inline-@RequestMapping
Annotationswerte.
Wie auch immer, das macht den Trick. Ich würde mich freuen, wenn Sie eine etwas elegantere Möglichkeit zum Überschreiben der Anforderungszuordnungswerte für Endpoint Controller hören könnten.
Danke.
Finale, Arbeits app Kontext:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:sec="http://www.springframework.org/schema/security" xmlns:oauth="http://www.springframework.org/schema/security/oauth2"
xsi:schemaLocation="
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd
http://www.springframework.org/schema/security/oauth2 http://www.springframework.org/schema/security/spring-security-oauth2.xsd
"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
<!-- Declare OAuth2 services white-list. (This is the top of the config.) -->
<oauth:authorization-server client-details-service-ref="clientDetailsService" token-services-ref="tokenServices" user-approval-handler-ref="userApprovalHandler" authorization-endpoint-url="/authorize" token-endpoint-url="/token">
<oauth:authorization-code />
<oauth:implicit />
<oauth:refresh-token />
<oauth:client-credentials />
<!-- <oauth:password /> -->
</oauth:authorization-server>
<bean id="userApprovalHandler" class="org.springframework.security.oauth2.provider.approval.TokenServicesUserApprovalHandler">
<!-- This bean bridges client auth service and user tokens... kind of an out of place requirement. -->
<property name="tokenServices" ref="tokenServices" />
</bean>
<!-- This starts the far back-end config for client token management. -->
<sec:authentication-manager id="clientAuthenticationManager">
<sec:authentication-provider user-service-ref="clientDetailsUserService" />
</sec:authentication-manager>
<bean id="clientDetailsUserService" class="org.springframework.security.oauth2.provider.client.ClientDetailsUserDetailsService">
<constructor-arg ref="clientDetailsService" />
</bean>
<bean id="clientDetailsService" class="com.mycompany.oauth.spring.security.oauth2.IntegratedOauth2ClientDetailsService">
<!-- This bean is what wires OAuth2 into the persistence stack for client details stored in the oauth_client table. -->
</bean>
<!-- OAuth is layered on to spring security which is centered around users which requires a user auth manager. -->
<authentication-manager alias="authenticationManager" xmlns="http://www.springframework.org/schema/security">
<authentication-provider ref="daoAuthenticationProvider" />
</authentication-manager>
<bean id="daoAuthenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
<property name="userDetailsService" ref="userDetailsService" />
</bean>
<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="com.mycompany.oauth.spring.security.oauth2.IntegratedOAuth2TokenStore">
<!-- This bean is what wires OAuth2 tokens into my company's application stack. -->
<constructor-arg ref="dataSource" />
</bean>
<!-- **************************************************************************************** -->
<!-- Finally, sew OAuth into spring security with some http tags... -->
<!-- **************************************************************************************** -->
<!-- The OAuth2 endpoint for direct token requests (i.e. for client_credentials flow). -->
<http pattern="/token/**" create-session="stateless" authentication-manager-ref="clientAuthenticationManager" xmlns="http://www.springframework.org/schema/security">
<intercept-url pattern="/token/**" access="IS_AUTHENTICATED_FULLY" />
<anonymous enabled="false" />
<http-basic entry-point-ref="clientAuthenticationEntryPoint" />
<custom-filter ref="clientCredentialsTokenEndpointFilter" before="BASIC_AUTH_FILTER" />
<access-denied-handler ref="oauthAccessDeniedHandler" />
</http>
<bean id="clientCredentialsTokenEndpointFilter" class="org.springframework.security.oauth2.provider.client.ClientCredentialsTokenEndpointFilter">
<property name="authenticationManager" ref="clientAuthenticationManager" />
<property name="filterProcessesUrl" value="/token" />
</bean>
<bean id="clientAuthenticationEntryPoint" class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint">
<property name="realmName" value="myrealm" />
</bean>
<bean id="oauthAccessDeniedHandler" class="org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler" />
<!-- The OAuth2 endpoint for user-approved authorization (i.e. for "authorization" flow involving user login/approve). -->
<http pattern="/authorize/**" access-denied-page="/login.jsp?authorization_error=true" disable-url-rewriting="true" xmlns="http://www.springframework.org/schema/security">
<intercept-url pattern="/authorize/**" access="IS_AUTHENTICATED_FULLY" />
<form-login authentication-failure-url="/login.jsp?authentication_error=true" default-target-url="http://www.mycompany.com/" login-page="/login.jsp" login-processing-url="/login.do" />
<http-basic />
<anonymous />
</http>
</beans>
Hallo Anurag, ich habe alle diese Zeile hinzugefügt und meine Endzeigerreferenz auf -Tag gegeben. Beim Start des Servers wird jedoch eine Exception ausgelöst: "java.lang.IllegalArgumentException: authenticationManager muss angegeben werden". Irgendetwas anderes muss hier getan werden? .. Danke –
Srikanth
müssen Sie AuthenticationManager Bean in Ihrem clientCredentialsTokenEndpoint Filter – Imrank