CADataLocal cadata = cadatahome.findByPrimaryKey(new Integer(caid)); if(cadata.getStatus() == SecConst.CA_ACTIVE){ try { cadata.getCA().getCAToken().deactivate(); cadata.setStatus(SecConst.CA_OFFLINE); getLogSession().log(admin, caid, LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_INFO_CAEDITED,"CA " + cadata.getName() + "have been deactivated successfully."); } catch (IllegalKeyStoreException e) { throw new EJBException(e); } catch (UnsupportedEncodingException e) { throw new EJBException(e); } }else{ getLogSession().log(admin, caid, LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CAEDITED,"Error when trying to deactivate CA  " + cadata.getName() + ". CA is not active"); throw new EjbcaException("Wrong user status of CA."); }
    public void deactivateCAToken(Admin admin, int caid) throws AuthorizationDeniedException, EjbcaException{       // Authorize        try{            getAuthorizationSession().isAuthorizedNoLog(admin,AvailableAccessRules.REGULAR_ACTIVATECA);        }catch(AuthorizationDeniedException ade){            getLogSession().log (admin, caid, LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_NOTAUTHORIZEDTORESOURCE,"Administrator isn't authorized to deactivate CA token.",ade);            throw new AuthorizationDeniedException("Administrator not authorized to deactivate CA token.");        }    	try{    		if(caid >=0 && caid <= CAInfo.SPECIALCAIDBORDER){                // This should never happen.    			getLogSession().log(admin, caid, LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CAEDITED,"Error when trying to deactivate CA with caid " + caid + ". CA deactivation not available.");    			throw new EjbcaException("Error when trying to deactivate CA with caid " + caid + ". CA deactivation not available.");    		}else{    			CADataLocal cadata = cadatahome.findByPrimaryKey(new Integer(caid));    			if(cadata.getStatus() == SecConst.CA_ACTIVE){    				try {    					cadata.getCA().getCAToken().deactivate();    					cadata.setStatus(SecConst.CA_OFFLINE);    					getLogSession().log(admin, caid, LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_INFO_CAEDITED,"CA " + cadata.getName() + "have been deactivated successfully.");    				} catch (IllegalKeyStoreException e) {    					throw new EJBException(e);    				} catch (UnsupportedEncodingException e) {    					throw new EJBException(e);    				}    			}else{    				getLogSession().log(admin, caid, LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CAEDITED,"Error when trying to deactivate CA  " + cadata.getName() + ". CA is not active");    				throw new EjbcaException("Wrong user status of CA.");    			}    		}    	}catch(javax.ejb.FinderException fe) {    	   getLogSession().log(admin, caid, LogEntry.MODULE_CA,  new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CAEDITED,"Error when trying to deactivate CA with caid " + caid + ". CA could not be found.");    	   throw new EJBException(fe);    	}    }