내 질문과 비슷한 질문이 많았습니다. 이해하지 못하면 깨닫지 못해서야 깨닫기 시작했습니다.Homegrown 인증 필터에 시작 페이지가 표시되지 않음
인증 빈에서는 인증 성공으로 인해 일부 웹 리소스에 액세스해야하며 실패는 액세스를 "필터링"하고 현재 로그인 페이지로 리디렉션해야합니다. 나는 실패의 경우
public static final String AUTH_STATE = "";
를 다음을 수행하십시오으로 콩에 정의되어
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put(authentificationBean1.AUTH_STATE, "true") ;
AUTH_STATE : 지금, 그위한 인증 콩, 나는 성공의 경우에이 라인을 추가 :
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put(authentificationBean1.AUTH_STATE, null) ;
이제 필터 (인증 페이지를 제외한 모든 파일에 적용되는 필터)에서 내 doFilter m ethod은 다음과 같습니다
위한 인증이 잘 가면 내 생각이의 authentificationBean1.AUTH_STATE 세션 attribut가 null이 아닌 값으로 설정 될 것을public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException {
if (((HttpServletRequest) request).getSession().getAttribute(authentificationBean1.AUTH_STATE) == null) {
((HttpServletResponse) response).sendRedirect("authentification.xhtml");
}
if(((HttpServletRequest) request).getSession().getAttribute(authentificationBean1.AUTH_STATE) != null) {
((HttpServletResponse) response).sendRedirect("accueil.xhtml");
}
}
, 따라서 필터 테스트에서 내가로 리디렉션 할 수 있습니다 웰컴 페이지 (accueil.xhtml); 해당 속성이 null 인 경우 인증 페이지에 머물러 있습니다.
모든 것을 맛보기 : 필터가 작동하는 것처럼 보이지만 인증 테스트가 성공해야하는 경우에도 환영 페이지로 넘어 가지 않습니다. 실제로 필터 없이는 제대로 작동했지만, JSF로 필터를 사용하거나 필터로 사용하지 못하는 것 같습니다.
P.S : 다른 필터를 호출 할 필요가 없기 때문에 chain.doFilter가 적용되지 않았지만 거기에 무엇인가 의심됩니다.
귀하의 지적에 감사드립니다.
편집 :
<filter>
<filter-name>RestrictionFilter</filter-name>
<filter-class>beans.RestrictionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RestrictionFilter</filter-name>
<url-pattern>/faces/accueil.xhtml</url-pattern>
</filter-mapping>
web.xml을 게시 할 수 있습니까? – dratewka
(늦어서 죄송합니다.) 처음 게시물을 수정하겠습니다. – Akheloes
몇 가지 System.out을 만들었습니다. ** AUTH_STATE **가 null 인 경우 계정에 반영되지 않습니다. 그렇지 않으면 필터가 othercase에서 작동합니다 (** AUTH_STATE **가 null이 아닙니다. – Akheloes