Package org.ejbca.core.model.hardtoken

Examples of org.ejbca.core.model.hardtoken.HardTokenData


      hardTokenExists = hardTokenSession.existsHardToken(admin, hardTokenDataWS.getHardTokenSN());
      if(hardTokenExists){
        if(overwriteExistingSN){
          // fetch all old certificates and revoke them.
          Collection<java.security.cert.Certificate> currentCertificates = hardTokenSession.findCertificatesInHardToken(admin, hardTokenDataWS.getHardTokenSN());
          HardTokenData currentHardToken = hardTokenSession.getHardToken(admin, hardTokenDataWS.getHardTokenSN(), false);
          Iterator<java.security.cert.Certificate> iter = currentCertificates.iterator();
          while(iter.hasNext()){
            java.security.cert.X509Certificate nextCert = (java.security.cert.X509Certificate) iter.next();
            try {
              userAdminSession.revokeCert(admin, CertTools.getSerialNumber(nextCert), CertTools.getIssuerDN(nextCert), RevokedCertInfo.REVOCATION_REASON_SUPERSEDED);
            } catch (AlreadyRevokedException e) {
              // Ignore previously revoked certificates
            } catch (FinderException e) {
                            throw EjbcaWSHelper.getEjbcaException("Error revoking old certificate, the user : " + currentHardToken.getUsername() + " of the old certificate couldn't be found in database.",
                                                    logger, ErrorCode.USER_NOT_FOUND, null);
            }
          }

        }else{
View Full Code Here


    Admin admin = ejbhelper.getAdmin(true);
    ApprovalRequest ar = null;
    boolean isApprovedStep0 = false;
    boolean isRejectedStep0 = false;

    HardTokenData hardTokenData = null;
    final IPatternLogger logger = TransactionLogger.getPatternLogger();
        logAdminName(admin,logger);
        try {
    try{
      hardTokenData = hardTokenSession.getHardToken(admin, hardTokenSN, viewPUKData);
      if(hardTokenData == null){
        throw new HardTokenDoesntExistsException("Error, hard token with SN " + hardTokenSN + " doesn't exist.");
      }
      ejbhelper.isAuthorizedToHardTokenData(admin, hardTokenData.getUsername(), viewPUKData);
    }catch(AuthorizationDeniedException e){
      boolean genNewRequest = false;
      if(WebServiceConfiguration.getApprovalForHardTokenData()){
        // Check Approvals
        // Exists an GenTokenCertificates
          Admin intAdmin = Admin.getInternalAdmin();
          UserDataVO userData = userAdminSession.findUser(intAdmin, hardTokenData.getUsername());
          if (userData == null) {
            String msg = intres.getLocalizedMessage("ra.errorentitynotexist", hardTokenData.getUsername());             
            throw new NotFoundException(msg);
          }
          int caid = userData.getCAId();
          caAdminSession.verifyExistenceOfCA(caid);
          ar = new GenerateTokenApprovalRequest(userData.getUsername(), userData.getDN(), hardTokenData.getHardToken().getLabel(),admin,null,WebServiceConfiguration.getNumberOfRequiredApprovals(),caid,userData.getEndEntityProfileId());
          int status = ApprovalDataVO.STATUS_REJECTED;          
          try{
            if(!WebServiceConfiguration.getApprovalForGenTokenCertificates()){
              throw new ApprovalException("");
            }
View Full Code Here

      ejbhelper.isAuthorizedToHardTokenData(admin, username, viewPUKData);

      Collection<HardTokenData> hardtokens = hardTokenSession.getHardTokens(admin, username, viewPUKData);
      Iterator<HardTokenData> iter = hardtokens.iterator();
      while(iter.hasNext()){
        HardTokenData next = (HardTokenData) iter.next();
        int caid = next.getSignificantIssuerDN().hashCode();
        caAdminSession.verifyExistenceOfCA(caid);
        if(!authorizationSession.isAuthorizedNoLog(admin, AccessRulesConstants.CAPREFIX + caid)) {
            Authorizer.throwAuthorizationException(admin, AccessRulesConstants.CAPREFIX + caid, null);
        }
        Collection<java.security.cert.Certificate> certs = hardTokenSession.findCertificatesInHardToken(admin, next.getTokenSN());
        if(onlyValidCertificates){
          certs = ejbhelper.returnOnlyValidCertificates(admin, certs);
        }
        retval.add(ejbhelper.convertHardTokenToWS(next,certs, viewPUKData));
      }
View Full Code Here

    @Override
    public HardTokenData getHardToken(Admin admin, String tokensn, boolean includePUK) throws AuthorizationDeniedException {
        if (log.isTraceEnabled()) {
            log.trace("<getHardToken(tokensn :" + tokensn + ")");
        }
        HardTokenData returnval = null;
        org.ejbca.core.ejb.hardtoken.HardTokenData htd = org.ejbca.core.ejb.hardtoken.HardTokenData.findByTokenSN(entityManager, tokensn);
        if (htd != null) {
            // Find Copyof
            String copyof = null;
            HardTokenPropertyData htpd = HardTokenPropertyData.findByProperty(entityManager, tokensn, HardTokenPropertyData.PROPERTY_COPYOF);
            if (htpd != null) {
                copyof = htpd.getValue();
            }
            ArrayList<String> copies = null;
            if (copyof == null) {
                // Find Copies
                Collection<HardTokenPropertyData> copieslocal = HardTokenPropertyData.findIdsByPropertyAndValue(entityManager,
                        HardTokenPropertyData.PROPERTY_COPYOF, tokensn);
                if (copieslocal.size() > 0) {
                    copies = new ArrayList<String>();
                    Iterator<HardTokenPropertyData> iter = copieslocal.iterator();
                    while (iter.hasNext()) {
                        copies.add(iter.next().getId());
                    }
                }
            }
            if (htd != null) {
                returnval = new HardTokenData(htd.getTokenSN(), htd.getUsername(), htd.getCreateTime(), htd.getModifyTime(), htd.getTokenType(), htd
                        .getSignificantIssuerDN(), getHardToken(admin, globalConfigurationSession.getCachedGlobalConfiguration(admin).getHardTokenEncryptCA(),
                        includePUK, htd.getData()), copyof, copies);
                String msg = intres.getLocalizedMessage("hardtoken.viewedtoken", tokensn);
                logSession.log(admin, htd.getSignificantIssuerDN().hashCode(), LogConstants.MODULE_HARDTOKEN, new java.util.Date(), htd.getUsername(), null,
                        LogConstants.EVENT_INFO_HARDTOKENVIEWED, msg);
View Full Code Here

                    while (iter.hasNext()) {
                        copies.add(iter.next().getId());
                    }
                }
            }
            returnval.add(new HardTokenData(htd.getTokenSN(), htd.getUsername(), htd.getCreateTime(), htd.getModifyTime(), htd.getTokenType(), htd
                    .getSignificantIssuerDN(), getHardToken(admin, globalConfigurationSession.getCachedGlobalConfiguration(admin).getHardTokenEncryptCA(),
                    includePUK, htd.getData()), copyof, copies));
            String msg = intres.getLocalizedMessage("hardtoken.viewedtoken", htd.getTokenSN());
            logSession.log(admin, htd.getSignificantIssuerDN().hashCode(), LogConstants.MODULE_HARDTOKEN, new java.util.Date(), htd.getUsername(), null,
                    LogConstants.EVENT_INFO_HARDTOKENVIEWED, msg);
View Full Code Here

  /**
   * @see org.ejbca.ui.cli.hardtoken.importer.FileReadHardTokenImporter#readHardTokenData()
   */
  public HardTokenData readHardTokenData() throws IOException {
    HardTokenData retval = null;
   
   
    String line = bufferedReader.readLine();
    if(line != null){
      String basicPIN = "";
      String signaturePIN = "";
      String basicPUK = "";
      String signaturePUK = "";
      String tokenSN = "";
     
     
      String[] lineColumns = line.split(columnSeparator);
      for(int i=0;i < lineColumns.length;i++){
        lineColumns[i] = lineColumns[i].trim();
        switch(columns[i]){
        case COLUMN_TOKENSN :
          tokenSN = lineColumns[i];
          break;
        case COLUMN_PIN1 :
          basicPIN = lineColumns[i];
          break;
        case COLUMN_PIN2 :
          signaturePIN = lineColumns[i];
          break;
        case COLUMN_BOTHPIN :
          basicPIN = lineColumns[i];
          signaturePIN = lineColumns[i];
          break;
        case COLUMN_PUK1:
          basicPUK = lineColumns[i];
          break;
        case COLUMN_PUK2 :
          signaturePUK = lineColumns[i];
          break;   
        case COLUMN_BOTHPUK :
          basicPUK = lineColumns[i];
          signaturePUK = lineColumns[i];
          break;   
        default:
          throw new IOException("Error reading column + " + i + " of hard token import data.");
        }
      }
      int tokenType = SecConst.TOKEN_SWEDISHEID;
      if(hardTokenType.equalsIgnoreCase("enhancedeid")){
        tokenType = SecConst.TOKEN_ENHANCEDEID;       
      }
      HardToken ht = getHardTokenType(basicPIN, basicPUK, signaturePIN, signaturePUK);
      retval = new HardTokenData(tokenSN,null,new Date(),new Date(), tokenType,null, ht,null,null);
    }
   
   
    return retval;
  }
View Full Code Here

          if(props.getProperty("importer.classpath") == null){
            throw new IllegalAdminCommandException("Error, the property importer.classpath isn't set in the propertyfile " + args[1]);
          }
          IHardTokenImporter importer =  (IHardTokenImporter) Thread.currentThread().getContextClassLoader().loadClass(props.getProperty("importer.classpath")).newInstance();
          importer.startImport(props);
          HardTokenData htd;
          try{
            while((htd = importer.readHardTokenData()) != null){
              try{
                   ejb.getHardTokenSession().addHardToken(getAdmin(), htd.getTokenSN(), htd.getUsername(), significantIssuerDN, htd.getTokenType(), htd.getHardToken(), null, htd.getCopyOf());
                   getLogger().info("Token with SN " + htd.getTokenSN() + " were added to the database.");
              }catch(HardTokenExistsException e){
                if(force){
                  ejb.getHardTokenSession().removeHardToken(getAdmin(), htd.getTokenSN());
                  ejb.getHardTokenSession().addHardToken(getAdmin(), htd.getTokenSN(), htd.getUsername(), significantIssuerDN, htd.getTokenType(), htd.getHardToken(), null, htd.getCopyOf());
                  getLogger().info("Token with SN " + htd.getTokenSN() + " already existed in the database but was OVERWRITTEN.");                 
                }else{
                  getLogger().error("Token with SN " + htd.getTokenSN() + " already exists in the database and is NOT imported.");
                }
              }
            }
          }finally{
              importer.endImport();
View Full Code Here

    public void test02EditHardToken() throws Exception {
        log.trace(">test02EditHardToken()");

        boolean ret = false;

        HardTokenData token = hardTokenSessionRemote.getHardToken(admin, "1234", true);

        SwedishEIDHardToken swe = (SwedishEIDHardToken) token.getHardToken();

        assertTrue("Retrieving HardToken failed", swe.getInitialAuthEncPIN().equals("1234"));

        swe.setInitialAuthEncPIN("5678");

        hardTokenSessionRemote.changeHardToken(admin, "1234", SecConst.TOKEN_SWEDISHEID, token.getHardToken());
        ret = true;

        assertTrue("Editing HardToken failed", ret);
        log.trace("<test02EditHardToken()");
    }
View Full Code Here

        gc.setHardTokenEncryptCA(getTestCAId());
        globalConfigurationSession.saveGlobalConfigurationRemote(admin, gc);
        boolean ret = false;

        // Make sure the old data can be read
        HardTokenData token = hardTokenSessionRemote.getHardToken(admin, "1234", true);

        SwedishEIDHardToken swe = (SwedishEIDHardToken) token.getHardToken();

        assertTrue("Retrieving HardToken failed : " + swe.getInitialAuthEncPIN(), swe.getInitialAuthEncPIN().equals("5678"));

        swe.setInitialAuthEncPIN("5678");

        // Store the new data as encrypted
        hardTokenSessionRemote.changeHardToken(admin, "1234", SecConst.TOKEN_SWEDISHEID, token.getHardToken());
        ret = true;

        assertTrue("Saving encrypted HardToken failed", ret);

        // Make sure the encrypted data can be read
        token = hardTokenSessionRemote.getHardToken(admin, "1234", true);

        swe = (SwedishEIDHardToken) token.getHardToken();

        assertTrue("Retrieving encrypted HardToken failed", swe.getInitialAuthEncPIN().equals("5678"));

        log.trace("<test04EncryptHardToken()");
    }
View Full Code Here

    }
   
    public HardTokenView getHardTokenView(String tokensn, boolean includePUK) throws AuthorizationDeniedException {
        HardTokenView  returnval = null;
        this.result=null;
        HardTokenData token =  hardtokensession.getHardToken(admin, tokensn, includePUK);
        if(token != null) {
            returnval = new  HardTokenView(token);
        }
        return returnval;
    }
View Full Code Here

TOP

Related Classes of org.ejbca.core.model.hardtoken.HardTokenData

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.