Здравствуйте!
Пишу authentication для rest приложения. Использую Spring Security 4. Сейчас застрял на том, что не могу нормально настроить security. Вот, что имеется сейчас:
applicationContext.xml
Кликните здесь для просмотра всего текста
XML |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
| <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sec="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans [url]http://www.springframework.org/schema/beans/spring-beans-4.0.xsd[/url]
[url]http://www.springframework.org/schema/security[/url] http://www.springframework.org/schema/security/spring-security.xsd">
<import resource="classpath*:securityServicesContext.xml"/>
<import resource="classpath*:businessServicesContext.xml"/>
<sec:http pattern="/rest/**" create-session="stateless" auto-config="false" entry-point-ref="unauthorizedEntryPoint">
<sec:expression-handler ref="webSecurityExpressionHandler"/>
<sec:custom-filter ref="customTokenAuthenticationFilter" position="FORM_LOGIN_FILTER"/>
<sec:intercept-url pattern="/rest/login" access="permitAll"/>
<sec:intercept-url pattern="/**" access="hasRole('USER')"/>
<sec:csrf disabled="true"/>
</sec:http>
<sec:authentication-manager id="authenticationManager">
<sec:authentication-provider ref="daoAuthenticationProvider"/>
</sec:authentication-manager>
<bean id="unauthorizedEntryPoint" class="com.itechart.security.web.security.UnauthorizedEntryPoint"/>
<bean id="customTokenAuthenticationFilter"
class="com.itechart.security.web.security.CustomTokenAuthenticationFilter">
<constructor-arg name="defaultFilterProcessesUrl" value="/rest/**"/>
<constructor-arg name="authenticationManager" ref="authenticationManager"/>
<constructor-arg name="authenticationSuccessHandler">
<bean class="com.itechart.security.web.security.TokenSimpleUrlAuthenticationSuccessHandler"/>
</constructor-arg>
</bean>
</beans> |
|
web.xml
Кликните здесь для просмотра всего текста
XML |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
| <?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>Security Web Application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcherServlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<resource-ref>
<res-ref-name>jdbc/SecuritySampleDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<welcome-file-list>
<welcome-file>/app/index.html</welcome-file>
</welcome-file-list>
</web-app> |
|
Получается, что когда я отправляю username&password на /rest/login, то попадаю в CustomTokenAuthenticationFilter, а мне это не нужно, так как по этому url я должен поучить token и все. А все остальные urls должны фильтроваться как положено.
Как это сделать?
Заранее спс!