LDAP Login Help
cbuckley Mar 2, 2004 7:47 PMThe code below I can get to work from a stand alone java application if I take the contents of the ejbCreate() and the createUpstrem... and put it in a main method. However when I try to make the following code execute as a session bean, it won't work. I'm not sure where the break down is. Below it the code I am using. Any help would be much appreciated.
/*
* Created on Feb 17, 2004
*
*/
package intuinet.session;
import intuinet.callback.UpstreamCallbackHandler;
import intuinet.util.LdapLoginProxy;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
/**
* @author cbuckley
* @ejb.bean description="Stateful LDAP Login Bean"
* display-name="LdapLoginSession"
* jndi-name="ejb/intuinet/LdapLoginHomeRemote"
* name="LdapLoginSession"
* type="Stateless"
* view-type="remote"
*
* @ejb.env-entry name = "java.security.policy"
* type = "java.lang.String"
* value = "jaas.policy"
*
* @ejb.env-entry name = "java.security.auth.login.config"
* type = "java.lang.String"
* value = "jaas.conf"
*
* @ejb.util generate = "physical"
*/
public class LdapLoginSession implements SessionBean {
private LdapLoginProxy login;
/* (non-Javadoc)
* @see javax.ejb.SessionBean#ejbActivate()
*/
public void ejbActivate() throws EJBException, RemoteException {
}
/**
*
* @throws CreateException
*
* @ejb.create-method
*/
public void ejbCreate() throws CreateException{
String policy = Thread.currentThread().getContextClassLoader().getResource("jaas.policy").toString();
String conf = Thread.currentThread().getContextClassLoader().getResource("jaas.conf").toString();
//Setting system variables....
String sep = System.getProperty("file.separator");
java.util.Properties p = new java.util.Properties(System.getProperties());
p.setProperty("java.security.krb5.realm", "upstream.cutthroatcom.com");
p.setProperty("java.security.krb5.kdc", "madison.upstream.cutthroatcom.com");
p.setProperty("java.security.policy", policy);
p.setProperty("java.security.auth.login.config", conf);
System.setProperties(p);
}
/**
* @ejb.interface-method
* @param user
* @param pass
* @return
*/
public boolean createUpstreamLogin(String user, String pass){
LoginContext lc = null;
boolean valid = false;
UpstreamCallbackHandler callback = new UpstreamCallbackHandler(user, pass);
try {
lc = new LoginContext("JaasIntuinet", callback);
} catch (LoginException le) {
System.err.println("Cannot create LoginContext. "
+ le.getMessage());
} catch (SecurityException se) {
System.err.println("Cannot create LoginContext. Security Exception"
+ se.getMessage());
}
try {
// attempt authentication
lc.login();
valid = true;
System.out.println("Your logged in");
} catch (LoginException le) {
System.err.println("Authentication failed:");
System.err.println(" " + le.getMessage());
}
return valid; }
/* (non-Javadoc)
* @see javax.ejb.SessionBean#ejbPassivate()
*/
public void ejbPassivate() throws EJBException, RemoteException {
}
/* (non-Javadoc)
* @see javax.ejb.SessionBean#ejbRemove()
*/
public void ejbRemove() throws EJBException, RemoteException {
}
/* (non-Javadoc)
* @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
*/
public void setSessionContext(SessionContext arg0)
throws EJBException, RemoteException {
}
}