@Override
public void revokeAndDeleteUser(Admin admin, String username, int reason) throws AuthorizationDeniedException, ApprovalException,
WaitingForApprovalException, RemoveException, NotFoundException {
final UserData data = UserData.findByUsername(entityManager, username);
if (data == null) {
throw new NotFoundException("User '" + username + "' not found.");
}
// Authorized?
final int caid = data.getCaId();
assertAuthorizedToCA(admin, caid, username, LogConstants.EVENT_ERROR_REVOKEDENDENTITY);
if (getGlobalConfiguration(admin).getEnableEndEntityProfileLimitations()) {
assertAuthorizedToEndEntityProfile(admin, data.getEndEntityProfileId(), AccessRulesConstants.REVOKE_RIGHTS, caid, username, LogConstants.EVENT_ERROR_REVOKEDENDENTITY);
}
try {
if (data.getStatus() != UserDataConstants.STATUS_REVOKED) {
// Check if approvals is required.
final int numOfReqApprovals = getNumOfApprovalRequired(admin, CAInfo.REQ_APPROVAL_REVOCATION, caid, data.getCertificateProfileId());
if (numOfReqApprovals > 0) {
final RevocationApprovalRequest ar = new RevocationApprovalRequest(true, username, reason, admin, numOfReqApprovals, caid, data.getEndEntityProfileId());
if (ApprovalExecutorUtil.requireApproval(ar, NONAPPROVABLECLASSNAMES_REVOKEANDDELETEUSER)) {
approvalSession.addApprovalRequest(admin, ar, getGlobalConfiguration(admin));
throw new WaitingForApprovalException(intres.getLocalizedMessage("ra.approvalrevoke"));
}
}
try {
revokeUser(admin, username, reason);
} catch (AlreadyRevokedException e) {
// This just means that the end entity was revoked before
// this request could be completed. No harm.
}
}
} catch (FinderException e) {
throw new NotFoundException("User " + username + "not found.");
}
deleteUser(admin, username);
}