1 13 14 package org.ejbca.ui.web.admin.cainterface; 15 16 import java.io.Serializable ; 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 36 public class PublisherDataHandler implements Serializable { 37 38 39 40 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 52 public void addPublisher(String 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 61 public void changePublisher(String 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 70 public boolean removePublisher(String 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 87 public void renamePublisher(String oldname, String 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 originalname, String 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 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 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 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 name){ 128 return publishersession.getPublisherId(administrator, name); 129 } 130 131 132 135 private boolean authorizedToPublisherName(String name){ 136 int id = publishersession.getPublisherId(administrator, name); 137 return authorizedToPublisherId(id); 138 } 139 140 141 144 private boolean authorizedToPublisherId(int id){ 145 return info.getAuthorizedPublisherNames().values().contains(new Integer (id)); 146 } 147 148 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 |