我正在尝试为 Glassfish V3.1.1 创建自定义领域,但是当我使用 BASIC 方法登录时出现了一些 LoginException:
[#|2012-10-11T22:57:21.625+0200|FINE|glassfish3.1.2|org.apache.catalina.authenticator.AuthenticatorBase|_ThreadID=35;_ThreadName=Thread-2;ClassName=org.apache.catalina.authenticator .AuthenticatorBase;MethodName=invoke;|安全检查请求 GET /testForMySimRealm/S1|#]
[#|2012-10-11T22:57:21.625+0200|FINE|glassfish3.1.2|org.apache.catalina.authenticator.AuthenticatorBase|_ThreadID=35;_ThreadName=Thread-2;ClassName=org.apache.catalina.authenticator .AuthenticatorBase;方法名=调用;| 调用 hasUserDataPermission()|#]
[#|2012-10-11T22:57:21.625+0200|FINE|glassfish3.1.2|javax.enterprise.system.container.web.com.sun.web.security|_ThreadID=35;_ThreadName=Thread-2;ClassName =com.sun.web.security.RealmAdapter;MethodName=hasUserDataPermission;|[Web-Security][ hasUserDataPermission ] 主体:空 ContextPath:/testForMySimRealm|#]
[#|2012-10-11T22:57:21.625+0200|FINE|glassfish3.1.2|javax.enterprise.system.container.web.com.sun.web.security|_ThreadID=35;_ThreadName=Thread-2;ClassName =com.sun.web.security.RealmAdapter;MethodName=invokeWebSecurityManager;|[Web-Security] [ hasResourcePermission ] 主体:空 ContextPath:/testForMySimRealm|#]
[#|2012-10-11T22:57:21.625+0200|FINE|glassfish3.1.2|org.apache.catalina.authenticator.AuthenticatorBase|_ThreadID=35;_ThreadName=Thread-2;ClassName=org.apache.catalina.authenticator .AuthenticatorBase;方法名=调用;| 调用 authenticate()|#]
[#|2012-10-11T22:57:21.640+0200|FINE|glassfish3.1.2|org.apache.catalina.authenticator.AuthenticatorBase|_ThreadID=35;_ThreadName=Thread-2;ClassName=org.apache.catalina.authenticator .AuthenticatorBase;方法名=调用;| 验证失败()测试|#]
[#|2012-10-11T22:57:21.640+0200|FINE|glassfish3.1.2|org.apache.catalina.connector.OutputBuffer|_ThreadID=35;_ThreadName=Thread-2;ClassName=org.apache.catalina.connector .OutputBuffer;MethodName=setConverter;|得到编码:ISO-8859-1|#]
[#|2012-10-11T22:57:21.640+0200|FINE|glassfish3.1.2|org.apache.catalina.connector.OutputBuffer|_ThreadID=35;_ThreadName=Thread-2;ClassName=org.apache.catalina.connector .OutputBuffer;MethodName=realWriteBytes;|realWrite(b, 0, 1073) com.sun.grizzly.tcp.Response@192d307|#]
[#|2012-10-11T22:57:21.640+0200|FINEST|glassfish3.1.2|org.apache.catalina.connector.InputBuffer|_ThreadID=35;_ThreadName=Thread-2;ClassName=org.apache.catalina.connector .InputBuffer;MethodName=recycle;|recycle()|#]
[#|2012-10-11T22:57:21.640+0200|FINE|glassfish3.1.2|org.apache.catalina.connector.OutputBuffer|_ThreadID=35;_ThreadName=Thread-2;ClassName=org.apache.catalina.connector .OutputBuffer;MethodName=recycle;|recycle()|#]
[#|2012-10-11T22:57:24.625+0200|FINE|glassfish3.1.2|org.apache.catalina.authenticator.AuthenticatorBase|_ThreadID=36;_ThreadName=Thread-2;ClassName=org.apache.catalina.authenticator .AuthenticatorBase;MethodName=invoke;|安全检查请求 GET /testForMySimRealm/S1|#]
[#|2012-10-11T22:57:24.625+0200|FINE|glassfish3.1.2|org.apache.catalina.authenticator.AuthenticatorBase|_ThreadID=36;_ThreadName=Thread-2;ClassName=org.apache.catalina.authenticator .AuthenticatorBase;方法名=调用;| 调用 hasUserDataPermission()|#]
[#|2012-10-11T22:57:24.625+0200|FINE|glassfish3.1.2|javax.enterprise.system.container.web.com.sun.web.security|_ThreadID=36;_ThreadName=Thread-2;ClassName =com.sun.web.security.RealmAdapter;MethodName=hasUserDataPermission;|[Web-Security][ hasUserDataPermission ] 主体:空 ContextPath:/testForMySimRealm|#]
[#|2012-10-11T22:57:24.625+0200|FINE|glassfish3.1.2|javax.enterprise.system.container.web.com.sun.web.security|_ThreadID=36;_ThreadName=Thread-2;ClassName =com.sun.web.security.RealmAdapter;MethodName=invokeWebSecurityManager;|[Web-Security] [ hasResourcePermission ] 主体:空 ContextPath:/testForMySimRealm|#]
[#|2012-10-11T22:57:24.625+0200|FINE|glassfish3.1.2|org.apache.catalina.authenticator.AuthenticatorBase|_ThreadID=36;_ThreadName=Thread-2;ClassName=org.apache.catalina.authenticator .AuthenticatorBase;方法名=调用;| 调用 authenticate()|#]
[#|2012-10-11T22:57:24.625+0200|FINE|glassfish3.1.2|javax.enterprise.system.container.web.com.sun.web.security|_ThreadID=36;_ThreadName=Thread-2;ClassName =com.sun.web.security.RealmAdapter;MethodName=authenticate;|用于验证用户/密码的Tomcat回调|#]
[#|2012-10-11T22:57:24.625+0200|FINE|glassfish3.1.2|javax.enterprise.system.container.web.com.sun.web.security|_ThreadID=36;_ThreadName=Thread-2;ClassName =com.sun.web.security.RealmAdapter;MethodName=authenticate;|usename = j|#]
[#|2012-10-11T22:57:24.625+0200|警告|glassfish3.1.2|javax.enterprise.system.container.web.com.sun.web.security|_ThreadID=36;_ThreadName=Thread-2;| WEB9102:Web 登录失败:com.sun.enterprise.security.auth.login.common.LoginException:登录失败:Entrée NULL 无效:nom|#]
[#|2012-10-11T22:57:24.625+0200|FINE|glassfish3.1.2|javax.enterprise.system.container.web.com.sun.web.security|_ThreadID=36;_ThreadName=Thread-2;ClassName =com.sun.web.security.RealmAdapter;MethodName=authenticate;|Exception com.sun.enterprise.security.auth.login.common.LoginException: Login failed: Entrée NULL non valide: nom at com.sun.enterprise.security .auth.login.LoginContextDriver.doPasswordLogin(LoginContextDriver.java:394) 在 com.sun.enterprise.security.auth.login.LoginContextDriver.login(LoginContextDriver.java:240) 在 com.sun.enterprise.security.auth.login .LoginContextDriver.login(LoginContextDriver.java:153) 在 com.sun.web.security.RealmAdapter.authenticate(RealmAdapter.java:514) 在 com.sun.web.security.RealmAdapter.authenticate(RealmAdapter.java:455) 在org.apache.catalina.authenticator。BasicAuthenticator.authenticate(BasicAuthenticator.java:169) at com.sun.web.security.RealmAdapter.invokeAuthenticateDelegate(RealmAdapter.java:1333) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:551) at org .apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:623) 在 org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) 在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve .java:161) 在 org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331) 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) 在 com.sun.enterprise。 v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317) 位于 com.sun.enterprise.v3.services.impl.ContainerMapper。com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860) com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757) com.sun 的服务(ContainerMapper.java:195) .grizzly.http.ProcessorTask.process(ProcessorTask.java:1056) 在 com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229) 在 com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137 ) 在 com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) 在 com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) 在 com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain. java:79) 在 com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) 在 com.sun.grizzly.SelectionKeyContextTask。在 com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) 在 com.sun 的 com.sun.grizzly.ContextTask.run(ContextTask.java:71) 调用(SelectionKeyContextTask.java:59) .grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) at java.lang.Thread.run(Thread.java:722) 原因:javax.security.auth.login.LoginException:Entrée NULL 无效:在 javax.security.auth.login.LoginContext.init(LoginContext.java:246) 在 javax.security.auth.login.LoginContext.(LoginContext.java:382) 在 javax.security.auth.login.LoginContext.( LoginContext.java:459) 在 com.sun.enterprise.security.auth.login.LoginContextDriver.doPasswordLogin(LoginContextDriver.java:381) ... 28 更多 |#]71) 在 com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) 在 java.lang.Thread 的 com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) .run(Thread.java:722) 引起:javax.security.auth.login.LoginException: Entrée NULL non valide : nom at javax.security.auth.login.LoginContext.init(LoginContext.java:246) at javax。 security.auth.login.LoginContext.(LoginContext.java:382) at javax.security.auth.login.LoginContext.(LoginContext.java:459) at com.sun.enterprise.security.auth.login.LoginContextDriver.doPasswordLogin( LoginContextDriver.java:381) ... 28 更多 |#]71) 在 com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) 在 java.lang.Thread 的 com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) .run(Thread.java:722) 引起:javax.security.auth.login.LoginException: Entrée NULL non valide : nom at javax.security.auth.login.LoginContext.init(LoginContext.java:246) at javax。 security.auth.login.LoginContext.(LoginContext.java:382) at javax.security.auth.login.LoginContext.(LoginContext.java:459) at com.sun.enterprise.security.auth.login.LoginContextDriver.doPasswordLogin( LoginContextDriver.java:381) ... 28 更多 |#]运行(Thread.java:722)引起:javax.security.auth.login.LoginException:Entrée NULL non valide:在 javax.security.auth.login.LoginContext.init(LoginContext.java:246) 在 javax.security .auth.login.LoginContext.(LoginContext.java:382) 在 javax.security.auth.login.LoginContext.(LoginContext.java:459) 在 com.sun.enterprise.security.auth.login.LoginContextDriver.doPasswordLogin(LoginContextDriver .java:381) ... 还有 28 个 |#]运行(Thread.java:722)引起:javax.security.auth.login.LoginException:Entrée NULL non valide:在 javax.security.auth.login.LoginContext.init(LoginContext.java:246) 在 javax.security .auth.login.LoginContext.(LoginContext.java:382) 在 javax.security.auth.login.LoginContext.(LoginContext.java:459) 在 com.sun.enterprise.security.auth.login.LoginContextDriver.doPasswordLogin(LoginContextDriver .java:381) ... 还有 28 个 |#]doPasswordLogin(LoginContextDriver.java:381) ... 28 更多 |#]doPasswordLogin(LoginContextDriver.java:381) ... 28 更多 |#]
[#|2012-10-11T22:57:24.625+0200|FINE|glassfish3.1.2|org.apache.catalina.authenticator.AuthenticatorBase|_ThreadID=36;_ThreadName=Thread-2;ClassName=org.apache.catalina.authenticator .AuthenticatorBase;方法名=调用;| 验证失败()测试|#]
[#|2012-10-11T22:57:24.625+0200|FINE|glassfish3.1.2|org.apache.catalina.connector.OutputBuffer|_ThreadID=36;_ThreadName=Thread-2;ClassName=org.apache.catalina.connector .OutputBuffer;MethodName=setConverter;|得到编码:ISO-8859-1|#]
[#|2012-10-11T22:57:24.625+0200|FINE|glassfish3.1.2|org.apache.catalina.connector.OutputBuffer|_ThreadID=36;_ThreadName=Thread-2;ClassName=org.apache.catalina.connector .OutputBuffer;MethodName=realWriteBytes;|realWrite(b, 0, 1073) com.sun.grizzly.tcp.Response@7e592c|#]
[#|2012-10-11T22:57:24.625+0200|FINEST|glassfish3.1.2|org.apache.catalina.connector.InputBuffer|_ThreadID=36;_ThreadName=Thread-2;ClassName=org.apache.catalina.connector .InputBuffer;MethodName=recycle;|recycle()|#]
[#|2012-10-11T22:57:24.625+0200|FINE|glassfish3.1.2|org.apache.catalina.connector.OutputBuffer|_ThreadID=36;_ThreadName=Thread-2;ClassName=org.apache.catalina.connector .OutputBuffer;MethodName=recycle;|recycle()|#]
这是我的领域课程:
CustomSimLoginModule 扩展 AppservPasswordLoginModule :
package com.sim;
import javax.security.auth.login.LoginException;
import com.sun.appserv.security.AppservPasswordLoginModule;
public class CustomSimLoginModule extends AppservPasswordLoginModule {
@Override
protected void authenticateUser() throws LoginException {
// TODO Auto-generated method stub
System.out.println("AUTHENTIFICATION !!");
String[] grpList = {"ADMIN"};
commitUserAuthentication(grpList);
}
}
CustomSimRealm 扩展 AppservRealm :
package com.sim;
import java.util.Enumeration;
import java.util.Properties;
import java.util.Vector;
import com.sun.appserv.security.AppservRealm;
import com.sun.enterprise.security.auth.realm.BadRealmException;
import com.sun.enterprise.security.auth.realm.InvalidOperationException;
import com.sun.enterprise.security.auth.realm.NoSuchRealmException;
import com.sun.enterprise.security.auth.realm.NoSuchUserException;
public class CustomSimRealm extends AppservRealm {
@Override
public void init(Properties properties) throws BadRealmException, NoSuchRealmException {
System.out.println("CustomSimRealm->init");
Enumeration<?> names = properties.propertyNames();
String name = null;
while(names.hasMoreElements()){
name = (String)names.nextElement();
System.out.println("name->" + name + " value->" + properties.getProperty(name));
}
}
@Override
public String getAuthType() {
return "BASIC";
}
@Override
public Enumeration<String> getGroupNames(String username)
throws InvalidOperationException, NoSuchUserException {
Vector<String> v = new Vector<String>();
v.add("ADMIN");
return v.elements();
}
}
这 2 个类使用 maven 打包到 JAR 文件中,并具有以下依赖项:
<dependency>
<groupId>org.glassfish.main.security</groupId>
<artifactId>security</artifactId>
<version>3.1.2</version>
</dependency>
JAR 文件被复制到 ${GLASSFISH}/glassfish/domains/domain1/lib 目录中,我将 login.conf 更改为:
simRealm {
com.sim.CustomSimLoginModule required;
};
和 domain.xml :
<auth-realm name="sim-realm" classname="com.sim.CustomSimRealm">
<property name="prop1" value="test propriete 1"></property>
<property name="prop2" value="test propriete 2"></property>
<property description="null" name="jaas-context" value="simRealm"></property>
</auth-realm>
Glassfish 启动时未引发异常,但在用户输入凭据时会引发上述异常。
请问我做错了什么?
PS:没有使用 Glassfish create-auth-realm 命令,我手动更改了 login.conf 和 domain.xml,这可能是问题吗?
感谢您的想法
奥利维尔