Sau khi đăng nhập thành công, nó không chuyển hướng đến "index.php". Nó chuyển hướng cùng một trang đó là "login.php". Có điều gì sai với trang spring-security.xml của tôi không?Chuyển hướng bảo mật mùa xuân sau khi đăng nhập
Nhân tiện khi tôi chạy ứng dụng, nó chuyển hướng tôi đến "login.php" rất tốt. Nhưng nó không hiển thị các thành phần của thủ công mà là các thành phần html. Sau khi tôi đăng nhập thành công, Nó chuyển hướng cùng một trang nhưng lần này Nó hiển thị các thành phần Primefaces thay vì các thành phần html.
<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.2.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/pages/login.xhtml*" access="permitAll"/>
<intercept-url pattern="/**" access="hasRole('admin')" />
<form-login login-page='/pages/login.xhtml' default-target-url="/pages/index.xhtml"
authentication-failure-url="/pages/login.xhtml"/>
<logout logout-success-url="/pages/logout.xhtml" />
</http>
<!--Authentication Manager Details -->
<authentication-manager alias="authenticationManager">
<authentication-provider user-service-ref="customUserDetailsService">
<!-- <password-encoder hash="md5"/>-->
</authentication-provider>
</authentication-manager>
web.xml của tôi
<welcome-file-list>
<welcome-file>pages/index.xhtml</welcome-file>
</welcome-file-list>
trang đăng nhập của tôi
<p:outputPanel id="loginOutputPanelId" style="border: navy">
<p:panelGrid id="loginInformationPanel" columns="2">
<h:outputText value="Username: "/>
<p:inputText value="#{loginController.userName}"/>
<h:outputText value="Password: "/>
<p:inputText value="#{loginController.password}"/>
</p:panelGrid>
<p:commandButton value="Login" actionListener="#{loginController.login()}"/>
</p:outputPanel>
loginController.login của tôi() phương pháp lợi nhuận "chỉ số" chuỗi và faces.config của tôi;
<navigation-rule>
<from-view-id>/pages/login.xhtml</from-view-id>
<navigation-case>
<from-outcome>index</from-outcome>
<to-view-id>/pages/index.xhtml</to-view-id>
<redirect />
</navigation-case>
</navigation-rule>
EDIT: không có yếu tố nó chạy mà không cần bất kỳ vấn đề. Khi tôi thêm hình thức đăng nhập nó nói "Trang web tại http://localhost:8080/myApplication/pages/login.xhtml
đã dẫn đến quá nhiều chuyển hướng".
<http auto-config='true' use-expressions="true">
<intercept-url pattern="/**" access="hasRole('admin')" />
<logout logout-success-url="/pages/logout.xhtml" />
<form-login login-page="/pages/login.xhtml"
login-processing-url="/j_spring_security_check"
default-target-url="/pages/index.xhtml"
authentication-failure-url="/pages/login.xhtml"/>
</http>
trang đăng nhập của tôi
<p:outputPanel id="loginOutputPanelId" style="border: navy">
<p:panelGrid id="loginInformationPanel" columns="2">
<h:outputText value="Kullanıcı Adı: "/>
<p:inputText id="j_username" required="true" value="#{loginController.userName}"/>
<h:outputText value="Şifre: "/>
<p:inputText id="j_password" required="true" value="#{loginController.password}"/>
</p:panelGrid>
<p:commandButton id="login" type="submit" ajax="false" value="Login" actionListener="#{loginController.login()}"/>
</p:outputPanel>
loginController.login mới của tôi() phương pháp;
ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
RequestDispatcher dispatcher = ((ServletRequest) context.getRequest())
.getRequestDispatcher("/j_spring_security_check");
dispatcher.forward((ServletRequest) context.getRequest(),
(ServletResponse) context.getResponse());
FacesContext.getCurrentInstance().responseComplete();
Tuy nhiên cùng. Nó không thay đổi gì cả. –
url đầu tiên bạn gọi là gì? Bạn có gọi trực tiếp trang đăng nhập hoặc bạn gọi một url được bảo mật khác không? – baraber
index.xhtml là tệp chào mừng của tôi được xác định trong "web.xml". Tôi không hiểu ý bạn là gì. Có login-page = '/ pages/login.xhtml' tại spring-security.xml và bảo mật mùa xuân đầu tiên gọi login.xhtml. sau khi tôi thêm dòng luôn sử dụng-mặc định-target = "true", bây giờ nó không chuyển hướng bất kỳ trang nào. Nó vẫn ở trang login.xhtml. Sau đó, tôi viết địa chỉ chỉ mục theo cách thủ công để giải quyết thanh trình duyệt. –