Package org.ejbca.core

Examples of org.ejbca.core.EjbcaException


        // But it can also be that the certificate has expired, very unlikely since the SSL server checks that
        throw new AuthorizationDeniedException(e.getMessage());
      }
    } catch (EJBException e) {
      log.error("EJBCA WebService error: ",e);
      throw new EjbcaException(ErrorCode.INTERNAL_ERROR, e.getMessage());
    }

    return admin;
  }
View Full Code Here


    MessageContext msgContext = wsContext.getMessageContext();
    HttpServletRequest request = (HttpServletRequest) msgContext.get(MessageContext.SERVLET_REQUEST);
    X509Certificate[] certificates = (X509Certificate[]) request.getAttribute("javax.servlet.request.X509Certificate");

    if(certificates == null){
      throw new EjbcaException(ErrorCode.AUTH_CERT_NOT_RECEIVED,
                "Error no client certificate recieved used for authentication.");
    }

    try{
      Admin admin = userAdminSession.getAdmin(certificates[0]);
View Full Code Here

          Authorizer.throwAuthorizationException(admin, AccessRulesConstants.REGULAR_VIEWCERTIFICATE, null);
      }
      UserDataVO userdata = userAdminSession.findUser(admin, username);
      if(userdata == null){
        String msg = intres.getLocalizedMessage("ra.errorentitynotexist", username);             
        throw new EjbcaException(ErrorCode.USER_NOT_FOUND, msg);
      }
      if(!authorizationSession.isAuthorizedNoLog(admin, AccessRulesConstants.ENDENTITYPROFILEPREFIX + userdata.getEndEntityProfileId() + AccessRulesConstants.VIEW_RIGHTS)) {
          Authorizer.throwAuthorizationException(admin, AccessRulesConstants.ENDENTITYPROFILEPREFIX + userdata.getEndEntityProfileId() + AccessRulesConstants.VIEW_RIGHTS, null);
      }
      if(!authorizationSession.isAuthorizedNoLog(admin, AccessRulesConstants.CAPREFIX + caid )){
          Authorizer.throwAuthorizationException(admin, AccessRulesConstants.CAPREFIX + caid, null);
      }

    } catch (EJBException e) {
      throw new EjbcaException(ErrorCode.INTERNAL_ERROR, e);
    }

  }
View Full Code Here

          Authorizer.throwAuthorizationException(admin, AccessRulesConstants.REGULAR_VIEWHARDTOKENS, null);
      }
      UserDataVO userdata = userAdminSession.findUser(admin, username);
      if(userdata == null){
        String msg = intres.getLocalizedMessage("ra.errorentitynotexist", username);             
        throw new EjbcaException(ErrorCode.USER_NOT_FOUND, msg);
      }

      if(!authorizationSession.isAuthorizedNoLog(admin, AccessRulesConstants.REGULAR_VIEWHARDTOKENS)) {
          Authorizer.throwAuthorizationException(admin, AccessRulesConstants.REGULAR_VIEWHARDTOKENS, null);
      }
      if(viewPUKData){
        if(!authorizationSession.isAuthorizedNoLog(admin, AccessRulesConstants.REGULAR_VIEWPUKS)) {
            Authorizer.throwAuthorizationException(admin, AccessRulesConstants.REGULAR_VIEWPUKS, null);
        }
      }

      if(userdata != null){
          if(!authorizationSession.isAuthorizedNoLog(admin, AccessRulesConstants.ENDENTITYPROFILEPREFIX + userdata.getEndEntityProfileId() + AccessRulesConstants.HARDTOKEN_RIGHTS)) {
              Authorizer.throwAuthorizationException(admin, AccessRulesConstants.ENDENTITYPROFILEPREFIX + userdata.getEndEntityProfileId() + AccessRulesConstants.HARDTOKEN_RIGHTS, null);
          }
        if(viewPUKData){
            if(!authorizationSession.isAuthorizedNoLog(admin, AccessRulesConstants.ENDENTITYPROFILEPREFIX + userdata.getEndEntityProfileId() + AccessRulesConstants.HARDTOKEN_PUKDATA_RIGHTS)) { 
                Authorizer.throwAuthorizationException(admin, AccessRulesConstants.ENDENTITYPROFILEPREFIX + userdata.getEndEntityProfileId() + AccessRulesConstants.HARDTOKEN_PUKDATA_RIGHTS, null);
            }
        }
      }

    } catch (EJBException e) {
      throw new EjbcaException(ErrorCode.INTERNAL_ERROR, e);
    }   
  }
View Full Code Here

      throw new CADoesntExistsException("Error CA " + userdata.getCaName() + " have caid 0, which is impossible.");
    }
   
    final int endentityprofileid = endEntityProfileSession.getEndEntityProfileId(admin,userdata.getEndEntityProfileName());
    if(endentityprofileid == 0){
      throw new EjbcaException(ErrorCode.EE_PROFILE_NOT_EXISTS,
                "Error End Entity profile " + userdata.getEndEntityProfileName() + " doesn't exists.");
    }

    final int certificateprofileid = certificateProfileSession.getCertificateProfileId(admin,userdata.getCertificateProfileName());
    if(certificateprofileid == 0){
      throw new EjbcaException(ErrorCode.CERT_PROFILE_NOT_EXISTS,
                "Error Certificate profile " + userdata.getCertificateProfileName() + " doesn't exists.");
    }
   
    final int hardtokenissuerid;
    if(userdata.getHardTokenIssuerName() != null){
         hardtokenissuerid = hardTokenSession.getHardTokenIssuerId(admin,userdata.getHardTokenIssuerName());
       if(hardtokenissuerid == 0){
        throw new EjbcaException(ErrorCode.HARD_TOKEN_ISSUER_NOT_EXISTS,
                  "Error Hard Token Issuer " + userdata.getHardTokenIssuerName() + " doesn't exists.");
       }
    } else {
      hardtokenissuerid = 0;
    }
   
    final int tokenid = getTokenId(admin,userdata.getTokenType());
    if(tokenid == 0){
      throw new EjbcaException(ErrorCode.UNKOWN_TOKEN_TYPE,
                "Error Token Type  " + userdata.getTokenType() + " doesn't exists.");
    }

    final ExtendedInformation ei = new ExtendedInformation();
    boolean useEI = false;

    if(userdata.getStartTime() != null) {
      String customStartTime = userdata.getStartTime();
      try {
        if (customStartTime.length()>0 && !customStartTime.matches("^\\d+:\\d?\\d:\\d?\\d$")) {
          if (!customStartTime.matches("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}.\\d{2}:\\d{2}$")) {
            // We use the old absolute time format, so we need to upgrade and log deprecation info
            final DateFormat oldDateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.US);
            final String newCustomStartTime = ValidityDate.formatAsISO8601(oldDateFormat.parse(customStartTime), ValidityDate.TIMEZONE_UTC);
            log.info("WS client sent userdata with startTime using US Locale date format. yyyy-MM-dd HH:mm:ssZZ should be used for absolute time and any fetched UserDataVOWS will use this format.");
            if (log.isDebugEnabled()) {
              log.debug(" Changed startTime \"" + customStartTime + "\" to \"" + newCustomStartTime + "\" in UserDataVOWS.");
            }
            customStartTime = newCustomStartTime;
          }
          customStartTime = ValidityDate.getImpliedUTCFromISO8601(customStartTime);
        }
        ei.setCustomData(ExtendedInformation.CUSTOM_STARTTIME, customStartTime);
        useEI = true;
      } catch (ParseException e) {
        log.info("WS client supplied invalid startTime in userData. startTime for this request was ignored. Supplied SubjectDN was \"" + userdata.getSubjectDN() + "\"");
        throw new EjbcaException(ErrorCode.FIELD_VALUE_NOT_VALID, "Invalid date format in StartTime.");
      }
    }
        if(userdata.getEndTime() != null) {
      String customEndTime = userdata.getEndTime();
      try {
        if (customEndTime.length()>0 && !customEndTime.matches("^\\d+:\\d?\\d:\\d?\\d$")){
          if (!customEndTime.matches("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}.\\d{2}:\\d{2}$")) {
            // We use the old absolute time format, so we need to upgrade and log deprecation info
            final DateFormat oldDateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.US);
            final String newCustomStartTime = ValidityDate.formatAsISO8601(oldDateFormat.parse(customEndTime), ValidityDate.TIMEZONE_UTC);
            log.info("WS client sent userdata with endTime using US Locale date format. yyyy-MM-dd HH:mm:ssZZ should be used for absolute time and any fetched UserDataVOWS will use this format.");
            if (log.isDebugEnabled()) {
              log.debug(" Changed endTime \"" + customEndTime + "\" to \"" + newCustomStartTime + "\" in UserDataVOWS.");
            }
            customEndTime = newCustomStartTime;
          }
          customEndTime = ValidityDate.getImpliedUTCFromISO8601(customEndTime);
        }
              ei.setCustomData(ExtendedInformation.CUSTOM_ENDTIME, customEndTime);
              useEI = true;
      } catch (ParseException e) {
        log.info("WS client supplied invalid endTime in userData. endTime for this request was ignored. Supplied SubjectDN was \"" + userdata.getSubjectDN() + "\"");
        throw new EjbcaException(ErrorCode.FIELD_VALUE_NOT_VALID, "Invalid date format in EndTime.");
      }
        }
        if ( userdata.getCertificateSerialNumber()!=null) {
            ei.setCertificateSerialNumber(userdata.getCertificateSerialNumber());
            useEI = true;
View Full Code Here

    dataWS.setUsername(username);

    if(caname == null){
      String message = "Error CA id " + userdata.getCAId() + " doesn't exists. User: "+username;
      log.error(message);
      throw new EjbcaException(ErrorCode.CA_NOT_EXISTS, message);
    }
    dataWS.setCaName(caname);
   
    String endentityprofilename = endEntityProfileSession.getEndEntityProfileName(admin,userdata.getEndEntityProfileId());
    if(endentityprofilename == null){
      String message = "Error End Entity profile id " + userdata.getEndEntityProfileId() + " doesn't exists. User: "+username;
      log.error(message);
      throw new EjbcaException(ErrorCode.EE_PROFILE_NOT_EXISTS, message);
    }
        dataWS.setEndEntityProfileName(endentityprofilename);

    String certificateprofilename = certificateProfileSession.getCertificateProfileName(admin,userdata.getCertificateProfileId());
    if(certificateprofilename == null){
      String message = "Error Certificate profile id " + userdata.getCertificateProfileId() + " doesn't exists. User: "+username;
      log.error(message);
      throw new EjbcaException(ErrorCode.CERT_PROFILE_NOT_EXISTS, message);
    }
      dataWS.setCertificateProfileName(certificateprofilename);
   
    String hardtokenissuername = null;
    if(userdata.getHardTokenIssuerId() != 0){
       hardtokenissuername = hardTokenSession.getHardTokenIssuerAlias(admin,userdata.getHardTokenIssuerId());
       if(hardtokenissuername == null){
         String message = "Error Hard Token Issuer id " + userdata.getHardTokenIssuerId() + " doesn't exists. User: "+username;
         log.error(message);
         throw new EjbcaException(ErrorCode.HARD_TOKEN_ISSUER_NOT_EXISTS, message);
       }
       dataWS.setHardTokenIssuerName(hardtokenissuername);
    }
   
    String tokenname = getTokenName(admin,userdata.getTokenType());
    if(tokenname == null){
      String message = "Error Token Type id " + userdata.getTokenType() + " doesn't exists. User: "+username;
      log.error(message);
      throw new EjbcaException(ErrorCode.UNKOWN_TOKEN_TYPE, message);
    }
    dataWS.setTokenType(tokenname);

    dataWS.setPassword(null);
    dataWS.setClearPwd(false);
View Full Code Here

      while(iter.hasNext()){
        retval.getCertificates().add(new Certificate(iter.next()));
      }
    }catch(DatatypeConfigurationException e){
      log.error("EJBCA WebService error, getHardToken: ",e);
      throw new EjbcaException(ErrorCode.INTERNAL_ERROR, e.getMessage());
    }catch(CertificateEncodingException e){
      log.error("EJBCA WebService error, getHardToken: ",e);
      throw new EjbcaException(ErrorCode.INTERNAL_ERROR, e.getMessage());
    }


    if(data.getHardToken() instanceof SwedishEIDHardToken){
      SwedishEIDHardToken ht = (SwedishEIDHardToken) data.getHardToken();
      if(includePUK){
        retval.getPinDatas().add(new PinDataWS(HardTokenConstants.PINTYPE_SIGNATURE,ht.getInitialSignaturePIN(),ht.getSignaturePUK()));
        retval.getPinDatas().add(new PinDataWS(HardTokenConstants.PINTYPE_BASIC,ht.getInitialAuthEncPIN(),ht.getAuthEncPUK()));
      }
      retval.setTokenType(HardTokenConstants.TOKENTYPE_SWEDISHEID);
      return retval;
    }
    if(data.getHardToken() instanceof EnhancedEIDHardToken){
      EnhancedEIDHardToken ht = (EnhancedEIDHardToken) data.getHardToken();
      retval.setEncKeyKeyRecoverable(ht.getEncKeyRecoverable());
      if(includePUK){
        retval.getPinDatas().add(new PinDataWS(HardTokenConstants.PINTYPE_SIGNATURE,ht.getInitialSignaturePIN(),ht.getSignaturePUK()));
        retval.getPinDatas().add(new PinDataWS(HardTokenConstants.PINTYPE_BASIC,ht.getInitialAuthPIN(),ht.getAuthPUK()));
      }
      retval.setTokenType(HardTokenConstants.TOKENTYPE_ENHANCEDEID);
      return retval;
    }
    if(data.getHardToken() instanceof TurkishEIDHardToken){
      TurkishEIDHardToken ht = (TurkishEIDHardToken) data.getHardToken();
      if(includePUK){
        retval.getPinDatas().add(new PinDataWS(HardTokenConstants.PINTYPE_BASIC,ht.getInitialPIN(),ht.getPUK()));
      }
      retval.setTokenType(HardTokenConstants.TOKENTYPE_TURKISHEID);
      return retval;
    }
    throw new EjbcaException(ErrorCode.INTERNAL_ERROR,
                             "Error: only SwedishEIDHardToken, EnhancedEIDHardToken, TurkishEIDHardToken supported.");
  }
View Full Code Here

  protected static EjbcaException getEjbcaException(Throwable t, IPatternLogger logger, ErrorCode errorCode, Priority p) {
        log.log(p, "EJBCA WebService error", t);
        if (logger != null) {
            logger.paramPut(TransactionTags.ERROR_MESSAGE.toString(), errorCode.toString());         
        }
        return new EjbcaException(errorCode, t.getMessage());
  }
View Full Code Here

        }
        if ( errorCode!=null ) {
            if (logger != null) {
              logger.paramPut(TransactionTags.ERROR_MESSAGE.toString(), errorCode.toString());
            }
            return new EjbcaException(errorCode, s);
        }
        return new EjbcaException(s);
    }
View Full Code Here

  /**
   * Verify that nested ApprovalExceptions propagate errorCode.
   */
  public void testErrorCode() {
    ApprovalException approvalException = new ApprovalException(ErrorCode.APPROVAL_ALREADY_EXISTS, "JUnit test message..");
    EjbcaException ejbcaException = new EjbcaException(approvalException);
    assertEquals("EjbcaException did not inherit ErrorCode.", ErrorCode.APPROVAL_ALREADY_EXISTS, ejbcaException.getErrorCode());
  }
View Full Code Here

TOP

Related Classes of org.ejbca.core.EjbcaException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.