2015-05-23 3 views
-1

Моя проблема в том, когда вы хотите запросить некоторые страницы, login.xhtml не открывается для аутентификации пользователя.Ошибка учетной записи безопасности безопасности jsf

Вот security-config.xml:

<?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.xsd 
     http://www.springframework.org/schema/security 
     http://www.springframework.org/schema/security/spring-security.xsd"> 

    <security:http auto-config="false" use-expressions="true"> 
     <security:csrf disabled="true"/> 
     <security:intercept-url pattern="/faces/login2.xhtml" access="IS_AUTHENTICATED_ANONYMOUSLY"/> 

     <security:intercept-url pattern="/faces/MyCard.xhtml" access="hasRole('ROLE_USER')"/> 
     <security:form-login login-page="/faces/login2.xhtml" default-target-url="/Home.xhtml" 
          authentication-failure-url="/faces/login2.xhtml?error=1" login-processing-url="/j_spring_security_check"/> 

    </security:http> 

    <security:authentication-manager> 
     <security:authentication-provider> 
      <security:user-service> 
       <security:user name="sajjad" authorities="ROLE_USER" password="ssss"/> 
      </security:user-service> 
     </security:authentication-provider> 
    </security:authentication-manager> 
</beans> 

И это web.xml:

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>/WEB-INF/applicationContext.xml 
     /WEB-INF/security-config.xml 
    </param-value> 
</context-param> 

<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 


<!-- SPRING SECURITY RELATED CONFIG--> 
<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> 
    <dispatcher>FORWARD</dispatcher> 
    <dispatcher>REQUEST</dispatcher> 
</filter-mapping> 

И это login bean:

@ManagedBean 
@SessionScoped 
public class LoginBean { 

private String username; 
private String password; 

public String login() throws IOException, ServletException { 
    FacesContext context = FacesContext.getCurrentInstance(); 
    ExternalContext externalContext = context.getExternalContext(); 

    RequestDispatcher dispatcher = ((ServletRequest) externalContext.getRequest()) 
      .getRequestDispatcher("/j_spring_security_check?j_username=" + username 
        + "&j_password=" + password); 

    dispatcher.forward((ServletRequest) externalContext.getRequest(), (ServletResponse) externalContext.getResponse()); 
    context.responseComplete(); 
    return null; 
} 
//getter/setters 

ответ

0

Кажется, вы не precising право имя учетной записи в файле конфигурации. Это login не login2:

<security:http auto-config="false" use-expressions="true"> 
    ... 
    <security:form-login login-page="/faces/login.xhtml" default-target-url="/Home.xhtml" 
    ... 
</security:http> 

Если он не работает, опускаем .xhtml, иначе держать только "login" для атрибута Логин-страницы.

Смежные вопросы