1 13 14 19 package org.ejbca.core.model; 20 21 22 import java.security.cert.X509Certificate ; 23 24 import javax.ejb.FinderException ; 25 import javax.naming.InitialContext ; 26 import javax.servlet.http.HttpServletRequest ; 27 28 import org.ejbca.core.ejb.ca.store.ICertificateStoreSessionHome; 29 import org.ejbca.core.ejb.ca.store.ICertificateStoreSessionRemote; 30 import org.ejbca.core.ejb.ra.IUserAdminSessionHome; 31 import org.ejbca.core.ejb.ra.IUserAdminSessionRemote; 32 import org.ejbca.core.model.ca.certificateprofiles.CertificateProfile; 33 import org.ejbca.core.model.log.Admin; 34 import org.ejbca.core.model.ra.UserDataVO; 35 36 37 38 39 45 public class ApplyBean implements java.io.Serializable { 46 49 public ApplyBean() { 50 } 51 52 public void initialize(HttpServletRequest request) 54 throws Exception { 55 if (!initialized) { 56 if (request.getAttribute("javax.servlet.request.X509Certificate") != null) { 57 administrator = new Admin(((X509Certificate []) request.getAttribute( 58 "javax.servlet.request.X509Certificate"))[0]); 59 } else { 60 administrator = new Admin(Admin.TYPE_PUBLIC_WEB_USER, request.getRemoteAddr()); 61 } 62 63 InitialContext jndicontext = new InitialContext (); 64 Object obj1 = jndicontext.lookup(IUserAdminSessionHome.JNDI_NAME); 65 useradminhome = (IUserAdminSessionHome) javax.rmi.PortableRemoteObject.narrow(obj1, 66 IUserAdminSessionHome.class); 67 obj1 = jndicontext.lookup(ICertificateStoreSessionHome.JNDI_NAME); 68 certificatesessionhome = (ICertificateStoreSessionHome) javax.rmi.PortableRemoteObject.narrow(obj1, 69 ICertificateStoreSessionHome.class); 70 initialized = true; 71 } 72 } 73 74 84 public int getTokenType(String username) throws Exception { 85 int returnval = 0; 86 IUserAdminSessionRemote useradminsession = useradminhome.create(); 87 88 if(!username.equals(this.username) || this.useradmindata == null){ 89 try { 90 this.useradmindata = useradminsession.findUser(administrator, username); 91 } catch (FinderException fe) { 92 } 93 } 94 95 if (useradmindata != null) { 96 returnval = useradmindata.getTokenType(); 97 } 98 this.username = username; 99 100 return returnval; 101 } 102 103 113 public int getCAId(String username) throws Exception { 114 int returnval = 0; 115 IUserAdminSessionRemote useradminsession = useradminhome.create(); 116 117 if(!username.equals(this.username) || this.useradmindata == null){ 118 try { 119 this.useradmindata = useradminsession.findUser(administrator, username); 120 } catch (FinderException fe) { 121 } 122 } 123 124 if (useradmindata != null) { 125 returnval = useradmindata.getCAId(); 126 } 127 this.username = username; 128 129 return returnval; 130 } 131 132 133 141 public int[] availableBitLengths(String username) throws Exception { 142 int[] returnval = null; 143 IUserAdminSessionRemote useradminsession = useradminhome.create(); 144 145 if(!username.equals(this.username) || this.useradmindata == null){ 146 try { 147 this.useradmindata = useradminsession.findUser(administrator, username); 148 } catch (FinderException fe) { 149 } 150 } 151 152 if (useradmindata != null) { 153 ICertificateStoreSessionRemote certstoresession = certificatesessionhome.create(); 154 int certprofile = useradmindata.getCertificateProfileId(); 155 156 if (certprofile != SecConst.PROFILE_NO_PROFILE) { 157 CertificateProfile p = certstoresession.getCertificateProfile(administrator, certprofile); 158 returnval = p.getAvailableBitLengths(); 159 } 160 } 161 this.username = username; 162 163 return returnval; 164 } 165 166 private IUserAdminSessionHome useradminhome; 169 private ICertificateStoreSessionHome certificatesessionhome; 170 private boolean initialized; 171 private Admin administrator; 172 private String username = ""; 173 private UserDataVO useradmindata = null; 174 } 175 | Popular Tags |