Example usage for javax.ejb FinderException FinderException

List of usage examples for javax.ejb FinderException FinderException

Introduction

In this page you can find the example usage for javax.ejb FinderException FinderException.

Prototype

public FinderException(String message) 

Source Link

Document

Constructs an FinderException with the specified detail message.

Usage

From source file:org.ejbca.core.ejb.ra.UserAdminSessionBean.java

@Override
public void resetRemainingLoginAttempts(Admin admin, String username)
        throws AuthorizationDeniedException, FinderException {
    if (log.isTraceEnabled()) {
        log.trace(">resetRamainingLoginAttempts(" + username + ")");
    }/*from www . j av  a 2  s . c  o m*/
    int resetValue = -1;
    int caid = LogConstants.INTERNALCAID;
    final UserData data1 = UserData.findByUsername(entityManager, username);
    if (data1 != null) {
        caid = data1.getCaId();
        assertAuthorizedToCA(admin, caid, username, LogConstants.EVENT_INFO_CHANGEDENDENTITY);
        final ExtendedInformation ei = data1.getExtendedInformation();
        if (ei != null) {
            resetRemainingLoginAttemptsInternal(admin, ei, username, caid);
            data1.setTimeModified(new Date().getTime());
            data1.setExtendedInformation(ei);
        }
    } else {
        String msg = intres.getLocalizedMessage("ra.errorentitynotexist", username);
        logSession.log(admin, caid, LogConstants.MODULE_RA, new Date(), username, null,
                LogConstants.EVENT_INFO_CHANGEDENDENTITY, msg);
        throw new FinderException(msg);
    }
    if (log.isTraceEnabled()) {
        log.trace("<resetRamainingLoginAttempts(" + username + "): " + resetValue);
    }
}

From source file:org.ejbca.core.ejb.ra.UserAdminSessionBean.java

@Override
public void decRemainingLoginAttempts(Admin admin, String username)
        throws AuthorizationDeniedException, FinderException {
    if (log.isTraceEnabled()) {
        log.trace(">decRemainingLoginAttempts(" + username + ")");
    }/*  w  w w  .java2s. c o m*/
    int caid = LogConstants.INTERNALCAID;
    int counter = Integer.MAX_VALUE;
    UserData data1 = UserData.findByUsername(entityManager, username);
    if (data1 != null) {
        caid = data1.getCaId();
        assertAuthorizedToCA(admin, caid, username, LogConstants.EVENT_INFO_CHANGEDENDENTITY);
        final ExtendedInformation ei = data1.getExtendedInformation();
        if (ei != null) {
            counter = ei.getRemainingLoginAttempts();
            // If we get to 0 we must set status to generated
            if (counter == 0) {
                // if it isn't already
                if (data1.getStatus() != UserDataConstants.STATUS_GENERATED) {
                    data1.setStatus(UserDataConstants.STATUS_GENERATED);
                    final String msg = intres.getLocalizedMessage("ra.decreasedloginattemptscounter", username,
                            counter);
                    logSession.log(admin, caid, LogConstants.MODULE_RA, new Date(), username, null,
                            LogConstants.EVENT_INFO_CHANGEDENDENTITY, msg);
                    resetRemainingLoginAttemptsInternal(admin, ei, username, caid);
                    data1.setTimeModified(new Date().getTime());
                    data1.setExtendedInformation(ei);
                }
            } else if (counter != -1) {
                if (log.isDebugEnabled()) {
                    log.debug("Found a remaining login counter with value " + counter);
                }
                ei.setRemainingLoginAttempts(--counter);
                data1.setExtendedInformation(ei);
                String msg = intres.getLocalizedMessage("ra.decreasedloginattemptscounter", username, counter);
                logSession.log(admin, caid, LogConstants.MODULE_RA, new Date(), username, null,
                        LogConstants.EVENT_INFO_CHANGEDENDENTITY, msg);
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Found a remaining login counter with value UNLIMITED, not decreased in db.");
                }
                counter = Integer.MAX_VALUE;
            }
        }
    } else {
        String msg = intres.getLocalizedMessage("ra.errorentitynotexist", username);
        logSession.log(admin, caid, LogConstants.MODULE_RA, new Date(), username, null,
                LogConstants.EVENT_INFO_CHANGEDENDENTITY, msg);
        throw new FinderException(msg);
    }
    if (log.isTraceEnabled()) {
        log.trace("<decRemainingLoginAttempts(" + username + "): " + counter);
    }
}

From source file:org.ejbca.core.ejb.ra.UserAdminSessionBean.java

@Override
public int decRequestCounter(Admin admin, String username)
        throws AuthorizationDeniedException, FinderException, ApprovalException, WaitingForApprovalException {
    if (log.isTraceEnabled()) {
        log.trace(">decRequestCounter(" + username + ")");
    }//from w  w w.ja va2  s  .c o  m
    // Default return value is as if the optional value does not exist for
    // the user, i.e. the default values is 0
    // because the default number of allowed requests are 1
    int counter = 0;
    // Check if administrator is authorized to edit user.
    int caid = LogConstants.INTERNALCAID;
    UserData data1 = UserData.findByUsername(entityManager, username);
    if (data1 != null) {
        caid = data1.getCaId();
        assertAuthorizedToCA(admin, caid, username, LogConstants.EVENT_INFO_CHANGEDENDENTITY);
        if (getGlobalConfiguration(admin).getEnableEndEntityProfileLimitations()) {
            assertAuthorizedToEndEntityProfile(admin, data1.getEndEntityProfileId(),
                    AccessRulesConstants.EDIT_RIGHTS, caid, username, LogConstants.EVENT_INFO_CHANGEDENDENTITY);
        }
        // Do the work of decreasing the counter
        ExtendedInformation ei = data1.getExtendedInformation();
        if (ei != null) {
            String counterstr = ei.getCustomData(ExtendedInformation.CUSTOM_REQUESTCOUNTER);
            boolean serialNumberCleared = false;
            if (StringUtils.isNotEmpty(counterstr)) {
                try {
                    counter = Integer.valueOf(counterstr);
                    if (log.isDebugEnabled()) {
                        log.debug("Found a counter with value " + counter);
                    }
                    // decrease the counter, if we get to 0 we must set
                    // status to generated
                    counter--;
                    if (counter >= 0) {
                        ei.setCustomData(ExtendedInformation.CUSTOM_REQUESTCOUNTER, String.valueOf(counter));
                        ei.setCertificateSerialNumber(null);// cert serial number should also be cleared after successful command.
                        data1.setExtendedInformation(ei);
                        serialNumberCleared = true;
                        final Date now = new Date();
                        if (counter > 0) { // if 0 then update when changing type
                            data1.setTimeModified(now.getTime());
                        }
                        String msg = intres.getLocalizedMessage("ra.decreasedentityrequestcounter", username,
                                counter);
                        logSession.log(admin, caid, LogConstants.MODULE_RA, now, username, null,
                                LogConstants.EVENT_INFO_CHANGEDENDENTITY, msg);
                    } else {
                        if (log.isDebugEnabled()) {
                            log.debug("Counter value was already 0, not decreased in db.");
                        }
                    }
                } catch (NumberFormatException e) {
                    String msg = intres.getLocalizedMessage("ra.errorrequestcounterinvalid", username,
                            counterstr, e.getMessage());
                    log.error(msg, e);
                }
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("No (optional) request counter exists for end entity: " + username);
                }
            }
            if (!serialNumberCleared && ei.certificateSerialNumber() != null) {
                ei.setCertificateSerialNumber(null);// cert serial number should also be cleared after successful command.
                data1.setExtendedInformation(ei);
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("No extended information exists for user: " + data1.getUsername());
            }
        }
    } else {
        String msg = intres.getLocalizedMessage("ra.errorentitynotexist", username);
        logSession.log(admin, caid, LogConstants.MODULE_RA, new Date(), username, null,
                LogConstants.EVENT_INFO_CHANGEDENDENTITY, msg);
        throw new FinderException(msg);
    }
    if (counter <= 0) {
        setUserStatus(admin, data1, UserDataConstants.STATUS_GENERATED);
    }
    if (log.isTraceEnabled()) {
        log.trace("<decRequestCounter(" + username + "): " + counter);
    }
    return counter;
}

From source file:org.ejbca.core.ejb.ra.UserAdminSessionBean.java

@Override
public void cleanUserCertDataSN(Admin admin, String username)
        throws AuthorizationDeniedException, FinderException, ApprovalException, WaitingForApprovalException {
    if (log.isTraceEnabled()) {
        log.trace(">cleanUserCertDataSN(" + username + ")");
    }/*from  ww  w . j  a  v a  2  s  .co  m*/
    final int caid = LogConstants.INTERNALCAID;
    try {
        // Check if administrator is authorized to edit user.
        UserData data1 = UserData.findByUsername(entityManager, username);
        if (data1 != null) {
            assertAuthorizedToCA(admin, caid, username, LogConstants.EVENT_INFO_CHANGEDENDENTITY);
            if (getGlobalConfiguration(admin).getEnableEndEntityProfileLimitations()) {
                assertAuthorizedToEndEntityProfile(admin, data1.getEndEntityProfileId(),
                        AccessRulesConstants.EDIT_RIGHTS, caid, username,
                        LogConstants.EVENT_INFO_CHANGEDENDENTITY);
            }
            final ExtendedInformation ei = data1.getExtendedInformation();
            if (ei == null) {
                if (log.isDebugEnabled()) {
                    log.debug("No extended information exists for user: " + data1.getUsername());
                }
            } else {
                ei.setCertificateSerialNumber(null);
                data1.setExtendedInformation(ei);
            }
        } else {
            String msg = intres.getLocalizedMessage("ra.errorentitynotexist", username);
            logSession.log(admin, caid, LogConstants.MODULE_RA, new Date(), username, null,
                    LogConstants.EVENT_INFO_CHANGEDENDENTITY, msg);
            throw new FinderException(msg);
        }
    } finally {
        if (log.isTraceEnabled()) {
            log.trace("<cleanUserCertDataSN(" + username + ")");
        }
    }
}

From source file:org.ejbca.core.ejb.ra.UserAdminSessionBean.java

@Override
public void setUserStatus(final Admin admin, final String username, final int status)
        throws AuthorizationDeniedException, FinderException, ApprovalException, WaitingForApprovalException {
    if (log.isTraceEnabled()) {
        log.trace(">setUserStatus(" + username + ", " + status + ")");
    }// w  w w.j  av  a  2  s  .  c  o  m
    // Check if administrator is authorized to edit user.
    final UserData data = UserData.findByUsername(entityManager, username);
    if (data == null) {
        final String msg = intres.getLocalizedMessage("ra.errorentitynotexist", username);
        logSession.log(admin, LogConstants.INTERNALCAID, LogConstants.MODULE_RA, new Date(), username, null,
                LogConstants.EVENT_INFO_CHANGEDENDENTITY, msg);
        throw new FinderException(msg);
    }
    // Check authorization
    final int caid = data.getCaId();
    assertAuthorizedToCA(admin, caid, username, LogConstants.EVENT_INFO_CHANGEDENDENTITY);
    if (getGlobalConfiguration(admin).getEnableEndEntityProfileLimitations()) {
        assertAuthorizedToEndEntityProfile(admin, data.getEndEntityProfileId(),
                AccessRulesConstants.EDIT_RIGHTS, caid, username, LogConstants.EVENT_INFO_CHANGEDENDENTITY);
    }
    setUserStatus(admin, data, status);
}

From source file:org.ejbca.core.ejb.ra.UserAdminSessionBean.java

/**
 * Sets a password, hashed or clear text, for a user.
 * /*ww  w  .  j ava2  s . co  m*/
 * @param admin the administrator pwrforming the action
 * @param username the unique username.
 * @param password the new password to be stored in clear text. Setting
 *            password to 'null' effectively deletes any previous clear
 *            text password.
 * @param cleartext true gives cleartext password, false hashed
 */
private void setPassword(final Admin admin, final String username, final String password,
        final boolean cleartext)
        throws UserDoesntFullfillEndEntityProfile, AuthorizationDeniedException, FinderException {
    if (log.isTraceEnabled()) {
        log.trace(">setPassword(" + username + ", hiddenpwd), " + cleartext);
    }
    // Find user
    String newpasswd = password;
    final UserData data = UserData.findByUsername(entityManager, username);
    if (data == null) {
        throw new FinderException("Could not find user " + username);
    }
    final int caid = data.getCaId();
    final String dn = data.getSubjectDN();
    final int endEntityProfileId = data.getEndEntityProfileId();

    final EndEntityProfile profile = endEntityProfileSession.getEndEntityProfile(admin, endEntityProfileId);

    if (profile.useAutoGeneratedPasswd()) {
        newpasswd = profile.getAutoGeneratedPasswd();
    }
    if (getGlobalConfiguration(admin).getEnableEndEntityProfileLimitations()) {
        // Check if user fulfills it's profile.
        try {
            profile.doesPasswordFulfillEndEntityProfile(password, true);
        } catch (UserDoesntFullfillEndEntityProfile ufe) {
            final String msg = intres.getLocalizedMessage("ra.errorfullfillprofile",
                    Integer.valueOf(endEntityProfileId), dn, ufe.getMessage());
            logSession.log(admin, caid, LogConstants.MODULE_RA, new Date(), username, null,
                    LogConstants.EVENT_INFO_CHANGEDENDENTITY, msg);
            throw ufe;
        }
        // Check if administrator is authorized to edit user.
        assertAuthorizedToEndEntityProfile(admin, data.getEndEntityProfileId(),
                AccessRulesConstants.EDIT_RIGHTS, caid, username, LogConstants.EVENT_INFO_CHANGEDENDENTITY);
    }
    assertAuthorizedToCA(admin, caid, username, LogConstants.EVENT_INFO_CHANGEDENDENTITY);
    try {
        final Date now = new Date();
        if ((newpasswd == null) && (cleartext)) {
            data.setClearPassword("");
            data.setTimeModified(now.getTime());
        } else {
            if (cleartext) {
                data.setOpenPassword(newpasswd);
            } else {
                data.setPassword(newpasswd);
            }
            data.setTimeModified(now.getTime());
        }
        final String msg = intres.getLocalizedMessage("ra.editpwdentity", username);
        logSession.log(admin, caid, LogConstants.MODULE_RA, now, username, null,
                LogConstants.EVENT_INFO_CHANGEDENDENTITY, msg);
    } catch (NoSuchAlgorithmException nsae) {
        log.error("NoSuchAlgorithmException while setting password for user " + username);
        throw new EJBException(nsae);
    }
    if (log.isTraceEnabled()) {
        log.trace("<setPassword(" + username + ", hiddenpwd), " + cleartext);
    }
}

From source file:org.ejbca.core.ejb.ra.UserAdminSessionBean.java

@Override
public boolean verifyPassword(Admin admin, String username, String password)
        throws UserDoesntFullfillEndEntityProfile, AuthorizationDeniedException, FinderException {
    if (log.isTraceEnabled()) {
        log.trace(">verifyPassword(" + username + ", hiddenpwd)");
    }/*from ww  w .jav a 2  s  . c  o m*/
    boolean ret = false;
    // Find user
    UserData data = UserData.findByUsername(entityManager, username);
    if (data == null) {
        throw new FinderException("Could not find user " + username);
    }
    int caid = data.getCaId();
    if (getGlobalConfiguration(admin).getEnableEndEntityProfileLimitations()) {
        // Check if administrator is authorized to edit user.
        assertAuthorizedToEndEntityProfile(admin, data.getEndEntityProfileId(),
                AccessRulesConstants.EDIT_RIGHTS, caid, username, LogConstants.EVENT_INFO_CHANGEDENDENTITY);
    }
    assertAuthorizedToCA(admin, caid, username, LogConstants.EVENT_INFO_CHANGEDENDENTITY);
    try {
        ret = data.comparePassword(password);
    } catch (NoSuchAlgorithmException nsae) {
        log.debug("NoSuchAlgorithmException while verifying password for user " + username);
        throw new EJBException(nsae);
    }
    if (log.isTraceEnabled()) {
        log.trace("<verifyPassword(" + username + ", hiddenpwd)");
    }
    return ret;
}

From source file:org.ejbca.core.ejb.ra.UserAdminSessionBean.java

@Override
public void revokeUser(Admin admin, String username, int reason) throws AuthorizationDeniedException,
        FinderException, ApprovalException, WaitingForApprovalException, AlreadyRevokedException {
    if (log.isTraceEnabled()) {
        log.trace(">revokeUser(" + username + ")");
    }/*w  w w. j  a v  a2 s . co m*/
    final UserData userData = UserData.findByUsername(entityManager, username);
    if (userData == null) {
        throw new FinderException("Could not find user " + username);
    }
    final int caid = userData.getCaId();
    assertAuthorizedToCA(admin, caid, username, LogConstants.EVENT_ERROR_REVOKEDENDENTITY);
    if (getGlobalConfiguration(admin).getEnableEndEntityProfileLimitations()) {
        assertAuthorizedToEndEntityProfile(admin, userData.getEndEntityProfileId(),
                AccessRulesConstants.REVOKE_RIGHTS, caid, username, LogConstants.EVENT_ERROR_REVOKEDENDENTITY);
    }
    if (userData.getStatus() == UserDataConstants.STATUS_REVOKED) {
        final String msg = intres.getLocalizedMessage("ra.errorbadrequest",
                Integer.valueOf(userData.getEndEntityProfileId()));
        logSession.log(admin, caid, LogConstants.MODULE_RA, new Date(), username, null,
                LogConstants.EVENT_INFO_REVOKEDENDENTITY, msg);
        throw new AlreadyRevokedException(msg);
    }
    // Check if approvals is required.
    final int numOfReqApprovals = getNumOfApprovalRequired(admin, CAInfo.REQ_APPROVAL_REVOCATION, caid,
            userData.getCertificateProfileId());
    if (numOfReqApprovals > 0) {
        final RevocationApprovalRequest ar = new RevocationApprovalRequest(false, username, reason, admin,
                numOfReqApprovals, caid, userData.getEndEntityProfileId());
        if (ApprovalExecutorUtil.requireApproval(ar, NONAPPROVABLECLASSNAMES_REVOKEUSER)) {
            approvalSession.addApprovalRequest(admin, ar, getGlobalConfiguration(admin));
            throw new WaitingForApprovalException(intres.getLocalizedMessage("ra.approvalrevoke"));
        }
    }
    // Revoke all certs, one at the time
    final Collection<Certificate> certs = certificateStoreSession.findCertificatesByUsername(admin, username);
    for (final Certificate cert : certs) {
        try {
            revokeCert(admin, CertTools.getSerialNumber(cert), CertTools.getIssuerDN(cert), reason);
        } catch (AlreadyRevokedException e) {
            if (log.isDebugEnabled()) {
                log.debug("Certificate from issuer '" + CertTools.getIssuerDN(cert) + "' with serial "
                        + CertTools.getSerialNumber(cert) + " was already revoked.");
            }
        }
    }
    // Finally set revoke status on the user as well
    try {
        setUserStatus(admin, userData, UserDataConstants.STATUS_REVOKED);
    } catch (ApprovalException e) {
        throw new EJBException("This should never happen", e);
    } catch (WaitingForApprovalException e) {
        throw new EJBException("This should never happen", e);
    }
    final String msg = intres.getLocalizedMessage("ra.revokedentity", username);
    logSession.log(admin, caid, LogConstants.MODULE_RA, new Date(), username, null,
            LogConstants.EVENT_INFO_REVOKEDENDENTITY, msg);
    if (log.isTraceEnabled()) {
        log.trace("<revokeUser()");
    }
}

From source file:org.ejbca.core.ejb.ra.UserAdminSessionBean.java

@Override
public void revokeCert(Admin admin, BigInteger certserno, Date revocationdate, String issuerdn, int reason,
        boolean checkDate) throws AuthorizationDeniedException, FinderException, WaitingForApprovalException,
        RevokeBackDateNotAllowedForProfileException, AlreadyRevokedException, ApprovalException {
    if (log.isTraceEnabled()) {
        log.trace(">revokeCert(" + certserno.toString(16) + ", IssuerDN: " + issuerdn + ")");
    }//from   ww w . j a  v a  2  s  .  c  om
    // Check that the admin has revocation rights.
    if (!authorizationSession.isAuthorizedNoLog(admin, AccessRulesConstants.REGULAR_REVOKEENDENTITY)) {
        Authorizer.throwAuthorizationException(admin, AccessRulesConstants.REGULAR_REVOKEENDENTITY, null);
    }
    // To be fully backwards compatible we just use the first fingerprint found..
    final CertificateInfo info = certificateStoreSession.findFirstCertificateInfo(issuerdn, certserno);
    if (info == null) {
        final String msg = intres.getLocalizedMessage("ra.errorfindentitycert", issuerdn,
                certserno.toString(16));
        logSession.log(admin, LogConstants.INTERNALCAID, LogConstants.MODULE_RA, new Date(), null, null,
                LogConstants.EVENT_INFO_REVOKEDENDENTITY, msg);
        throw new FinderException(msg);
    }
    final int caid = info.getIssuerDN().hashCode();
    final String username = info.getUsername();
    assertAuthorizedToCA(admin, caid, username, LogConstants.EVENT_ERROR_REVOKEDENDENTITY);
    int certificateProfileId = info.getCertificateProfileId();
    String userDataDN = info.getSubjectDN();
    final CertReqHistory certReqHistory = certificateStoreSession.getCertReqHistory(admin, certserno, issuerdn);
    UserData data = null;
    if (certReqHistory == null || XkmsConfiguration.getEnabled()) {
        // We could use userdata later, so try to find it
        data = UserData.findByUsername(entityManager, username);
    }
    int endEntityProfileId = -1;
    if (certReqHistory != null) {
        // Get the EEP that was used in the original issuance, if we can find it
        endEntityProfileId = certReqHistory.getUserDataVO().getEndEntityProfileId();
        // Republish with the same user DN that was used in the original publication, if we can find it
        userDataDN = certReqHistory.getUserDataVO().getCertificateDN();
        // If for some reason the certificate profile id was not set in the certificate data, try to get it from the certreq history
        if (certificateProfileId == SecConst.CERTPROFILE_NO_PROFILE) {
            certificateProfileId = certReqHistory.getUserDataVO().getCertificateProfileId();
        }
    } else if (data != null) {
        // Get the EEP that is currently used as a fallback, if we can find it
        endEntityProfileId = data.getEndEntityProfileId();
        // Republish with the same user DN that is currently used as a fallback, if we can find it
        userDataDN = data.toUserDataVO().getCertificateDN();
        // If for some reason the certificate profile id was not set in the certificate data, try to get it from current userdata
        if (certificateProfileId == SecConst.CERTPROFILE_NO_PROFILE) {
            certificateProfileId = data.getCertificateProfileId();
        }
    }
    if (endEntityProfileId != -1) {
        // We can only perform this check if we have a trail of what eep was used..
        if (getGlobalConfiguration(admin).getEnableEndEntityProfileLimitations()) {
            assertAuthorizedToEndEntityProfile(admin, endEntityProfileId, AccessRulesConstants.REVOKE_RIGHTS,
                    caid, username, LogConstants.EVENT_ERROR_REVOKEDENDENTITY);
        }
    }
    // Check that unrevocation is not done on anything that can not be unrevoked
    if (reason == RevokedCertInfo.NOT_REVOKED || reason == RevokedCertInfo.REVOCATION_REASON_REMOVEFROMCRL) {
        if (info.getRevocationReason() != RevokedCertInfo.REVOCATION_REASON_CERTIFICATEHOLD) {
            final String msg = intres.getLocalizedMessage("ra.errorunrevokenotonhold", issuerdn,
                    certserno.toString(16));
            logSession.log(admin, caid, LogConstants.MODULE_RA, new Date(), username, null,
                    LogConstants.EVENT_INFO_REVOKEDENDENTITY, msg);
            throw new AlreadyRevokedException(msg);
        }
    } else {
        if (info.getRevocationReason() != RevokedCertInfo.NOT_REVOKED &&
        // a valid certificate could have reason "REVOCATION_REASON_REMOVEFROMCRL" if it has been revoked in the past.
                info.getRevocationReason() != RevokedCertInfo.REVOCATION_REASON_REMOVEFROMCRL) {
            final String msg = intres.getLocalizedMessage("ra.errorrevocationexists");
            logSession.log(admin, caid, LogConstants.MODULE_RA, new Date(), username, null,
                    LogConstants.EVENT_INFO_REVOKEDENDENTITY, msg);
            throw new AlreadyRevokedException(msg);
        }
    }
    if (endEntityProfileId != -1 && certificateProfileId != SecConst.CERTPROFILE_NO_PROFILE) {
        // We can only perform this check if we have a trail of what eep and cp was used..
        // Check if approvals is required.
        final int numOfReqApprovals = getNumOfApprovalRequired(admin, CAInfo.REQ_APPROVAL_REVOCATION, caid,
                certificateProfileId);
        if (numOfReqApprovals > 0) {
            final RevocationApprovalRequest ar = new RevocationApprovalRequest(certserno, issuerdn, username,
                    reason, admin, numOfReqApprovals, caid, endEntityProfileId);
            if (ApprovalExecutorUtil.requireApproval(ar, NONAPPROVABLECLASSNAMES_REVOKECERT)) {
                approvalSession.addApprovalRequest(admin, ar, getGlobalConfiguration(admin));
                throw new WaitingForApprovalException(intres.getLocalizedMessage("ra.approvalrevoke"));
            }
        }
    }
    // Finally find the publishers for the certificate profileId that we found
    Collection<Integer> publishers = new ArrayList<Integer>(0);
    final CertificateProfile certificateProfile = certificateProfileSession.getCertificateProfile(admin,
            certificateProfileId);
    if (certificateProfile != null) {
        publishers = certificateProfile.getPublisherList();
        if (publishers == null || publishers.size() == 0) {
            if (log.isDebugEnabled()) {
                log.debug("No publishers defined for certificate with serial #" + certserno.toString(16)
                        + " issued by " + issuerdn);
            }
        }
    } else {
        log.warn("No certificate profile for certificate with serial #" + certserno.toString(16) + " issued by "
                + issuerdn);
    }
    if (checkDate && revocationdate != null
            && (certificateProfile == null || !certificateProfile.getAllowBackdatedRevocation())) {
        final String profileName = this.certificateProfileSession.getCertificateProfileName(admin,
                certificateProfileId);
        final String m = intres.getLocalizedMessage("ra.norevokebackdate", profileName, certserno.toString(16),
                issuerdn);
        throw new RevokeBackDateNotAllowedForProfileException(m);
    }
    // Revoke certificate in database and all publishers
    this.certificateStoreSession.setRevokeStatus(admin, issuerdn, certserno,
            revocationdate != null ? revocationdate : new Date(), publishers, reason, userDataDN);
    if (XkmsConfiguration.getEnabled() && data != null) {
        // Reset the revocation code identifier used in XKMS
        final ExtendedInformation inf = data.getExtendedInformation();
        if (inf != null && inf.getRevocationCodeIdentifier() != null) {
            inf.setRevocationCodeIdentifier(null);
            data.setExtendedInformation(inf);
        }
    }
    if (log.isTraceEnabled()) {
        log.trace("<revokeCert()");
    }
}

From source file:org.ejbca.core.ejb.services.ServiceSessionBean.java

@TransactionAttribute(TransactionAttributeType.SUPPORTS)
@Override// w  w w  .ja  v a  2  s  .  c  o  m
public boolean removeService(AuthenticationToken admin, String name) {
    if (log.isTraceEnabled()) {
        log.trace(">removeService(name: " + name + ")");
    }
    boolean retval = false;
    try {
        ServiceData htp = serviceDataSession.findByName(name);
        if (htp == null) {
            throw new FinderException("Cannot find service " + name);
        }
        ServiceConfiguration serviceConfiguration = htp.getServiceConfiguration();
        if (isAuthorizedToEditService(admin)) {
            IWorker worker = getWorker(serviceConfiguration, name, htp.getRunTimeStamp(),
                    htp.getNextRunTimeStamp());
            if (worker != null) {
                serviceSession.cancelTimer(htp.getId());
            }
            serviceDataSession.removeServiceData(htp.getId());
            final String msg = intres.getLocalizedMessage("services.serviceremoved", name);
            final Map<String, Object> details = new LinkedHashMap<String, Object>();
            details.put("msg", msg);
            auditSession.log(EjbcaEventTypes.SERVICE_REMOVE, EventStatus.SUCCESS, EjbcaModuleTypes.SERVICE,
                    EjbcaServiceTypes.EJBCA, admin.toString(), null, null, null, details);
            retval = true;
        } else {
            final String msg = intres.getLocalizedMessage("services.notauthorizedtoedit", name);
            log.info(msg);
        }
    } catch (Exception e) {
        final String msg = intres.getLocalizedMessage("services.errorremovingservice", name);
        final Map<String, Object> details = new LinkedHashMap<String, Object>();
        details.put("msg", msg);
        details.put("error", e.getMessage());
        auditSession.log(EjbcaEventTypes.SERVICE_REMOVE, EventStatus.FAILURE, EjbcaModuleTypes.SERVICE,
                EjbcaServiceTypes.EJBCA, admin.toString(), null, null, null, details);
    }
    log.trace("<removeService)");
    return retval;
}