Apatche Shiro的委托类登录代码。
显示错误 Subject subject = this.securityManager.login(this, token);
错误是Principal争论不能为空..
result = {AuthenticationException @ 7922}方法抛出 ' org.apache.shiro.authc.AuthenticationException'例外。 detailMessage ="令牌提交的身份验证失败 [org.apache.shiro.authc.UsernamePasswordToken - 9876534357, 了rememberMe =真]。可能意外错误? (典型或预期 登录异常应该从AuthenticationException扩展。"原因 = {IllegalArgumentException @ 8066}" java.lang.IllegalArgumentException:principal参数不能为null。" stackTrace = {StackTraceElement [70] @ 8067} suppressExceptions = {Collections $ UnmodifiableRandomAccessList @ 7696} size = 0
public void login(AuthenticationToken token) throws AuthenticationException {
this.clearRunAsIdentitiesInternal();
Subject subject = this.securityManager.login(this, token);
String host = null;
PrincipalCollection principals;
if (subject instanceof DelegatingSubject) {
DelegatingSubject delegating = (DelegatingSubject)subject;
principals = delegating.principals;
host = delegating.host;
} else {
principals = subject.getPrincipals();
}
if (principals != null && !principals.isEmpty()) {
this.principals = principals;
this.authenticated = true;
if (token instanceof HostAuthenticationToken) {
host = ((HostAuthenticationToken)token).getHost();
}
if (host != null) {
this.host = host;
}
Session session = subject.getSession(false);
if (session != null) {
this.session = this.decorate(session);
} else {
this.session = null;
}
} else {
String msg = "Principals returned from securityManager.login( token ) returned a null or empty value. This value must be non null and populated with one or more elements.";
throw new IllegalStateException(msg);
}
}
stackTrace = {StackTraceElement[70]@7843}
0 = {StackTraceElement @ 7701}
" org.apache.shiro.authc.AbstractAuthenticator.authenticate(AbstractAuthenticator.java:214)" 1 = {StackTraceElement @ 7702} " org.apache.shiro.mgt.AuthenticatingSecurityManager.authenticate(AuthenticatingSecurityManager.java:106)" 2 = {StackTraceElement @ 7703} " org.apache.shiro.mgt.DefaultSecurityManager.login(DefaultSecurityManager.java:274)" 3 = {StackTraceElement @ 7704} " org.apache.shiro.subject.support.DelegatingSubject.login(DelegatingSubject.java:260)" 4 = {StackTraceElement @ 7705} " com.hk.impl.service.auth.LoginServiceImpl.login(LoginServiceImpl.java:262)" 5 = {StackTraceElement @ 7706} " com.hk.impl.service.auth.LoginServiceImpl.loginAuthenticatedUser(LoginServiceImpl.java:223)" 6 = {StackTraceElement @ 7707} " com.hk.impl.service.auth.LoginServiceImpl.login(LoginServiceImpl.java:450)" 7 = {StackTraceElement @ 7708} " com.hk.web.resource.UserResource.loginViaOTP(UserResource.java:365)" 8 = {StackTraceElement @ 7709} " sun.reflect.NativeMethodAccessorImpl.invoke0(原生方法)" 9 = {@ StackTraceElement的7710} " sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)" 10 = {StackTraceElement @ 7711} " sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)" 11 = {StackTraceElement @ 7712} " java.lang.reflect.Method.invoke(Method.java:498)" 12 = {@ StackTraceElement的7713} " org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:139)" 13 = {StackTraceElement @ 7714} " org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:295)" 14 = {StackTraceElement @ 7715} " org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:249)" 15 = {StackTraceElement @ 7716} " org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:236)" 16 = {StackTraceElement @ 7717} " org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:376)" 17 = {StackTraceElement @ 7718} " org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:199)" 18 = {StackTraceElement @ 7719} " org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:221)" 19 = {StackTraceElement @ 7720} " org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)" 20 = {StackTraceElement @ 7721} " org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)" 21 = {StackTraceElement @ 7722} " javax.servlet.http.HttpServlet.service(HttpServlet.java:742)" 22 = {@ StackTraceElement的7723} " org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)" 23 = {StackTraceElement @ 7724} " org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)" 24 = {StackTraceElement @ 7725} " org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)" 25 = {StackTraceElement @ 7726} " org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)" 26 = {StackTraceElement @ 7727} " org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)" 27 = {StackTraceElement @ 7728} " com.hk.web.filter.PersonaCookieFilter.doFilter(PersonaCookieFilter.java:60)" 28 = {StackTraceElement @ 7729} " org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)" 29 = {StackTraceElement @ 7730} " org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)" 30 = {StackTraceElement @ 7731} " com.hk.web.filter.GoogleBotFilter.doFilter(GoogleBotFilter.java:102)" 31 = {StackTraceElement @ 7732} " org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)" 32 = {StackTraceElement @ 7733} " org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)" 33 = {StackTraceElement @ 7734} " com.hk.web.filter.InAppUrlRedirectFilter.doFilter(InAppUrlRedirectFilter.java:315)" 34 = {StackTraceElement @ 7735} " org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)" 35 = {StackTraceElement @ 7736} " org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)" 36 = {StackTraceElement @ 7737} " com.hk.web.filter.WebContextFilter.doFilter(WebContextFilter.java:13)" 37 = {StackTraceElement @ 7738} " org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)" 38 = {StackTraceElement @ 7739} " org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)" 39 = {StackTraceElement @ 7740} " org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)" 40 = {StackTraceElement @ 7741} " org.apache.shiro.web.servlet.AbstractShiroFilter $ 1.call(AbstractShiroFilter.java:365)" 41 = {StackTraceElement @ 7742} " org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)" 42 = {StackTraceElement @ 7743} " org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)" 43 = {StackTraceElement @ 7744} " org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:387)" 44 = {StackTraceElement @ 7745} " org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)" 45 = {StackTraceElement @ 7746} " org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)" 46 = {StackTraceElement @ 7747} " org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:347)" 47 = {StackTraceElement @ 7748} " org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:263)" 48 = {StackTraceElement @ 7749} " org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)" 49 = {StackTraceElement @ 7750} " org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)" 50 = {StackTraceElement @ 7751} " com.hk.web.filter.EncodingFilter.doFilter(EncodingFilter.java:27)" 51 = {StackTraceElement @ 7752} " org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)" 52 = {StackTraceElement @ 7753} " org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)" 53 = {StackTraceElement @ 7754} " org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)" 54 = {StackTraceElement @ 7755} " org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)" 55 = {StackTraceElement @ 7756} " org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)" 56 = {StackTraceElement @ 7757} " org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)" 57 = {StackTraceElement @ 7758} " org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)" 58 = {StackTraceElement @ 7759} " org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)" 59 = {StackTraceElement @ 7760} " org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)" 60 = {StackTraceElement @ 7761} " org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)" 61 = {StackTraceElement @ 7762} " org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)" 62 = {StackTraceElement @ 7763} " org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)" 63 = {StackTraceElement @ 7764} " org.apache.coyote.AbstractProtocol $ ConnectionHandler.process(AbstractProtocol.java:790)" 64 = {StackTraceElement @ 7765} " org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1459)" 65 = {StackTraceElement @ 7766} " org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)" 66 = {StackTraceElement @ 7767} " java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)" 67 = {StackTraceElement @ 7768} " java.util.concurrent.ThreadPoolExecutor中$ Worker.run(ThreadPoolExecutor.java:624)" 68 = {StackTraceElement @ 7769} " org.apache.tomcat.util.threads.TaskThread $ WrappingRunnable.run(TaskThread.java:61)" 69 = {StackTraceElement @ 7770}" java.lang.Thread.run(Thread.java:748)"
答案 0 :(得分:0)
这个问题并没有提供太多背景信息,请参阅: https://stackoverflow.com/help/how-to-ask
我在堆栈跟踪中执行此操作:
com.hk.web.resource.UserResource.loginViaOTP(UserResource.java:365)
如果您不使用Shiro的网络过滤器,则需要直接管理Subject creation和thread association。