I'm trying to do the authentication when my client application access the ejb.
I use Glassfish V2 and NetBeans 6.7.1.
I has added a realm (test) and set the default realm as (file).
When I run the program, I get the following exception on client console:
javax.naming.CommunicationException: Can't find SerialContextProvider [Root exception is org.omg.CORBA.NO_PERMISSION: ----------BEGIN server-side stack trace----------
org.omg.CORBA.NO_PERMISSION: vmcid: 0x0 minor code: 0 completed: No
at com.sun.enterprise.iiop.security.SecServerRequestInterceptor.receive_request(SecServerRequestInterceptor.java:576)
at com.sun.corba.ee.impl.interceptors.InterceptorInvoker.invokeServerInterceptorIntermediatePoint(InterceptorInvoker.java:627)
at com.sun.corba.ee.impl.interceptors.PIHandlerImpl.invokeServerPIIntermediatePoint(PIHandlerImpl.java:530)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.getServantWithPI(CorbaServerRequestDispatcherImpl.java:406)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:224)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1846)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1706)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:1088)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:223)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:806)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.dispatch(CorbaMessageMediatorImpl.java:563)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.doWork(CorbaMessageMediatorImpl.java:2567)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:555)
----------END server-side stack trace---------- vmcid: 0x0 minor code: 0 completed: No]
and following exception on server console:
SEC5046: Audit: Authentication refused for [test].
Audit: Authentication for user = (test) under realm = (default) returned = false
IOP5049: Login exception: [com.sun.enterprise.security.LoginException: Login failed: javax.security.auth.login.LoginException: Failed file login for test.]
It seen that the server is using the default realm to do the authentication.
I tried to set the default realm as (test), then everything are work.
In my case, I have 2 or above projects deploy on the glassfish, so I cannot use the default realm.
Anyone can help me to set the non-default realm to do the authentication?
Thanks.
-----------------------------------------------------------------------------------------------
sun-ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 EJB 3.0//EN" "
http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-0.dtd">
<sun-ejb-jar>
<security-role-mapping>
<role-name>_administrators</role-name>
<group-name>administrators</group-name>
</security-role-mapping>
<security-role-mapping>
<role-name>_User</role-name>
<group-name>User</group-name>
</security-role-mapping>
<security-role-mapping>
<role-name>_guest</role-name>
<group-name/>
</security-role-mapping>
<enterprise-beans>
<unique-id>0</unique-id>
<ejb>
<ejb-name>TestEjbBean</ejb-name>
<jndi-name>TestEjbBean</jndi-name>
<ior-security-config>
<transport-config>
<integrity>supported</integrity>
<confidentiality>supported</confidentiality>
<establish-trust-in-target>supported</establish-trust-in-target>
<establish-trust-in-client>supported</establish-trust-in-client>
</transport-config>
<as-context>
<auth-method>USERNAME_PASSWORD</auth-method>
<realm>test</realm>
<required>true</required>
</as-context>
<sas-context>
<caller-propagation>supported</caller-propagation>
</sas-context>
</ior-security-config>
</ejb>
</enterprise-beans>
</sun-ejb-jar>
-----------------------------------------------------------------------------------------------
ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns = "
http://java.sun.com/xml/ns/javaee"
version = "3.0"
xmlns:xsi = "
http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "
http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
<enterprise-beans>
<!-- A minimal session EJB deployment-->
<session>
<ejb-name>TestEjbBean</ejb-name>
<!--<mapped-name>TestEjbBean</mapped-name>-->
<business-remote>Stateful.TestEjbRemote</business-remote>
<ejb-class>Stateful.TestEjbBean</ejb-class>
<session-type>Stateful</session-type>
<transaction-type>Bean</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
-----------------------------------------------------------------------------------------------
Client application
public class Main extends JFrame implements Runnable{
TestEjbRemote testEJB;
JTextArea jTextArea1;
JScrollPane jScrollPane1;
JButton jButton1;
public Main(){
try {
System.setProperty("java.security.auth.login.config", "C:/Sun/AppServer/lib/appclient/appclientlogin.conf");
ProgrammaticLogin pm = new ProgrammaticLogin();
pm.login("test", "testtest", "test", true);
Properties props = new Properties();
InputStream in = this.getClass().getResourceAsStream("jndi.properties");
props.load(in);
InitialContext ctx = new InitialContext(props);
testEJB = (TestEjbRemote) ctx.lookup("TestEjbBean");
System.out.println(testEJB.getText());
} catch (NamingException nex) {
nex.printStackTrace();
} catch (Exception ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
initComponents();
}
public static void main(String[] args) {
Main main = new Main();
main.setVisible(true);
Thread t = new Thread(main);
t.start();
}
public void run() {
try{
int i = 0;
while(i < 10){
i++;
jTextArea1.append("\nTest:");
jTextArea1.append("\nName:" + testEJB.getName());
jTextArea1.append("\nTime:" + testEJB.getTime());
jTextArea1.repaint();
jTextArea1.revalidate();
testEJB.appendText("1");
jTextArea1.append(testEJB.getText());
Thread.sleep(600);
}
}catch(Exception e){
e.printStackTrace();
}
}
}
-----------------------------------------------------------------------------------------------
jndi.properties
org.omg.CORBA.ORBInitialHost = 101.100.100.109
org.omg.CORBA.ORBInitialPort = 3700
-----------------------------------------------------------------------------------------------
[Message sent by forum member 'thlee86']
http://forums.java.net/jive/thread.jspa?messageID=485440