我的应用程序没有准备好shiro.ini。我正在使用VRaptor框架,而不是这个慢速的shiro.ini。这在类路径上,不读。
public LoginController() {
Factory<SecurityManager> factory = new IniSecurityManagerFactory();
SecurityManager securityManager = factory.getInstance();
SecurityUtils.setSecurityManager(securityManager);
}
public boolean autenticar(String email, String password, Boolean rememberMe) throws NoSuchAlgorithmException, UnsupportedEncodingException {
UsernamePasswordToken token = new UsernamePasswordToken(email, password);
token.setRememberMe(true);
Subject subject = SecurityUtils.getSubject();
try {
subject.login(token);
} catch ( UnknownAccountException uae ) {
System.out.println(uae.getMessage());
} catch ( IncorrectCredentialsException ice ) {
System.out.println(ice.getMessage());
} catch ( LockedAccountException lae ) {
System.out.println(lae.getMessage());
} catch ( ExcessiveAttemptsException eae ){
System.out.println(eae.getMessage());
}
result.redirectTo(LoginController.class).admin();
return false;
}
的src /主/ web应用/ WEB-INF / shiro.ini
我使用了一个名为vraptor的框架。我把shiro依赖项和.ini文件,这个错误。
GRAVE: Servlet.service() for servlet [default] in context with path [/vraptor-andre] threw exception [net.vidageek.mirror.exception.ReflectionProviderException: Could not invoke method autenticar] with root cause
java.lang.IllegalStateException: Configuration error: No realms have been configured! One or more realms must be present to execute an authentication attempt.
at org.apache.shiro.authc.pam.ModularRealmAuthenticator.assertRealmsConfigured(ModularRealmAuthenticator.java:161)
at org.apache.shiro.authc.pam.ModularRealmAuthenticator.doAuthenticate(ModularRealmAuthenticator.java:264)
at org.apache.shiro.authc.AbstractAuthenticator.authenticate(AbstractAuthenticator.java:198)
at org.apache.shiro.mgt.AuthenticatingSecurityManager.authenticate(AuthenticatingSecurityManager.java:106)
at org.apache.shiro.mgt.DefaultSecurityManager.login(DefaultSecurityManager.java:270)
at org.apache.shiro.subject.support.DelegatingSubject.login(DelegatingSubject.java:256)
at br.com.genius.shiro.controller.LoginController.autenticar(LoginController.java:55)
shiro.ini
[main]
authc.loginUrl = /login
jdbcRealm = br.com.genius.shiro.auth.MyCustomRealm
sha256Matcher = org.apache.shiro.authc.credential.Sha256CredentialsMatcher
sha256Matcher.storedCredentialsHexEncoded = false
sha256Matcher.hashIterations = 1024
jdbcRealm.credentialsMatcher = $sha256Matcher
jdbcRealm.authenticationQuery = SELECT password, salt FROM User WHERE email = ?
jdbcRealm.permissionsLookupEnabled = true
jdbcRealm.userRolesQuery = select roleName from UserRole where email = ?
jdbcRealm.permissionsQuery = select permission from RolesPermission where roleName = ?
ds = com.mysql.jdbc.jdbc2.optional.MysqlDataSource
ds.serverName = x.x.x.x
ds.user = xxxx
ds.password = xxxx
ds.databaseName = data
jdbcRealm.dataSource=$ds
authc.usernameParam = email
authc.passwordParam = password
authc.failureKeyAttribute = shiroLoginFailure
builtInCacheManager = org.apache.shiro.cache.MemoryConstrainedCacheManager
securityManager.cacheManager = $builtInCacheManager
securityManager.realms = $jdbcRealm
[urls]
/login = authc
/logout = logout
/admin/** = user, roles[admin]
/guest/** = user, roles[guest]`
shiro.ini中的当[AUTH]将其作为内部错误时,无法识别并且不显示此错误
`The server encountered an internal error that prevented it from fulfilling this request.`
javax.enterprise.event.ObserverException
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
java.lang.reflect.Constructor.newInstance(Unknown Source)
java.lang.Class.newInstance(Unknown Source)
com.google.common.util.concurrent.ExecutionError:java.lang.NoClassDefFoundError:org / apache / commons / logging / LogFactory com.google.common.cache.LocalCache $ Segment.get(LocalCache.java:2197) com.google.common.cache.LocalCache.get(LocalCache.java:3932) com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3936) com.google.common.cache.LocalCache $ LocalLoadingCache.get(LocalCache.java:4806) org.jboss.weld.util.cache.LoadingCacheUtils.getCacheValue(LoadingCacheUtils.java:52) org.jboss.weld.util.cache.LoadingCacheUtils.getCastCacheValue(LoadingCacheUtils.java:80) org.jboss.weld.bean.proxy.ClientProxyProvider.getClientProxy(ClientProxyProvider.java:204) org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:727) org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:753)
答案 0 :(得分:0)
如果您的应用程序正在查找shiro.ini的类路径,则目录src / main / webapp / web-inf不是放置它的正确路径。
看起来你正在使用maven,如果是这样,它应该进入src / main / resources。 在生成的webapp中,它应该以WEB-INF / classes
结束