我想在我的JSF 2.2页面中实现这个示例https://github.com/hakdogan/ApacheShiro。
我已添加到我的登录页面f:event
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:a="http://xmlns.jcp.org/jsf/passthrough"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:metadata>
<f:event type="javax.faces.event.PreRenderViewEvent" listener="#{loginController.authorizedUserControl}"/>
</f:metadata>
<h:head>
........
</h:head>
重定向方法:
public void authorizedUserControl(){
if(null != SecurityUtils.getSubject().getPrincipal()){
NavigationHandler nh = FacesContext.getCurrentInstance().getApplication().getNavigationHandler();
nh.handleNavigation(FacesContext.getCurrentInstance(), null, "/member/index.xhtml?faces-redirect=true");
}
}
当我打开页面时,我得到了:
The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
This problem can sometimes be caused by disabling or refusing to accept cookies.
我如何解决这个问题?
shiro.ini文件
[main]
authc.loginUrl = /authentication/login.xhtml
user.loginUrl = /authentication/login.xhtml
dataSource = org.apache.shiro.jndi.JndiObjectFactory
dataSource.resourceName = jdbc/DefaultDB
dataSource.resourceRef = true
jdbcRealm = com.crm.web.authentication.JdbcRealm
jdbcRealm.dataSource = $dataSource
jdbcRealm.permissionsLookupEnabled = true
securityManager.realm = $jdbcRealm
passwordMatcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher
credentialsMatcher = org.apache.shiro.authc.credential.HashedCredentialsMatcher
credentialsMatcher.hashAlgorithmName = SHA-256
credentialsMatcher.storedCredentialsHexEncoded = true
credentialsMatcher.hashIterations = 5000
multipleroles = com.crm.web.authentication.MultipleRolesAuthorizationFilter
[users]
;admin = password
[urls]
/authentication/login.xhtml = authc
/authentication/passwordreset.xhtml = anon
/javax.faces.resource/** = anon
/** = authc