powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Java [игнор отключен] [закрыт для гостей] / spring Security
7 сообщений из 7, страница 1 из 1
spring Security
    #38945020
goldenhawk
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Пытаюсь в проект добавить spring Security

Начальная страница reg.html с вводом имени, далее buy.html, order.html

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.
<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app version="2.5" 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_2_5.xsd">

	<display-name>Archetype Created Web Application</display-name>

	<servlet>
		<servlet-name>OnlineShopServlet</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>/WEB-INF/spring-config.xml</param-value>
		</init-param>
	</servlet>

	<servlet-mapping>
		<servlet-name>OnlineShopServlet</servlet-name>
		<url-pattern>*.html</url-pattern>
	</servlet-mapping>

	<welcome-file-list>
		<welcome-file>reg.html</welcome-file>

	</welcome-file-list>
	<error-page>
		<error-code>404</error-code>
		<location>/404.jsp</location>
	</error-page>

<!-- Spring Security -->
<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>


 	<session-config>
		<session-timeout>5</session-timeout>
	</session-config>

</web-app>



security.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.
<beans:beans xmlns="http://www.springframework.org/schema/security"          
      xmlns:beans="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://www.springframework.org/schema/beans 
                 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
                 http://www.springframework.org/schema/security 
                 http://www.springframework.org/schema/security/spring-security-3.0.xsd"> 

  
<http access-denied-page="/error.jsp"> 
   <intercept-url pattern="/reg*" access="ROLE_USER,ROLE_ADMIN"/> 
   <intercept-url pattern="/buy*" access="ROLE_ADMIN,ROLE_USER"/> 
   <intercept-url pattern="/order*" access="ROLE_ADMIN"/> 
   <form-login login-page="/reg.html" default-target-url="/reg" authentication-failure-url="/reg.jsp?error=true"/> 
   <logout logout-url="/logout" logout-success-url="/index"/> 
   <anonymous username="guest" granted-authority="ROLE_ANONYMOUS"/> 
   <remember-me/> 
</http> 
  
<authentication-manager> 
   <authentication-provider> 
      <user-service> 
         <user name="admin"  authorities="ROLE_ADMIN"/> 
         <user name="user1"  authorities="ROLE_USER"/> 
         <user name="user2"  disabled="true" authorities="ROLE_USER"/>    
      </user-service> 
   </authentication-provider> 
</authentication-manager> 
</beans:beans> 



в pom.xml

Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-web</artifactId>
    <version>3.2.5.RELEASE</version>
  </dependency>
  <dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-config</artifactId>
    <version>3.2.5.RELEASE</version>
  </dependency>




При запуске вылетает

java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered?
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:251)
...
Рейтинг: 0 / 0
spring Security
    #38945022
Фотография Blazkowicz
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
...
Рейтинг: 0 / 0
spring Security
    #38945034
goldenhawk
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Blazkowicz http://stackoverflow.com/a/8924825
добавил <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

теперь

org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
...
Рейтинг: 0 / 0
spring Security
    #38945036
Фотография Blazkowicz
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Ну, так XML нужен чтобы спринговый контекст создать. Для сервлета вон прописан, а для контекста указан?
...
Рейтинг: 0 / 0
spring Security
    #38945041
goldenhawk
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Blazkowicz,
Что в нем прописать? В контексте?
...
Рейтинг: 0 / 0
spring Security
    #38945051
goldenhawk
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
BlazkowiczНу, так XML нужен чтобы спринговый контекст создать. Для сервлета вон прописан, а для контекста указан?
Делал по этому примеру http://habrahabr.ru/post/203318/
...
Рейтинг: 0 / 0
spring Security
    #38945072
goldenhawk
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
переделал
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.
53.
54.
55.
56.
57.
58.
<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app version="2.5" 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_2_5.xsd">

	<display-name>Archetype Created Web Application</display-name>

	<servlet>
		<servlet-name>OnlineShopServlet</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>/WEB-INF/spring-config.xml</param-value>
		</init-param>
	</servlet>

	<servlet-mapping>
		<servlet-name>OnlineShopServlet</servlet-name>
		<url-pattern>*.html</url-pattern>
	</servlet-mapping>

	<welcome-file-list>
		<welcome-file>reg.html</welcome-file>

	</welcome-file-list>
	<error-page>
		<error-code>404</error-code>
		<location>/404.jsp</location>
	</error-page>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
  <!-- Spring Security -->  
<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>
<context-param>
	<param-name>contextConfigLocation</param-name>
	<param-value>
		/WEB-INF/application-security.xml
	</param-value>
</context-param>

 	<session-config>
		<session-timeout>5</session-timeout>
	</session-config>

</web-app>



application-securety.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.
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
	xmlns:beans="http://www.springframework.org/schema/beans" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
                    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                    http://www.springframework.org/schema/security 
                    http://www.springframework.org/schema/security/spring-security-3.2.xsd">
	
	
	<http auto-config="true">
		<intercept-url pattern="/order/**" access="ROLE_ADMIN" />
 		<intercept-url pattern="/buy/**" access="ROLE_ADMIN,ROLE_USER" /> 
	</http>	
<http pattern="/reg/**" security="none" />
	<authentication-manager>
		<authentication-provider>
			<user-service>
				<user name="admin"   authorities="ROLE_ADMIN" />
				<user name="user"   authorities="ROLE_USER" />
			</user-service>
		</authentication-provider>
	</authentication-manager>
</beans:beans> 




Выдает исключение

SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChainProxy': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: A universal match pattern ('/**') is defined before other patterns in the filter chain, causing them to be ignored. Please check the ordering in your <security:http> namespace or FilterChainProxy bean configuration


Не могу понять как сделать это.
...
Рейтинг: 0 / 0
7 сообщений из 7, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / spring Security
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]