KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > model > ApplyBean


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13  
14 /*
15  * ApplyBean.java
16  *
17  * Created on den 3 nov 2002, 12:06
18  */

19 package org.ejbca.core.model;
20
21
22 import java.security.cert.X509Certificate JavaDoc;
23
24 import javax.ejb.FinderException JavaDoc;
25 import javax.naming.InitialContext JavaDoc;
26 import javax.servlet.http.HttpServletRequest JavaDoc;
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 /**
40  * A class used as an interface between Apply jsp pages and ejbca functions.
41  *
42  * @author Philip Vendil
43  * @version $Id: ApplyBean.java,v 1.4 2006/10/02 07:59:05 anatom Exp $
44  */

45 public class ApplyBean implements java.io.Serializable JavaDoc {
46     /**
47      * Creates a new instance of CaInterfaceBean
48      */

49     public ApplyBean() {
50     }
51
52     // Public methods
53
public void initialize(HttpServletRequest JavaDoc request)
54         throws Exception JavaDoc {
55         if (!initialized) {
56             if (request.getAttribute("javax.servlet.request.X509Certificate") != null) {
57                 administrator = new Admin(((X509Certificate JavaDoc[]) 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 JavaDoc jndicontext = new InitialContext JavaDoc();
64             Object JavaDoc 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     /**
75      * Method that returns a users tokentype defined in SecConst, if 0 is returned user couldn't be
76      * found i database.
77      *
78      * @param username the user whose tokentype should be returned
79      *
80      * @return tokentype as defined in SecConst
81      *
82      * @see org.ejbca.core.model.SecConst
83      */

84     public int getTokenType(String JavaDoc username) throws Exception JavaDoc {
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 JavaDoc fe) {
92           }
93         }
94         
95         if (useradmindata != null) {
96             returnval = useradmindata.getTokenType();
97         }
98         this.username = username;
99         
100         return returnval;
101     }
102
103     /**
104      * Method that returns a users tokentype defined in SecConst, if 0 is returned user couldn't be
105      * found i database.
106      *
107      * @param username the user whose tokentype should be returned
108      *
109      * @return caid of user.
110      *
111      * @see org.ejbca.core.model.SecConst
112      */

113     public int getCAId(String JavaDoc username) throws Exception JavaDoc {
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 JavaDoc 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     /**
134      * Method that returns a bitlengths available for the user. Returns null if user couldn't be
135      * found in database.
136      *
137      * @param username user whose bit lengts are requested.
138      *
139      * @return array of available bit lengths
140      */

141     public int[] availableBitLengths(String JavaDoc username) throws Exception JavaDoc {
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 JavaDoc 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 methods
167
// Private fields
168
private IUserAdminSessionHome useradminhome;
169     private ICertificateStoreSessionHome certificatesessionhome;
170     private boolean initialized;
171     private Admin administrator;
172     private String JavaDoc username = "";
173     private UserDataVO useradmindata = null;
174 }
175
Popular Tags