Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用JPA创建ApacheShiro授权?_Java_Jpa_Shiro - Fatal编程技术网

Java 如何使用JPA创建ApacheShiro授权?

Java 如何使用JPA创建ApacheShiro授权?,java,jpa,shiro,Java,Jpa,Shiro,我将shiro auth从本机SQL更改为JPA,并且我有一些等式。 我做了一个例子 但我有错误 [2015-12-03 08:58:33,087] Artifact ear:ear exploded: Artifact is being deployed, please wait... [2015-12-03 08:59:06,931] Artifact ear:ear exploded: Error during artifact deployment. See server log for

我将shiro auth从本机SQL更改为JPA,并且我有一些等式。 我做了一个例子

但我有错误

[2015-12-03 08:58:33,087] Artifact ear:ear exploded: Artifact is being deployed, please wait...
[2015-12-03 08:59:06,931] Artifact ear:ear exploded: Error during artifact deployment. See server log for details.
[2015-12-03 08:59:06,932] Artifact ear:ear exploded: java.io.IOException: com.sun.enterprise.admin.remote.RemoteFailureException: Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.NoClassDefFoundError: org/apache/commons/collections/FastHashMap. Please see server.log for more details.
我不了解它的工作原理。我创建了JpaAuthorizingRealm类:

public class JpaAuthorizingRealm extends AuthorizingRealm {

    public static final String REALM_NAME = "MY_REALM";
    public static final int HASH_ITERATIONS = 200;

    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(final PrincipalCollection principals) {
        Long userId = (Long) principals.fromRealm(getName()).iterator().next();
        User user = ShiroDao.me().userById(userId);
        if (user != null) {
            SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
            for (Role role : user.getRoles()) {
                info.addRole(role.getRoleName());
                for (Permission permition : user.getPermissions()) {
                    info.addStringPermission(permition.getPermission());
                }
            }
            return info;
        } else {
            return null;
        }
    }

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken authToken) throws AuthenticationException {
        UsernamePasswordToken token = (UsernamePasswordToken) authToken;
        User user = ShiroDao.me().userByname(token.getUsername());
        if (user != null) {
            return new SimpleAuthenticationInfo(user.getId(), user.getPassword(), getName());
        } else {
            return null;
        }
    }

    @Override
    @Inject
    public void setCredentialsMatcher(final CredentialsMatcher credentialsMatcher) {
        super.setCredentialsMatcher(credentialsMatcher);
    }

}
并对用户、角色和权限进行建模。在ini文件中,我注册了:

[main]
cacheManager = org.apache.shiro.cache.MemoryConstrainedCacheManager
securityManager.cacheManager = $cacheManager

# realms to be used
adRealm = myPackeg.CustomActiveDirectoryRealm
adRealm.url = ldap://myIP

noPassWordCredentialMatcher=myPackeg.CustomNoPassMatcher

userRealm=myPackeg.JpaAuthorizingRealm
userRealm.permissionsLookupEnabled=true
userRealm.credentialsMatcher=$noPassWordCredentialMatcher

authc.loginUrl = /login.xhtml
user.loginUrl = /login.xhtml
authc.successUrl  = /index.xhtml?faces-redirect=true
roles.unauthorizedUrl = /error/ErrorInsufficientPrivileges.xhtml?faces-redirect=true

securityManager.realms= $adRealm, $customSecurityRealm
authcStrategy = org.apache.shiro.authc.pam.AllSuccessfulStrategy
securityManager.authenticator.authenticationStrategy = $authcStrategy

;multipleroles = myPackeg.MultipleRolesAuthorizationFilter
multipleroles = myPackeg.MultipleRolesAuthorizationFilter

[roles]

[urls]
/javax.faces.resource/** = anon
/error/ = anon
/login.xhtml = authc
/logout = logout
#/admin/ChangePassword.xhtml= authc, roles[user]
/admin/**= authc, roles[administrator]
/reports/qcforcc_report.xhtml= authc, roles[user]
/reports/**= authc, roles[administrator]
/** = authc, roles[user]
#/** = user, multipleroles["administrator", "user"]
如果我将
JpaAuthorizingRealm extends AuthorizingRealm
更改为
JpaAuthorizingRealm extends JdbcRealm
则不会显示错误


Maby somebode知道如何使用JPA创建shiro auth吗?

这似乎更像是链接错误,而不是shiro的问题。该错误意味着您的代码(或Shiro库中的代码)无法从commons集合中找到
FastHashMap


这很可能是因为在类路径(应用程序、应用程序服务器等)中有多个commons集合版本。问题可能是commons collections的旧版本比新版本更受欢迎,并且旧版本不包括
FastHashMap

,这似乎更像是链接错误,而不是Shiro的问题。该错误意味着您的代码(或Shiro库中的代码)无法从commons集合中找到
FastHashMap


这很可能是因为在类路径(应用程序、应用程序服务器等)中有多个commons集合版本。问题可能是commons collections的旧版本比新版本更受欢迎,而且旧版本不包括
FastHashMap

我已经用jpa实现了shiro,您可以在中找到源代码

我已经用jpa实现了shiro,您可以在上找到源代码