Package com.alu.e3.data.model.sub

Examples of com.alu.e3.data.model.sub.QuotaRLBucket


    policy.setId("id3");
    policy.getApiIds().add(api.getId());
    dataManager.addPolicy(policy);

    // Create bucket
    QuotaRLBucket authIds = new QuotaRLBucket();
    authIds.setId("id3");
    authIds.getAuthIds().add(auth.getId());
    dataManager.createBucket(policy.getId(), authIds);

    // Now, get the API and check that it's OK
    Api api2 = dataManager.getApiById("id1");
    assertEquals("API has new policy", policy.getId(), api2.getPolicyIds().get(0));

    // Now, get the Auth and check that it's OK
    Auth auth2 = dataManager.getAuthById("id2");
    assertEquals("Auth has new policy", policy.getId(), auth2.getPolicyContexts().get(0).getPolicyId());

    // Check that bucket is added correctly to policy
    policy = dataManager.getPolicyById(policy.getId());
    assertEquals("Correct number of buckets for policy", 1, policy.getAuthIds().size());
    assertEquals("Policy has new bucket", authIds.getId(), policy.getAuthIds().get(0).getId());   

    dataManager.removePolicy(policy.getId());

    // Now, get the API and check that it's OK
    Api api3 = dataManager.getApiById("id1");
View Full Code Here


    // Add a new Policy
    Policy policy = new Policy();
    policy.setId("id53");
    policy.getApiIds().add(api.getId());
    QuotaRLBucket authIds = new QuotaRLBucket();
    authIds.setId("bucketId");
    authIds.getAuthIds().add(auth.getId());
    policy.getAuthIds().add(authIds);
    dataManager.addPolicy(policy);

    dataManager.removeApi(api.getId());
View Full Code Here

    auth.getAuthDetail().setType(NBAuthType.AUTHKEY);
    auth.getAuthDetail().setAuthKeyValue("authKey30");
    dataManager.addAuth(auth);

    // Add a new Policy
    QuotaRLBucket authIds = new QuotaRLBucket();
    authIds.setId("id63");
    authIds.getAuthIds().add(auth.getId());

    Policy policy = new Policy();
    policy.setId("id64");
    policy.getApiIds().add(api.getId());
    policy.getAuthIds().add(authIds);
View Full Code Here

    Policy policy = new Policy();
    policy.setId("id31");
    policy.getApiIds().add(api.getId());

    // Create Bucket authIds of auth ids
    QuotaRLBucket authIds = new QuotaRLBucket();
    authIds.setId("bucketId");
    authIds.getAuthIds().add(auth.getId());
    // Add bucket authIds to policy
    policy.getAuthIds().add(authIds);

    dataManager.addPolicy(policy);

    // Add a new Policy: Associated to API id2, API id3 and Auth id2, id4
    Policy policy2 = new Policy();
    policy2.setId("id32");
    policy2.getApiIds().add(api2.getId());
    policy2.getApiIds().add(api3.getId());

    // Create Bucket authIds2 of auth ids
    QuotaRLBucket authIds2 = new QuotaRLBucket();
    authIds.setId("bucketId2");
    authIds2.getAuthIds().add(auth2.getId());
    authIds2.getAuthIds().add(auth4.getId());
    // Add bucket authIds2 to the policy
    policy2.getAuthIds().add(authIds2);

    dataManager.addPolicy(policy2);


    // Add a new Policy: Associatd to API id4 and no Auth
    Policy policy3 = new Policy();
    policy3.setId("id33");
    policy3.getApiIds().add(api4.getId());
    dataManager.addPolicy(policy3);


    // Add a new Policy: Associatd to no API and Auth id3
    Policy policy4 = new Policy();
    policy4.setId("id34");

    // Create Bucket authIds4 of auth ids
    QuotaRLBucket authIds4 = new QuotaRLBucket();
    authIds.setId("bucketId4");
    authIds4.getAuthIds().add(auth3.getId());
    // Add bucket authIds4 to the policy
    policy4.getAuthIds().add(authIds4);

    dataManager.addPolicy(policy4);


    // Add a new Policy: Associatd to API id3 and no Auth
    Policy policy5 = new Policy();
    policy5.setId("id35");
    policy5.getApiIds().add(api3.getId());
    dataManager.addPolicy(policy5);


    // Add a new Policy: Associatd to API id3 and Auth id3
    Policy policy6 = new Policy();
    policy6.setId("id36");
    policy6.getApiIds().add(api3.getId());

    // Create Bucket authIds6  of auth ids
    QuotaRLBucket authIds6 = new QuotaRLBucket();
    authIds.setId("bucketId6");
    authIds6.getAuthIds().add(auth3.getId());
    // Add bucket authIds6 to the policy
    policy6.getAuthIds().add(authIds6);

    dataManager.addPolicy(policy6);


    // Add a new Policy: Associatd to no API and Auth id2
    Policy policy7 = new Policy();
    policy7.setId("id37");

    // Create Bucket authIds7  of authId2
    QuotaRLBucket authIds7 = new QuotaRLBucket();
    authIds.setId("bucketId7");
    authIds7.getAuthIds().add(auth2.getId());
    // Add bucket authIds7 to the policy
    policy7.getAuthIds().add(authIds7);

    dataManager.addPolicy(policy7);
View Full Code Here

    policy.setId("policyId1");
    policy.getApiIds().add(api.getId());
    dataManager.addPolicy(policy);

    // Create bucket to add new Auth
    QuotaRLBucket authIds = new QuotaRLBucket();
    authIds.setId("bucketId1");
    authIds.getAuthIds().add(auth.getId());
    dataManager.createBucket(policy.getId(), authIds);
    // fetch updated policy from the cache
    policy = dataManager.getPolicyById(policy.getId());

    // Now, get the API and check that it's OK
    Api api2 = dataManager.getApiById(api.getId());
    assertEquals("API has new policy", policy.getId(), api2.getPolicyIds().get(0));

    // Now, get the Auth and check that it's OK
    Auth auth2 = dataManager.getAuthById(auth.getId());
    assertEquals("Auth has new policy", policy.getId(), auth2.getPolicyContexts().get(0).getPolicyId());

    // Check that bucket is added correctly to policy
    assertEquals("Correct number of buckets for policy", 1, policy.getAuthIds().size());
    assertEquals("Policy has new bucket", authIds.getId(), policy.getAuthIds().get(0).getId());   

    dataManager.removePolicy(policy.getId());

    // Now, get the API and check that it's OK
    Api api3 = dataManager.getApiById(api.getId());
View Full Code Here

    policy.setId("policyId1");
    policy.getApiIds().add(api.getId());
    dataManager.addPolicy(policy);

    // Create bucket to add new Auth
    QuotaRLBucket authIds = new QuotaRLBucket();
    authIds.setId("bucketId1");
    authIds.getAuthIds().add(auth.getId());
    dataManager.createBucket(policy.getId(), authIds);
    // fetch updated policy from the cache
    policy = dataManager.getPolicyById(policy.getId());

    // Now, get the API and check that it's OK
    Api gApi1 = dataManager.getApiById(api.getId());
    assertEquals("API has new policy", policy.getId(), gApi1.getPolicyIds().get(0));

    // Now, get the Auth and check that it's OK
    Auth gAuth1 = dataManager.getAuthById(auth.getId());
    assertEquals("Auth has new policy", policy.getId(), gAuth1.getPolicyContexts().get(0).getPolicyId());

    // Check that bucket is added correctly to policy
    assertEquals("Correct number of buckets for policy", 1, policy.getAuthIds().size());
    assertEquals("Policy has new bucket", authIds.getId(), policy.getAuthIds().get(0).getId())

    // Append a new Auth to the bucket
    QuotaRLBucket authIdsToAppend = new QuotaRLBucket();
    authIdsToAppend.getAuthIds().add(auth2.getId());
    dataManager.addAuthsToBucket(policy.getId(), authIds.getId(), authIdsToAppend);
    // fetch updated policy from the cache
    policy = dataManager.getPolicyById(policy.getId());

    // Check that auth2 has been appended to original bucket
View Full Code Here

    policy.setId("policyId1");
    policy.getApiIds().add(api.getId());
    dataManager.addPolicy(policy);

    // Create bucket to add new Auth
    QuotaRLBucket authIds = new QuotaRLBucket();
    authIds.setId("bucketId1");
    authIds.getAuthIds().add(auth.getId());
    dataManager.createBucket(policy.getId(), authIds);

    // fetch policy from the cache
    policy = dataManager.getPolicyById(policy.getId());

    // Now, get the API and check that it's OK
    Api gApi1 = dataManager.getApiById(api.getId());
    assertEquals("API has new policy", policy.getId(), gApi1.getPolicyIds().get(0));

    // Now, get the Auth and check that it's OK
    Auth gAuth1 = dataManager.getAuthById(auth.getId());
    assertEquals("Auth has new policy", policy.getId(), gAuth1.getPolicyContexts().get(0).getPolicyId());

    // Check that bucket is added correctly to policy
    assertEquals("Correct number of buckets for policy", 1, policy.getAuthIds().size());
    assertEquals("Policy has new bucket", authIds.getId(), policy.getAuthIds().get(0).getId())

    // Append a new Auth to the bucket
    QuotaRLBucket authIdsToAppend = new QuotaRLBucket();
    authIdsToAppend.getAuthIds().add(auth2.getId());
    dataManager.addAuthsToBucket(policy.getId(), authIds.getId(), authIdsToAppend);

    // fetch policy from the cache
    policy = dataManager.getPolicyById(policy.getId());

    // Check that auth2 has been appended to original bucket
    Auth gAuth2 = dataManager.getAuthById(auth2.getId());
    assertEquals("Auth has new policy", policy.getId(), gAuth2.getPolicyContexts().get(0).getPolicyId());
    assertEquals("Correct number of buckets for policy", 1, policy.getAuthIds().size());
    assertEquals("Correct number of auths in the bucket", 2, policy.getAuthIds().get(0).getAuthIds().size());

    // Retry appending the same auth to the same bucket
    dataManager.addAuthsToBucket(policy.getId(), authIds.getId(), authIdsToAppend);

    // fetch policy from the cache
    policy = dataManager.getPolicyById(policy.getId());

    // Check that auth hasn't been added twice
    assertEquals("Correct number of auths in the bucket", 2, policy.getAuthIds().get(0).getAuthIds().size());

    // Create a new bucket containing a third auth
    QuotaRLBucket authIds2 = new QuotaRLBucket();
    authIds2.setId("bucketId2");
    authIds2.getAuthIds().add(auth3.getId());
    dataManager.createBucket(policy.getId(), authIds2);

    // fetch policy from the cache
    policy = dataManager.getPolicyById(policy.getId());

    // Check that bucket has been added correctly
    assertEquals("Correct number of buckets for policy", 2, policy.getAuthIds().size());

    // Just to be sure that order is maintained
    QuotaRLBucket bucket1, bucket2;
    if(policy.getAuthIds().get(0).getId().equals(authIds.getId())) {
      bucket1 = policy.getAuthIds().get(0);
      bucket2 = policy.getAuthIds().get(1);
    } else {
      bucket1 = policy.getAuthIds().get(1);
      bucket2 = policy.getAuthIds().get(0);
    }

    assertEquals("Correct number of auths in the bucket 1", 2, bucket1.getAuthIds().size());
    assertEquals("Correct number of auths in the bucket 2", 1, bucket2.getAuthIds().size());

    // removing auth3 from bucket2
    dataManager.removeAuthFromBucket(policy.getId(), bucket2.getId(), auth3.getId());

    // fetch policy from the cache
    policy = dataManager.getPolicyById(policy.getId());

    assertEquals("Correct number of buckets for policy", 2, policy.getAuthIds().size());
    assertEquals("Correct number of auths in the bucket 1", 2, bucket1.getAuthIds().size());
    assertEquals("Correct number of auths in the bucket 2", 0, bucket2.getAuthIds().size());

    // Now, get auth3 and check that it's no more associated with the policy
    Auth gAuth3_2 = dataManager.getAuthById(auth3.getId());
    assertEquals("Auth has no policy", 0, gAuth3_2.getPolicyContexts().size());
View Full Code Here

    Policy policy = new Policy();
    policy.setId("id31");
    policy.getApiIds().add(api.getId());

    // Create Bucket authIds of auth ids
    QuotaRLBucket authIds = new QuotaRLBucket();
    authIds.setId("bucketId");
    authIds.getAuthIds().add(auth.getId());
    authIds.getAuthIds().add(auth2.getId());
    authIds.getAuthIds().add(auth3.getId());

    // Add bucket authIds to policy
    policy.getAuthIds().add(authIds);

    dataManager.addPolicy(policy);
View Full Code Here

  public void addAuthsToBucket(String policyId, String bucketId, QuotaRLBucket bucket) throws IllegalArgumentException {

    Policy policy = getPolicyById(policyId);

    // Find the correct bucket in this policy
    QuotaRLBucket pAuthIds = getBucketWithIdForPolicy(policy, bucketId);
    if(pAuthIds == null) {
      throw new IllegalArgumentException("A Bucket with that ID [" + bucketId + "] doesn't exist for this Policy [" + policyId + "]");
    }

    checkIfAuthAlreadyInPolicy(policyId, bucket.getAuthIds(), bucketId);

    for(String authId : bucket.getAuthIds()) {

      String authToken = cachingTableAuthIdToAuthToken.get(authId);
      if (authToken == null)
        throw new IllegalArgumentException("Auth ID [" + authId + "] not found");

      Auth auth = cachingTableAuth.get(authToken);
      if (auth == null)
        throw new IllegalArgumentException("Auth token not found");

      // Add auth to the bucket
      if (pAuthIds.getAuthIds().indexOf(auth.getId()) < 0)
      {
        pAuthIds.getAuthIds().add(auth.getId());
        cachingTablePolicy.set(policy.getId(), policy);
      }

      // Add policy to auth
      boolean found = false;
      for (AuthIds authCtx : auth.getPolicyContexts()) {
        if (authCtx.getPolicyId().equals(policy.getId())) {
          //update Auth with good Policy context and bucket
          authCtx.setPolicyContextId(getPolicyContextId(auth, policy));
          authCtx.setPolicyBucketId(bucket.getBucketId());
          cachingTableAuth.set(authToken, auth);//updating auth
          found = true;
          break;
        }
      }

      if (!found) {
        auth.getPolicyContexts().add(new AuthIds(policyId, bucketId, getPolicyContextId(auth, policy), pAuthIds.getBucketId(), auth.getStatus().isActive()));
        cachingTableAuth.set(authToken, auth);
      }
    }
  }
View Full Code Here

    Auth auth = cachingTableAuth.get(authToken);
    if (auth == null)
      throw new InvalidIDException("An Authorization with that token doesn't exist");

    QuotaRLBucket pAuthIds = getBucketWithIdForPolicy(policy, bucketId);
    if(pAuthIds == null) {
      throw new InvalidIDException("A Bucket with that ID [" + bucketId + "] doesn't exist for this Policy [" + policyId + "]");
    }

    // Remove auth from the bucket
    pAuthIds.getAuthIds().remove(auth.getId());
    cachingTablePolicy.set(policy.getId(), policy);

    // Remove policy from auth
    for (AuthIds authCtx : auth.getPolicyContexts()) {
      if (authCtx.getPolicyId().equals(policy.getId())) {
View Full Code Here

TOP

Related Classes of com.alu.e3.data.model.sub.QuotaRLBucket

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.