KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > web > admin > cainterface > PublisherDataHandler


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 package org.ejbca.ui.web.admin.cainterface;
15
16 import java.io.Serializable JavaDoc;
17
18 import org.ejbca.core.ejb.authorization.IAuthorizationSessionLocal;
19 import org.ejbca.core.ejb.ca.caadmin.ICAAdminSessionLocal;
20 import org.ejbca.core.ejb.ca.publisher.IPublisherSessionLocal;
21 import org.ejbca.core.ejb.ca.store.ICertificateStoreSessionLocal;
22 import org.ejbca.core.model.authorization.AuthorizationDeniedException;
23 import org.ejbca.core.model.authorization.AvailableAccessRules;
24 import org.ejbca.core.model.ca.publisher.BasePublisher;
25 import org.ejbca.core.model.ca.publisher.PublisherConnectionException;
26 import org.ejbca.core.model.ca.publisher.PublisherExistsException;
27 import org.ejbca.core.model.log.Admin;
28 import org.ejbca.ui.web.admin.configuration.InformationMemory;
29
30 /**
31  * A class handling the hardtoken profile data in the webinterface.
32  *
33  * @author TomSelleck
34  * @version $Id: PublisherDataHandler.java,v 1.1 2006/01/17 20:28:08 anatom Exp $
35  */

36 public class PublisherDataHandler implements Serializable JavaDoc {
37
38     
39     
40     /** Creates a new instance of PublisherDataHandler */
41     public PublisherDataHandler(Admin administrator, IPublisherSessionLocal publishersession, IAuthorizationSessionLocal authorizationsession,
42                                 ICAAdminSessionLocal caadminsession,ICertificateStoreSessionLocal certificatestoresession, InformationMemory info) {
43        this.publishersession = publishersession;
44        this.authorizationsession = authorizationsession;
45        this.caadminsession = caadminsession;
46        this.certificatestoresession = certificatestoresession;
47        this.administrator = administrator;
48        this.info = info;
49     }
50     
51        /** Method to add a publisher. Throws PublisherExitsException if profile already exists */
52     public void addPublisher(String JavaDoc name, BasePublisher publisher) throws PublisherExistsException, AuthorizationDeniedException {
53       if(authorizedToEditPublishers()){
54         publishersession.addPublisher(administrator, name, publisher);
55         this.info.publishersEdited();
56       }else
57         throw new AuthorizationDeniedException("Not authorized to add publisher");
58     }
59
60        /** Method to change a publisher. */
61     public void changePublisher(String JavaDoc name, BasePublisher publisher) throws AuthorizationDeniedException{
62       if(authorizedToEditPublishers()){
63         publishersession.changePublisher(administrator, name,publisher);
64         this.info.publishersEdited();
65       }else
66         throw new AuthorizationDeniedException("Not authorized to edit publisher");
67     }
68     
69     /** Method to remove a publisher, returns true if deletion failed.*/
70     public boolean removePublisher(String JavaDoc name) throws AuthorizationDeniedException{
71       boolean returnval = true;
72
73       if(authorizedToEditPublishers()){
74         int publisherid = publishersession.getPublisherId(administrator, name);
75         if(!caadminsession.exitsPublisherInCAs(administrator, publisherid) && !certificatestoresession.existsPublisherInCertificateProfiles(administrator,publisherid)){
76           publishersession.removePublisher(administrator, name);
77           this.info.publishersEdited();
78           returnval = false;
79         }
80       }else
81         throw new AuthorizationDeniedException("Not authorized to remove publisher.");
82         
83       return returnval;
84     }
85     
86     /** Metod to rename a publisher */
87     public void renamePublisher(String JavaDoc oldname, String JavaDoc newname) throws PublisherExistsException, AuthorizationDeniedException{
88      if(authorizedToEditPublishers()){
89         publishersession.renamePublisher(administrator, oldname,newname);
90        this.info.publishersEdited();
91      }else
92        throw new AuthorizationDeniedException("Not authorized to rename publisher");
93     }
94     
95
96     public void clonePublisher(String JavaDoc originalname, String JavaDoc newname) throws AuthorizationDeniedException{
97       if(authorizedToEditPublishers()){
98         publishersession.clonePublisher(administrator, originalname,newname);
99         this.info.publishersEdited();
100       }else
101          throw new AuthorizationDeniedException("Not authorized to clone publisher");
102     }
103     
104     public void testConnection(String JavaDoc name) throws PublisherConnectionException, AuthorizationDeniedException{
105         if(authorizedToPublisherName(name)){
106             publishersession.testConnection(administrator, publishersession.getPublisherId(administrator, name));
107         }else
108             throw new AuthorizationDeniedException("Not authorized to clone publisher");
109     }
110     
111       /** Method to get a reference to a publisher.*/
112     public BasePublisher getPublisher(int id) throws AuthorizationDeniedException{
113       if(!authorizedToPublisherId(id))
114         throw new AuthorizationDeniedException("Not authorized to publisher");
115       
116       return publishersession.getPublisher(administrator, id);
117     }
118           
119     public BasePublisher getPublisher(String JavaDoc name) throws AuthorizationDeniedException{
120      if(!authorizedToPublisherName(name))
121         throw new AuthorizationDeniedException("Not authorized to publisher");
122          
123       return publishersession.getPublisher(administrator, name);
124     }
125    
126       
127     public int getPublisherId(String JavaDoc name){
128       return publishersession.getPublisherId(administrator, name);
129     }
130     
131     
132     /**
133      * Help function that checks if administrator is authorized to edit publisher with given name.
134      */

135     private boolean authorizedToPublisherName(String JavaDoc name){
136       int id = publishersession.getPublisherId(administrator, name);
137       return authorizedToPublisherId(id);
138     }
139      
140     
141     /**
142      * Help function that checks if administrator is authorized to edit publisher with given id.
143      */

144     private boolean authorizedToPublisherId(int id){
145       return info.getAuthorizedPublisherNames().values().contains(new Integer JavaDoc(id));
146     }
147     
148     /**
149      * Help function that checks if administrator is authorized to edit publisher.
150      */

151     private boolean authorizedToEditPublishers(){
152         try{
153           authorizationsession.isAuthorizedNoLog(administrator, AvailableAccessRules.ROLE_SUPERADMINISTRATOR);
154           return true;
155         }catch(AuthorizationDeniedException ade){}
156               
157        return false;
158     }
159    
160     private IPublisherSessionLocal publishersession;
161     private Admin administrator;
162     private IAuthorizationSessionLocal authorizationsession;
163     private ICAAdminSessionLocal caadminsession;
164     private ICertificateStoreSessionLocal certificatestoresession;
165     private InformationMemory info;
166 }
167
Popular Tags