Package org.ejbca.extra.db

Examples of org.ejbca.extra.db.Message


    String cert1 = new String(Base64.encode(firstCertificate.getEncoded()));
    assertNotNull("Missing certificate from previous test.", secondCertificate);
        String cert2 = new String(Base64.encode(secondCertificate.getEncoded()));
    smgs.addSubMessage(new CardRenewalRequest(10, cert1, cert1, null, null));
    msghome.create("SimpleCardRenewalTest", smgs);
        Message msg = waitForUser("SimpleCardRenewalTest");
    assertNotNull("No response.", msg);
    SubMessages submessagesresp = msg.getSubMessages(null,null,null);
    assertTrue("Number of submessages " + submessagesresp.getSubMessages().size(), submessagesresp.getSubMessages().size() == 1);
    ExtRAResponse resp = (ExtRAResponse) submessagesresp.getSubMessages().iterator().next();
    assertTrue("Wrong Request ID" + resp.getRequestId(), resp.getRequestId() == 10);
    assertTrue(resp.isSuccessful() == false);
        assertEquals(resp.getFailInfo(), "An authentication cert, a signature cert, an authentication request and a signature request are required");

        // Second fail message
    smgs = new SubMessages(null,null,null);
    smgs.addSubMessage(new CardRenewalRequest(11, null, null, Constants.pkcs10_1, Constants.pkcs10_2));
    msghome.create("SimpleCardRenewalTest", smgs);
        msg = waitForUser("SimpleCardRenewalTest");
    assertNotNull(msg);
    submessagesresp = msg.getSubMessages(null,null,null);
    assertTrue("Number of submessages " + submessagesresp.getSubMessages().size(), submessagesresp.getSubMessages().size() == 1);
    resp = (ExtRAResponse) submessagesresp.getSubMessages().iterator().next();
    assertTrue("Wrong Request ID" + resp.getRequestId(), resp.getRequestId() == 11);
    assertTrue(resp.isSuccessful() == false);
        assertEquals(resp.getFailInfo(), "An authentication cert, a signature cert, an authentication request and a signature request are required");

        // Third fail message
    smgs = new SubMessages(null,null,null);
    smgs.addSubMessage(new CardRenewalRequest(12, cert1, cert1, Constants.pkcs10_1, Constants.pkcs10_2));
    msghome.create("SimpleCardRenewalTest", smgs);
        msg = waitForUser("SimpleCardRenewalTest");
    assertNotNull(msg);
    submessagesresp = msg.getSubMessages(null,null,null);
    assertTrue("Number of submessages " + submessagesresp.getSubMessages().size(), submessagesresp.getSubMessages().size() == 1);
    resp = (ExtRAResponse) submessagesresp.getSubMessages().iterator().next();
    assertTrue("Wrong Request ID" + resp.getRequestId(), resp.getRequestId() == 12);
        assertTrue(resp.isSuccessful() == false);
        assertEquals(resp.getFailInfo(), "Verify failed for signature request");
       
        // Fourth fail message
        smgs = new SubMessages(null,null,null);
        smgs.addSubMessage(new CardRenewalRequest(12, cert1, cert2, Constants.pkcs10_1, Constants.pkcs10_2));
        msghome.create("SimpleCardRenewalTest", smgs);
        msg = waitForUser("SimpleCardRenewalTest");
        assertNotNull(msg);
        submessagesresp = msg.getSubMessages(null,null,null);
        assertTrue("Number of submessages " + submessagesresp.getSubMessages().size(), submessagesresp.getSubMessages().size() == 1);
        resp = (ExtRAResponse) submessagesresp.getSubMessages().iterator().next();
        assertTrue("Wrong Request ID" + resp.getRequestId(), resp.getRequestId() == 12);
        assertTrue(resp.isSuccessful() == false);
        log.debug("resp.getFailInfo: " + resp.getFailInfo());
View Full Code Here


    EditUserRequest editUserRequest = new EditUserRequest(requestId, username, "CN=" + username, null, null, null, "EMPTY", "ENDUSER",
                   "AdminCA1", password, 10, 1, EditUserRequest.SOFTTOKENNAME_P12, null);
    SubMessages smgs = new SubMessages(null,null,null);
    smgs.addSubMessage(editUserRequest);
    msghome.create(username, smgs);
        Message msg = waitForUser(username);
    assertNotNull("No response.", msg);
    SubMessages submessagesresp = msg.getSubMessages(null,null,null);
    assertTrue("Number of submessages " + submessagesresp.getSubMessages().size(), submessagesresp.getSubMessages().size() == 1);
    ExtRAResponse resp = (ExtRAResponse) submessagesresp.getSubMessages().iterator().next();
    assertTrue("Wrong Request ID: " + resp.getRequestId(), resp.getRequestId() == requestId);
    assertTrue("Edit user failed", resp.isSuccessful() == true);
    // Try to retrieve keystore
    requestId = random.nextLong();
    KeyStoreRetrievalRequest keyStoreRetrievalRequest = new KeyStoreRetrievalRequest(requestId, username, password);
    smgs = new SubMessages(null,null,null);
    smgs.addSubMessage(keyStoreRetrievalRequest);
    msghome.create(username+"ks", smgs);
        msg = waitForUser(username+"ks");
    assertNotNull("No response.", msg);
    submessagesresp = msg.getSubMessages(null,null,null);
    assertTrue("Number of submessages " + submessagesresp.getSubMessages().size(), submessagesresp.getSubMessages().size() == 1);
    resp = (ExtRAResponse) submessagesresp.getSubMessages().iterator().next();
    assertTrue("Wrong Request ID: " + resp.getRequestId(), resp.getRequestId() == requestId);
    assertTrue("KeyStoreRetrieval failed", resp.isSuccessful() == true);
    assertTrue("Wrong response type.", resp instanceof KeyStoreRetrievalResponse);
View Full Code Here

    EditUserRequest editUserRequest = new EditUserRequest(requestId, username, "CN=" + username, null, null, null, "EMPTY", "ENDUSER",
                   "AdminCA1", password, 10, 1, EditUserRequest.SOFTTOKENNAME_USERGENERATED, null);
    SubMessages smgs = new SubMessages(null,null,null);
    smgs.addSubMessage(editUserRequest);
    msghome.create(username, smgs);
        Message msg = waitForUser(username);
    assertNotNull("No response.", msg);
    SubMessages submessagesresp = msg.getSubMessages(null,null,null);
    assertTrue("Number of submessages " + submessagesresp.getSubMessages().size(), submessagesresp.getSubMessages().size() == 1);
    ExtRAResponse resp = (ExtRAResponse) submessagesresp.getSubMessages().iterator().next();
    assertTrue("Wrong Request ID" + resp.getRequestId(), resp.getRequestId() == requestId);
    assertTrue("Edit user failed", resp.isSuccessful() == true);
    // Try to retrieve keystore
    requestId = random.nextLong();
    byte[] requestData = NonEjbTestTools.generatePKCS10Req("CN=dummyname", password);
    CertificateRequestRequest certificateRequestRequest = new CertificateRequestRequest(requestId, username, password, CertificateRequestRequest.REQUEST_TYPE_PKCS10, requestData, CertificateRequestRequest.RESPONSE_TYPE_ENCODED);
    smgs = new SubMessages(null,null,null);
    smgs.addSubMessage(certificateRequestRequest);
    msghome.create(username+"csr", smgs);
        msg = waitForUser(username+"csr");
    assertNotNull("No response.", msg);
    submessagesresp = msg.getSubMessages(null,null,null);
    assertTrue("Number of submessages " + submessagesresp.getSubMessages().size(), submessagesresp.getSubMessages().size() == 1);
    resp = (ExtRAResponse) submessagesresp.getSubMessages().iterator().next();
    assertTrue("Wrong Request ID" + resp.getRequestId(), resp.getRequestId() == requestId);
    assertTrue("KeyStoreRetrieval failed", resp.isSuccessful() == true);
    assertTrue("Wrong response type.", resp instanceof CertificateRequestResponse);
View Full Code Here

   
    final SubMessages smgs = new SubMessages(null,null,null);
    smgs.addSubMessage(request);
    msghome.create(username + "csr", smgs);
       
    final Message msg = waitForUser(username + "csr");
        assertNotNull("No response.", msg);
    final SubMessages submessagesresp = msg.getSubMessages(null,null,null);
    assertEquals("Number of submessages " + submessagesresp.getSubMessages().size(), 1, submessagesresp.getSubMessages().size());
    final ExtRAResponse resp = (ExtRAResponse) submessagesresp.getSubMessages().iterator().next();
    assertEquals("Wrong Request ID" + resp.getRequestId(), requestId, resp.getRequestId());
    assertTrue("KeyStoreRetrieval failed: " + resp.getFailInfo(), resp.isSuccessful());
    assertTrue("Wrong response type.", resp instanceof CertificateRequestResponse);
View Full Code Here

  }

  private Message waitForUser(String user) throws InterruptedException{
    int waittime = 30; // Wait a maximum of 30 seconds
    boolean processed = false;
    Message msg = null;
    do{     
      msg = msghome.findByMessageId(user);
      assertNotNull(msg);
     
      if(msg.getStatus().equals(Message.STATUS_PROCESSED)){
        processed = true;
        break;
     
      Thread.sleep(1000);
    }while( waittime-- >= 0);
View Full Code Here

      createUser(username, submgs);     

      run=true;
      // Wait for response
      boolean processed = false;
      Message msg = null;
      int wait = waitTime;
      while (wait >= 0 && run) {
        msg = findByUser(username);
        if (msg != null && msg.getStatus().equals(Message.STATUS_PROCESSED)) {
          processed = true;
          break;
        }
        try {
          sleep(1000);
        } catch (InterruptedException e) {
        }
        wait--;
      }
      if (!processed) {
        println("Error : Couldn't get processed response within the specified waitTime : Username :" + username + ", WaitTime : " + waitTime);

      } else {
        SubMessages respmsgs = null;
        if (raKey != null) {         
          respmsgs = msg.getSubMessages(raKey,cAChain,null);
        } else {
          respmsgs = msg.getSubMessages(null,null,null);
        }
        PKCS10Response pkcs10resp = (PKCS10Response) respmsgs.getSubMessages().get(0);
        PKCS12Response pkcs12resp = null;
        if (requestKeyStore) {
          pkcs12resp = (PKCS12Response) respmsgs.getSubMessages().get(1);
View Full Code Here

      }else{
        log.debug("RAIssuer is misconfigured, but isn't required")
      }
    }       

    Message msg = null;
    String lastMessageId = null;
    do
      msg = msgHome.getNextWaitingMessage();
      // A small section that makes sure we don't loop too quickly over the same message.
      // Check if we are trying to process the same messageId as the last time. If this is the case exit from the loop and let the next
      // worker try to process it.
      // If it is not the same messageId process the message immediately.
      if (msg != null) {
        String id = msg.getMessageid();
        if (StringUtils.equals(id, lastMessageId)) {
          log.info("The same message (" + id + ") was in the queue twice, putting back and exiting from the current loop");
          // Re-set status to waiting so we will process it the next time the service is run
          msg.setStatus(Message.STATUS_WAITING);
          msgHome.update(msg);             
          msg = null;
        } else {
          String errormessage = null;
          SubMessages submgs = null;
          try {
            log.info("Started processing message with messageId: " + msg.getMessageid()+", and uniqueId: "+msg.getUniqueId());

            if (serviceKeyStore != null) {
              submgs = msg.getSubMessages(
                  (PrivateKey) serviceKeyStore.getKeyStore().getKey(serviceKeyStore.getAlias(), keystorePwd.toCharArray()),
                  cACertChain,null);
            } else {
              submgs =  msg.getSubMessages(null,null,null);
            }
            if (submgs.isSigned()) {
              log.debug("Message from : " + msg.getMessageid() + " was signed");
            }
            if (signatureRequired && !submgs.isSigned()) {
              errormessage = "Error: Message from : " + msg.getMessageid() + " wasn't signed which is a requirement";
              log.error(errormessage);

            }
            if (submgs.isEncrypted()) {
              log.debug("Message from : " + msg.getMessageid() + " was encrypted");
            }
            if (encryptionRequired && !submgs.isEncrypted()) {
              errormessage = "Error: Message from : " + msg.getMessageid() + " wasn't encrypted which is a requirement";
              log.error(errormessage);
            }
          } catch (Exception e) {
            errormessage = "Error processing waiting message with Messageid : " + msg.getMessageid() + " : "+ e.getMessage();
            log.error("Error processing waiting message with Messageid : " + msg.getMessageid(), e);
          }

          if (submgs != null) {
            SubMessages respSubMsg;
            try {
              respSubMsg = generateResponseSubMessage(submgs.getSignerCert());
              Iterator<ISubMessage> iter = submgs.getSubMessages().iterator();
              boolean somethingprocessed = false;
              while(iter.hasNext()){
                ISubMessage reqMsg = iter.next();
                if (!checkWhiteList(reqMsg)) {
                  errormessage = "Sub message of type " + reqMsg.getClass().getName() + " is not listed in white list. Message id: " + msg.getMessageid();
                }
                ISubMessage respMsg = MessageProcessor.processSubMessage(getAdmin(submgs), reqMsg, errormessage, ejbs);
                if (respMsg != null) {
                  // if the response message is null here, we will ignore this message,
                  // it means that we should not do anything with it this round
                  respSubMsg.addSubMessage(respMsg);
                  somethingprocessed = true;
                }
              }
              if (somethingprocessed) {
                msg.setStatus(Message.STATUS_PROCESSED);
                msg.setSubMessages(respSubMsg);
              } else {
                log.info("Nothing processed for msg with messageId: "+msg.getMessageid()+", leaving it in the queue");
                msg.setStatus(Message.STATUS_WAITING);
                // Update create time, so that we will process the next message instead of this again the next round in the loop
                msg.setCreatetime((new Date()).getTime());
              }
              msgHome.update(msg);             
            } catch (Exception e) {
              log.error("Error generating response message with Messageid : " + msg.getMessageid(), e);
            }

          }         
        }
        lastMessageId = id;        
View Full Code Here

TOP

Related Classes of org.ejbca.extra.db.Message

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.