1 13 14 package org.ejbca.samples; 15 16 import java.rmi.RemoteException ; 17 import java.util.ArrayList ; 18 19 import javax.ejb.CreateException ; 20 import javax.ejb.EJBException ; 21 import javax.ejb.ObjectNotFoundException ; 22 23 import org.ejbca.core.ejb.BaseSessionBean; 24 import org.ejbca.core.ejb.log.ILogSessionHome; 25 import org.ejbca.core.ejb.log.ILogSessionRemote; 26 import org.ejbca.core.model.SecConst; 27 import org.ejbca.core.model.ca.AuthLoginException; 28 import org.ejbca.core.model.ca.AuthStatusException; 29 import org.ejbca.core.model.log.Admin; 30 import org.ejbca.core.model.log.LogEntry; 31 import org.ejbca.core.model.ra.UserDataConstants; 32 import org.ejbca.core.model.ra.UserDataVO; 33 import org.ejbca.util.CertTools; 34 35 36 37 38 84 public class NullAuthenticationSessionBean extends BaseSessionBean { 85 86 private ILogSessionRemote logsession; 87 88 89 94 public void ejbCreate() throws CreateException { 95 debug(">ejbCreate()"); 96 97 try { 98 ILogSessionHome logsessionhome = (ILogSessionHome) getLocator().getLocalHome(ILogSessionHome.COMP_NAME); 99 logsession = logsessionhome.create(); 100 } catch (Exception e) { 101 throw new EJBException (e); 102 } 103 104 debug("<ejbCreate()"); 105 } 106 107 118 public UserDataVO authenticateUser(Admin admin, String username, String password) 119 throws ObjectNotFoundException , AuthStatusException, AuthLoginException { 120 debug(">authenticateUser(" + username + ", hiddenpwd)"); 121 122 try { 123 String dn = CertTools.stringToBCDNString(username); 125 126 if ((dn != null) && (dn.length() > 0)) { 127 String email = null; 128 ArrayList emails = CertTools.getEmailFromDN(dn); 129 if (emails.size() > 0) { 130 email = (String )emails.get(0); 131 } 132 try{ 133 logsession.log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date (),username, null, LogEntry.EVENT_INFO_USERAUTHENTICATION,"NULL-Authenticated user"); 134 }catch(RemoteException re){ 135 throw new EJBException (re); 136 } 137 138 String altName = (email == null) ? null : ("rfc822Name=" + email); 139 140 UserDataVO ret = new UserDataVO(username, dn, admin.getCaId(), altName, email, UserDataConstants.STATUS_NEW, SecConst.USER_ENDUSER, SecConst.PROFILE_NO_PROFILE, SecConst.PROFILE_NO_PROFILE, 142 null, null, SecConst.TOKEN_SOFT_BROWSERGEN,0,null); 143 ret.setPassword(password); 144 debug("<authenticateUser("+username+", hiddenpwd)"); 145 return ret; 146 } 147 try{ 148 logsession.log(admin, admin.getCaId(), LogEntry.MODULE_CA, new java.util.Date (),username, null, LogEntry.EVENT_ERROR_USERAUTHENTICATION,"User does not contain a DN."); 149 }catch(RemoteException re){ 150 throw new EJBException (re); 151 } 152 153 throw new AuthLoginException("User " + username + " does not contain a DN."); 154 } catch (AuthLoginException le) { 155 throw le; 156 } catch (Exception e) { 157 throw new EJBException (e.toString()); 158 } 159 } 161 168 public void finishUser(Admin admin, String username, String password) 169 throws ObjectNotFoundException { 170 debug(">finishUser(" + username + ", hiddenpwd)"); 171 debug("<finishUser(" + username + ", hiddenpwd)"); 172 } } 174 | Popular Tags |