Package org.ejbca.util.query

Examples of org.ejbca.util.query.Query


   * @param usermatch a usermatch containing names of profiles
   * @return a query containing id's of profiles.
   * @throws NumberFormatException
   */
  protected Query convertUserMatch(Admin admin, UserMatch usermatch) throws NumberFormatException {
    Query retval = new Query(Query.TYPE_USERQUERY);         
    switch(usermatch.getMatchwith()){
      case UserMatch.MATCH_WITH_ENDENTITYPROFILE:
        String endentityprofilename = Integer.toString(endEntityProfileSession.getEndEntityProfileId(admin,usermatch.getMatchvalue()));
        retval.add(usermatch.getMatchwith(),usermatch.getMatchtype(),endentityprofilename);
        break;
      case UserMatch.MATCH_WITH_CERTIFICATEPROFILE:
        String certificateprofilename = Integer.toString(certificateProfileSession.getCertificateProfileId(admin,usermatch.getMatchvalue()));
        retval.add(usermatch.getMatchwith(),usermatch.getMatchtype(),certificateprofilename);
        break;       
      case UserMatch.MATCH_WITH_CA:
        String caname = Integer.toString(caAdminSession.getCAInfo(admin,usermatch.getMatchvalue()).getCAId());
        retval.add(usermatch.getMatchwith(),usermatch.getMatchtype(),caname);
        break
      case UserMatch.MATCH_WITH_TOKEN:
        String tokenname = Integer.toString(getTokenId(admin,usermatch.getMatchvalue()));
        retval.add(usermatch.getMatchwith(),usermatch.getMatchtype(),tokenname);
        break;
      default:   
        retval.add(usermatch.getMatchwith(),usermatch.getMatchtype(),usermatch.getMatchvalue());
        break;
    }
    return retval;
  }
View Full Code Here


        final IPatternLogger logger = TransactionLogger.getPatternLogger();
        try {
          final EjbcaWSHelper ejbhelper = new EjbcaWSHelper(wsContext, authorizationSession, caAdminSession, certificateProfileSession, certificateStoreSession, endEntityProfileSession, hardTokenSession, userAdminSession);
          final Admin admin = ejbhelper.getAdmin();
          logAdminName(admin,logger);
          final Query query = ejbhelper.convertUserMatch(admin, usermatch);           
          final Collection<UserDataVO> result = userAdminSession.query(admin, query, null,null, MAXNUMBEROFROWS); // also checks authorization
          if (result.size() > 0) {
            retval = new ArrayList<UserDataVOWS>(result.size());
            for (final UserDataVO userdata : result) {
              retval.add(ejbhelper.convertUserDataVO(admin,userdata));
View Full Code Here

        while (iterator.hasNext()) {
          String logDeviceName = iterator.next();
          if (logDeviceName.equalsIgnoreCase(Log4jLogDevice.DEFAULT_DEVICE_NAME)) {
            continue;
          }
          Query query = new Query(Query.TYPE_LOGQUERY);
          query.add(LogMatch.MATCH_WITH_COMMENT,BasicMatch.MATCH_TYPE_EQUALS,"Test");
          result = logSession.query(logDeviceName, query, "", "cAId=" + Integer.toString(getTestCAId()), 500);
          Iterator<LogEntry> iter = result.iterator();
          boolean found = false;
          while (iter.hasNext()) {
            LogEntry entry = iter.next();
View Full Code Here

        while (iterator.hasNext()) {
          String logDeviceName = iterator.next();
          if (logDeviceName.equalsIgnoreCase(Log4jLogDevice.DEFAULT_DEVICE_NAME)) {
            continue;
          }
          Query query = new Query(Query.TYPE_LOGQUERY);
          query.add(LogMatch.MATCH_WITH_COMMENT, BasicMatch.MATCH_TYPE_EQUALS, "Test of rollback resistance of log-system.");
          result = logSession.query(logDeviceName, query, "", "cAId=" + 0, 500);
          Iterator<LogEntry> iter = result.iterator();
          boolean found = false;
          while (iter.hasNext()) {
            LogEntry entry = iter.next();
View Full Code Here

        resultMinor = XKMSConstants.RESULTMINOR_MESSAGENOTSUPPORTED;
      }
    }else{
      // Check that UseKeyWith isn't empty
      if(queryKeyBindingType.getUseKeyWith().size() >0){
        Query query = genQueryFromUseKeyWith(queryKeyBindingType.getUseKeyWith());
               
        try {               
          Collection<UserDataVO> userDatas = userAdminSession.query(pubAdmin, query, null, null, resSize);
          if (log.isDebugEnabled()) {
            log.debug("userAdminSession.query returned " + userDatas.size() + " results for query \"" + query.getQueryString() + "\"");
          }
          Iterator<UserDataVO> userIter = userDatas.iterator();
          while(userIter.hasNext() && retval.size() <= resSize){
            UserDataVO nextUser = userIter.next();
            // Find all the certificates of the matching users
View Full Code Here

  }


  
   protected Query genQueryFromUseKeyWith(List<UseKeyWithType> list){
     Query retval = new Query(Query.TYPE_USERQUERY);
     boolean retvalEmpty = true;
    
     Iterator<UseKeyWithType> iter = list.iterator();
     while(iter.hasNext()){

       if(!retvalEmpty){
        retval.add(Query.CONNECTOR_OR);  
       }
      
       UseKeyWithType useKeyWithType =  iter.next();
       if(useKeyWithType.getApplication().equals(XKMSConstants.USEKEYWITH_XKMS)||
            useKeyWithType.getApplication().equals(XKMSConstants.USEKEYWITH_XKMSPROFILE) ||
            useKeyWithType.getApplication().equals(XKMSConstants.USEKEYWITH_TLS)){
          retval.add(UserMatch.MATCH_WITH_URI,UserMatch.MATCH_TYPE_BEGINSWITH,useKeyWithType.getIdentifier());
          retvalEmpty=false;
       }
       if(useKeyWithType.getApplication().equals(XKMSConstants.USEKEYWITH_SMIME)||
          useKeyWithType.getApplication().equals(XKMSConstants.USEKEYWITH_PGP)){
         retval.add(UserMatch.MATCH_WITH_RFC822NAME,UserMatch.MATCH_TYPE_BEGINSWITH,useKeyWithType.getIdentifier());
         retvalEmpty=false;
       }
       if(useKeyWithType.getApplication().equals(XKMSConstants.USEKEYWITH_TLSHTTP)){
         retval.add(UserMatch.MATCH_WITH_COMMONNAME,UserMatch.MATCH_TYPE_BEGINSWITH,useKeyWithType.getIdentifier());
         retvalEmpty=false;        
       }
       if(useKeyWithType.getApplication().equals(XKMSConstants.USEKEYWITH_TLSSMTP)){
         retval.add(UserMatch.MATCH_WITH_DNSNAME,UserMatch.MATCH_TYPE_BEGINSWITH,useKeyWithType.getIdentifier());
         retvalEmpty=false;        
       }      
       if(useKeyWithType.getApplication().equals(XKMSConstants.USEKEYWITH_IPSEC)){
         retval.add(UserMatch.MATCH_WITH_IPADDRESS,UserMatch.MATCH_TYPE_BEGINSWITH,useKeyWithType.getIdentifier());
         retvalEmpty=false;
       }
       if(useKeyWithType.getApplication().equals(XKMSConstants.USEKEYWITH_PKIX)){
         retval.add(UserMatch.MATCH_WITH_DN,UserMatch.MATCH_TYPE_EQUALS,CertTools.stringToBCDNString(useKeyWithType.getIdentifier()));
         retvalEmpty=false;
       }
      

     }
View Full Code Here

        if (userAdminSession.existsUser(admin, userdata.getUsername())) {
          // a user already exists, so this is an edit entity request we are preparing
          log.debug("User already exist, we will look for an edit end entity request");
          approvalid = ear.generateApprovalId();
        }
    Query query = new Query(Query.TYPE_APPROVALQUERY);   
    query.add(ApprovalMatch.MATCH_WITH_APPROVALID, BasicMatch.MATCH_TYPE_EQUALS, Integer.toString(approvalid), Query.CONNECTOR_AND);
    query.add(ApprovalMatch.MATCH_WITH_STATUS, BasicMatch.MATCH_TYPE_EQUALS, "" + ApprovalDataVO.STATUS_WAITINGFORAPPROVAL, Query.CONNECTOR_AND);
    Date now = new Date();
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.HOUR_OF_DAY, -1);
    query.add(cal.getTime(), now);
        RAAuthorization raAuthorization = new RAAuthorization(admin, globalConfigurationSession, authorizationSession, caSession, endEntityProfileSession);
    List<ApprovalDataVO> approvals = approvalSession.query(admin, query, 0, 25, raAuthorization.getCAAuthorizationString(), raAuthorization.getEndEntityProfileAuthorizationString());
    // If there is an request waiting for approval we don't have to go on and try to add the user
        if (approvals.size() > 0) {
          log.debug("Found at least one waiting approval request for approvalid: "+approvalid);
          throw new ApprovalException("There is already an existing approval request pending for approvalid: "+approvalid);
        }
       
    // If there is no waiting request which should be the most common, we check If there is an existing reject withing the last 30 minutes
        // If there is a reject, we will cancel this request. A new request will then probably not be possible to create until 30 minutes have passed
    query = new Query(Query.TYPE_APPROVALQUERY);   
    query.add(ApprovalMatch.MATCH_WITH_APPROVALID, BasicMatch.MATCH_TYPE_EQUALS, Integer.toString(approvalid), Query.CONNECTOR_AND);
    query.add(ApprovalMatch.MATCH_WITH_STATUS, BasicMatch.MATCH_TYPE_EQUALS, "" + ApprovalDataVO.STATUS_EXECUTIONDENIED, Query.CONNECTOR_AND);
    cal = Calendar.getInstance();
    cal.add(Calendar.MINUTE, APPROVAL_REJECT_TIMEOUT);
    query.add(cal.getTime(), now);
    approvals = approvalSession.query(admin, query, 0, 25, raAuthorization.getCAAuthorizationString(), raAuthorization.getEndEntityProfileAuthorizationString());
    // If there is an request waiting for approval we don't have to go on and try to add the user
        if (approvals.size() > 0) {
          log.debug("Found at least one rejected approval request for approvalid: "+approvalid);
          throw new Exception("Approval request was rejected for approvalid: "+approvalid);
        }

    // Check if it failed as well...
    query = new Query(Query.TYPE_APPROVALQUERY);   
    query.add(ApprovalMatch.MATCH_WITH_APPROVALID, BasicMatch.MATCH_TYPE_EQUALS, Integer.toString(approvalid), Query.CONNECTOR_AND);
    query.add(ApprovalMatch.MATCH_WITH_STATUS, BasicMatch.MATCH_TYPE_EQUALS, "" + ApprovalDataVO.STATUS_EXECUTIONFAILED, Query.CONNECTOR_AND);
    cal = Calendar.getInstance();
    cal.add(Calendar.MINUTE, -30);
    query.add(cal.getTime(), now);
    approvals = approvalSession.query(admin, query, 0, 25, raAuthorization.getCAAuthorizationString(), raAuthorization.getEndEntityProfileAuthorizationString());
    // If there is an request waiting for approval we don't have to go on and try to add the user
        if (approvals.size() > 0) {
          log.debug("Found at least one failed approval request for approvalid: "+approvalid);
          throw new Exception("Approval request execution failed for approvalid: "+approvalid);
View Full Code Here

                            if (approvalType == ApprovalDataVO.APPROVALTYPE_REVOKECERTIFICATE) {
                                    approvalID = RevocationApprovalRequest.generateApprovalId(approvalType, username, reason, serialNumber, issuerDN);
                            } else {
                                    approvalID = RevocationApprovalRequest.generateApprovalId(approvalType, username, reason, null, null);
                            }
                            Query q = new Query(Query.TYPE_APPROVALQUERY);
                            q.add(ApprovalMatch.MATCH_WITH_APPROVALID, BasicMatch.MATCH_TYPE_EQUALS, Integer.toString(approvalID));
                            ApprovalDataVO approvalData = (ApprovalDataVO) (approvalSession.query(internalAdmin, q, 0, 1, "cAId="+approvalCAID, "(endEntityProfileId="+SecConst.EMPTY_ENDENTITYPROFILE+")").get(0));
                            Approval approval = new Approval("Approved during testing.");
                            approvalExecutionSession.approve(approvingAdmin, approvalID, approval, raAdminSession.getCachedGlobalConfiguration(new Admin(Admin.INTERNALCAID)));
                            approvalData = (ApprovalDataVO) approvalSession.findApprovalDataVO(internalAdmin, approvalID).iterator().next();
                            assertEquals(approvalData.getStatus(), ApprovalDataVO.STATUS_EXECUTED);
View Full Code Here

      log.debug("ApproveActionSessionBean.setApprovalId setting uniqueId : " + uniqueId);
      updateApprovalRequestData(uniqueId)
    }

    public void updateApprovalRequestData(int id){
      Query query = new Query(Query.TYPE_APPROVALQUERY);
      query.add(ApprovalMatch.MATCH_WITH_UNIQUEID, BasicMatch.MATCH_TYPE_EQUALS, Integer.toString(id));
      List<ApprovalDataVO> result;
      try {
        RAAuthorization raAuthorization = new RAAuthorization(EjbcaJSFHelper.getBean().getAdmin(), ejb.getGlobalConfigurationSession(),
            ejb.getAuthorizationSession(), ejb.getCaSession(), ejb.getEndEntityProfileSession());
        result = ejb.getApprovalSession().query( EjbcaJSFHelper.getBean().getAdmin(), query, 0, 1, raAuthorization.getCAAuthorizationString(), raAuthorization.getEndEntityProfileAuthorizationString());
View Full Code Here

     * @param size the number of elements to return.
     */
    public LogEntriesView filterByUsername(String deviceName, String username, Map<Integer,String> caidtonamemap) throws IllegalQueryException {
      LogEntriesView returnval = new LogEntriesView(dnproxy, localinfoeventnamesunsorted, localerroreventnamesunsorted, localsystemeventnamesunsorted, localmodulenamesunsorted,  caidtonamemap)
      String user = StringTools.strip(username)
      Query query = new Query(Query.TYPE_LOGQUERY);
      query.add(LogMatch.MATCH_WITH_USERNAME, BasicMatch.MATCH_TYPE_EQUALS, user);
      Collection<LogEntry> logentries = logSession.query(deviceName, query,informationmemory.getViewLogQueryString(), informationmemory.getViewLogCAIdString(), MAXIMUM_QUERY_ROWCOUNT);
      returnval.setEntries(logentries);
      lastquery = query;
      return returnval;       
    }       
View Full Code Here

TOP

Related Classes of org.ejbca.util.query.Query

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.