Всем доброго времени суток.
Прошу не пинать если вопрос глупый и не смог найти ответа на форме.
Суть такова, создал небольшое приложение с использованием IceFaces, после этого решил прикрутить Spring-Security.
Взял за основу статью
http://facestutorials.icefaces.org/tutorial/spring-security-basic.html.
Всё хорошо, авторизация проходит успешно, выход тоже срабатывает, но когда происходит Session-timeuot, то ни одна кнопка не работает, приложение как будто зависает.
Если не подключать Spring-Security то после Session-timeuot, приложение успешно переход на страницу с текстом "Ваша сессия истекла" согласно параметру в wed.xml
1.
2.
3.
4.
<context-param>
<param-name>org.icefaces.sessionExpiredRedirectURI</param-name>
<param-value>/public/sessionExpired.xhtml</param-value>
</context-param>
Но когда Spring-Security подключён ни на одно нажатие на кнопку не реагирует приложение, помогает только обновление.
Приложение запускаю под Томкат 7
Далее привожу настоечные файлы
web.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.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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"
version="3.0">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<!-- ICEfaces will gzip compress most static resource responses -->
<context-param>
<param-name>org.icefaces.compressResources</param-name>
<param-value>false</param-value>
</context-param>
<!-- More efficient, in an AJAX environment, to have server side state saving -->
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<!-- HTML comments become components unless they're stripped -->
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.VALIDATE_EMPTY_FIELDS</param-name>
<param-value>false</param-value>
</context-param>
<!-- If you're using ice:gmap component, you'll need your own key here -->
<context-param>
<param-name>com.icesoft.faces.gmapKey</param-name>
<param-value>ABQIAAAADlu0ZiSTam64EKaCQr9eTRTOTuQNzJNXRlYRLknj4cQ89tFfpxTEqxQnVWL4k55OPICgF5_SOZE06A
</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.uploadDirectory</param-name>
<param-value>upload</param-value>
</context-param>
<context-param>
<param-name>org.icefaces.windowScopeExpiration</param-name>
<param-value>1500</param-value>
</context-param>
<context-param>
<param-name>org.icefaces.sessionExpiredRedirectURI</param-name>
<!--<param-value>/pages/sessionExpired.xhtml</param-value>-->
<param-value>/public/sessionExpired.xhtml</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.validateXml</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.verifyObjects</param-name>
<param-value>false</param-value>
</context-param>
<!-- Special Debug Output for Development -->
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
<url-pattern>/icefaces/*</url-pattern>
</servlet-mapping>
<!-- Many of the ICEfaces Components make use of the Resource Servlet -->
<servlet>
<servlet-name>Resource Servlet</servlet-name>
<servlet-class>com.icesoft.faces.webapp.CompatResourceServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- This specific mapping is necessary for the Resource Servlet to function properly -->
<servlet-mapping>
<servlet-name>Resource Servlet</servlet-name>
<url-pattern>/xmlhttp/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>com.icesoft.faces.concurrentDOMViews</param-name>
<param-value>false</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<session-config>
<session-timeout>1</session-timeout>
</session-config>
<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>
</web-app>
pom.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.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
<dependencies>
<dependency>
<groupId>org.icefaces</groupId>
<artifactId>icefaces</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.icefaces</groupId>
<artifactId>icefaces-ace</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.icefaces</groupId>
<artifactId>icefaces-compat</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.18</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>2.0.4</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core-tiger</artifactId>
<version>2.0.4</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>2.0.4</version>
</dependency>
</dependencies>
faces-config.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.
<?xml version='1.0' encoding='UTF-8'?>
<faces-config 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-facesconfig_2_0.xsd"
version="2.0"
metadata-complete="false">
<application>
<locale-config>
<default-locale>ru</default-locale>
<supported-locale>ru</supported-locale>
<supported-locale>en</supported-locale>
</locale-config>
<resource-bundle>
<base-name>messages</base-name>
<var>msgs</var>
</resource-bundle>
</application>
<managed-bean>
<managed-bean-name>loginBean</managed-bean-name>
<managed-bean-class>ru.exam.bean.security.LoginBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>*</from-view-id>
<navigation-case>
<from-outcome>login</from-outcome>
<to-view-id>/public/login.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
applicationContext.xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
<?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:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.2.xsd">
<security:http auto-config="true" access-denied-page="/accessDenied.xhtml">
<security:intercept-url pattern="/examiner/**" access="ROLE_ALLACCESS, ROLE_URLACCESS"/>
<security:form-login login-page="/public/login.xhtml"
default-target-url="/examiner/pages/content.xhtml" always-use-default-target="true"/>
<security:concurrent-session-control max-sessions="1" expired-url="/public/login.xhtml"/>
<security:logout logout-success-url="/public/login.xhtml"/>
</security:http>
<security:authentication-provider user-service-ref="userDetailsService"/>
<bean id="userDetailsService" class="ru.exam.bean.security.UserDetailsServiceImpl">
<constructor-arg ref="userRepository"/>
</bean>
<bean id="userRepository" class="ru.exam.bean.security.UserDaoImpl"/>
</beans>
login.xhtml
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.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:ace="http://www.icefaces.org/icefaces/components"
xmlns:ice="http://www.icesoft.com/icefaces/component"
template="templates/main.xhtml"
>
<ui:define name="body">
<ice:form id="id_login_form">
<ice:panelGrid columns="2" border="0">
<ice:panelGrid columns="1" border="0" cellpadding="0" cellspacing="0">
<ice:graphicImage value="/public/resources/images/lock.gif" style="border:none; margin-left:25px; margin-right:15px;"/>
</ice:panelGrid>
<ice:panelGrid columns="1" border="0" width="100%">
<ice:panelGrid columns="1" border="0" cellpadding="0" cellspacing="0">
<ice:outputText style="margin-left:0px; margin-right:5px; color:#3366FF; font-size: 12pt; font-weight:bold;" id="id_login_auth_desc" value="Авторизация"/><br/>
</ice:panelGrid>
<ice:panelGrid columns="2" border="0" cellpadding="0" cellspacing="0">
<ice:outputText style="margin-left:5; margin-right:17px; color:#3366FF;" id="id_login_user_desc" value="Логин"/>
<ice:inputText id="j_username" value="#{loginBean.userId}" style="width: 115px" />
</ice:panelGrid>
<ice:panelGrid columns="2" border="0" cellpadding="0" cellspacing="0">
<ice:outputText style="margin-left:5; margin-right:7px; color:#3366FF;" id="id_login_pswd_desc" value="Пароль"/>
<ice:inputSecret id="j_password" value="#{loginBean.password}" style="width: 115px" />
</ice:panelGrid>
<ice:panelGrid columns="1" border="0" cellpadding="0" cellspacing="0">
<ice:commandButton id="id_login_enter_button" value="Войти" actionListener="#{loginBean.login}" style="margin-top:10px; margin-left:52px; width: 65px;" />
</ice:panelGrid>
</ice:panelGrid>
</ice:panelGrid>
</ice:form>
</ui:define>
</ui:composition>
LoginBean.java
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.
public class LoginBean {
// properties
private String userId;
private String password;
/**
* default empty constructor
*/
public LoginBean() {
Exception ex = (Exception) FacesContext
.getCurrentInstance()
.getExternalContext()
.getSessionMap()
.get(AbstractProcessingFilter.SPRING_SECURITY_LAST_EXCEPTION_KEY);
if (ex != null)
FacesContext.getCurrentInstance().addMessage(
null,
new FacesMessage(FacesMessage.SEVERITY_ERROR, ex
.getMessage(), ex.getMessage()));
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public void login(ActionEvent e) throws java.io.IOException {
FacesContext.getCurrentInstance().getExternalContext().redirect("/spring-authentication/j_spring_security_check?j_username=" + userId + "&j_password=" + password);
//FacesContext.getCurrentInstance().getExternalContext().redirect("/j_spring_security_check?j_username=" + userId + "&j_password=" + password);
}
public void logout(ActionEvent e) throws java.io.IOException {
FacesContext.getCurrentInstance().getExternalContext().redirect("/spring-authentication/j_spring_security_logout");
}
}
UserDetailsServiceImpl.java
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.
public class UserDetailsServiceImpl implements UserDetailsService {
private UserDao userDao;
public UserDetailsServiceImpl(UserDao userDao) {
this.userDao = userDao;
}
public UserDetails loadUserByUsername(String username)
throws UsernameNotFoundException, DataAccessException {
AppUser user = userDao.findUser(username);
if (user == null)
throw new UsernameNotFoundException("User not found: " + username);
else {
return makeUser(user);
}
}
private org.springframework.security.userdetails.User makeUser(AppUser user) {
return new org.springframework.security.userdetails.User(user.getLogin(), user
.getPassword(), true, true, true, true,
makeGrantedAuthorities(user));
}
private GrantedAuthority[] makeGrantedAuthorities(AppUser user) {
GrantedAuthority[] result = new GrantedAuthority[user.getRoles().size()];
int i = 0;
for (String role : user.getRoles()) {
result[i++] = new GrantedAuthorityImpl(role);
}
return result;
}
}
UserDaoImpl.java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
public class UserDaoImpl implements UserDao {
public AppUser findUser(String userName) {
AppUser appUser = null;
Set<String> roles = new HashSet<String>();
if (userName.equals("john")) {
roles.add("ROLE_URLACCESS");
appUser = new AppUser("john", "John", "Turner", "john", roles);
} else if (userName.equals("jim")) {
appUser = new AppUser("jim", "Jim", "Daniel", "jim", roles);
} else if (userName.equals("tina")) {
roles.add("ROLE_ALLACCESS");
appUser = new AppUser("tina", "Tina", "Joseph", "tina", roles);
} else if (userName.equals("admin")) {
roles.add("ROLE_ALLACCESS");
appUser = new AppUser("admin", "Tina", "Joseph", "admin", roles);
}
return appUser;
}
}
Прошу прошения, если получился длинный пост, но хотелось дать более полную информацию.
Используется Spring-Security 2, Icefaces 3
Прошу помощи решить проблему редиректа на страницу логина по истечении сессии, в трайсе ошибок ни каких нет.
Заранее спасибо.