Package com.alu.e3.data.model

Examples of com.alu.e3.data.model.Auth


  @Override
  public Auth getWsseAuth(String username, String password, boolean isPasswordText, String nonce, String created) {
    if(username == null || password == null) {
      return null;
    }
    Auth auth = getAuthByToken(createWsseTokenFromUser(username), false);
    if (auth != null) {
     
      // PasswordText
      if(isPasswordText) {
        String storedPassword = new String(auth.getWssePassword());
        if(storedPassword.equals(password)) {
          return auth;
        } else {
          return null;
        }
       
      // Digest password
      } else {
        if (created != null) {
          long then;
          try {
            then = WsseTools.getCreatedDate(created).getTime();
          } catch (ParseException e) {
            if (logger.isDebugEnabled()) {
              logger.debug("invalid WSSE: created parse error: " + created);
            }
            return null;
          }
          long now = System.currentTimeMillis();
          if (then > now + (WSSE_AGE_SECONDS * 1000)) {   // allow client to be up to 5 minutes in the future
            if (logger.isDebugEnabled()) {
              logger.debug("invalid WSSE: created in the future: " + created);
            }
            return null;
          } else if (then < now - (WSSE_AGE_SECONDS * 1000)) {
            if (logger.isDebugEnabled()) {
              logger.debug("invalid WSSE: old created: " + created);
            }
            return null;
          }
        }
        if (WsseTools.isValid(password, nonce, created, auth.getWssePassword())) {
          if (nonce != null && liveNonces.contains(nonce)) {
            if (logger.isDebugEnabled()) {
              logger.debug("invalid WSSE: familiar nonce: " + nonce + " (created " + created + ")");
            }
            return null;
View Full Code Here


  }

  @Override
  public Auth getAuthMatching(IAuthMatcher authMatcher) {

    Auth auth = null;

    ClassLoader previousClassLoader = Thread.currentThread().getContextClassLoader();

    Thread.currentThread().setContextClassLoader(DataManager.class.getClassLoader());
View Full Code Here

      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");
      }
    }

    for (QuotaRLBucket bucket : policy.getAuthIds()) {
      checkIfAuthAlreadyInPolicy(policy.getId(), bucket.getAuthIds(), bucket.getId());
    }

    Policy cachedPolicy = null;

    if(update) {
      cachedPolicy = getPolicyById(policy.getId(), false);

      // Remove existing contexts
      for (Integer contextId : cachedPolicy.getContextIds()) {
        cachingTableContext.remove(contextId);
      }
    }

    policy.getContextIds().clear();

    // TODO: Check value of quota, if changed, then reset the created date, otherwise, keep old value
    //=> Speaker needs to store the created date

    // Store all contexts aside, indexed by an int
    for (Context ctx : policy.getContexts()) {
      boolean ok = false;

      while (!ok) {
        int idx = (int)(Math.random() * Integer.MAX_VALUE);
        Integer contextId = Integer.valueOf(idx);
        if (!cachingTableContext.containsKey(contextId)) {
          ctx.setContextId(contextId);
          ctx.setCreatedDate(new Date());
          cachingTableContext.set(contextId, new ContextWrapper(ctx));
          policy.getContextIds().add(contextId);
          ok = true;
        }
      }
    }

    // Store all contexts aside, indexed by an int
    for (QuotaRLBucket bucket : policy.getAuthIds()) {
      boolean ok = false;

      if ((cachedPolicy != null) && ((bucket.getId() == null) || (bucket.getId().equals("")))) {
        // First, try to find the current bucket in the old policy
        for (QuotaRLBucket cachedBucket : cachedPolicy.getAuthIds()) {
          if (cachedBucket.getId().equals(bucket.getId())) {
            // Bucket was already in old policy
            bucket.setBucketId(cachedBucket.getBucketId());
            cachedPolicy.getAuthIds().remove(cachedBucket);
            ok = true;
            break;
          }
        }
      }

      while (!ok) {
        int idx = (int)(Math.random() * Integer.MAX_VALUE);
        Integer bucketId = Integer.valueOf(idx);
        if (!usedBucketIds.contains(bucketId)) {
          bucket.setBucketId(bucketId);
          usedBucketIds.add(bucketId);

          if ((bucket.getId() == null) || (bucket.getId().equals(""))) {
            bucket.setId(bucketId.toString());
          }

          ok = true;
        }
      }
    }

    if (cachedPolicy != null) {
      // Now remove all buckets which are not in the new policy
      for (QuotaRLBucket cachedBucket : cachedPolicy.getAuthIds()) {
        usedBucketIds.remove(cachedBucket.getBucketId());
        for (IDataManagerUsedBucketIdsListener listner : this.usedBucketIdslisteners)
        {
          listner.usedBucketIdsRemoved(cachedBucket.getBucketId());
        }
      }
    }

    cachingTablePolicy.set(policy.getId(), policy);

    // Now, iterate through all APIs and Auth in this policy and update them
    for (String apiId : policy.getApiIds()) {
      Api api = getApiById(apiId);
      if (api.getPolicyIds().indexOf(policy.getId()) < 0)
      {
        api.getPolicyIds().add(policy.getId());
        cachingTableApi.set(api.getId(), api);
      }
    }

    for (QuotaRLBucket bucket : policy.getAuthIds()) {
      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 policy: add a AuthContext object with PolicyId, LimitId, BucketId (instead of just PolicyId) => LimitId should be crossed with "policyContext" on 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(policy.getId(), bucket.getId(), getPolicyContextId(auth, policy), bucket.getBucketId(), auth.getStatus().isActive()));
          cachingTableAuth.set(authToken, auth);
        }
      }
    }
  }
View Full Code Here

      for(String authId : bucket.getAuthIds()) {
        String authToken = cachingTableAuthIdToAuthToken.get(authId);
        if (authToken == null)
          continue;

        Auth auth = cachingTableAuth.get(authToken);
        if (auth == null)
          continue;

        for (AuthIds authCtx : auth.getPolicyContexts()) {
          if (authCtx.getPolicyId().equals(policy.getId())) {
            auth.getPolicyContexts().remove(authCtx);
            break;
          }
        }
        cachingTableAuth.set(authToken, auth);
      }
View Full Code Here

    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 policy
      if (bucket.getAuthIds().indexOf(auth.getId()) < 0) {
        bucket.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, bucket.getId(), getPolicyContextId(auth, policy), bucket.getBucketId(), auth.getStatus().isActive()));
        cachingTableAuth.set(authToken, auth);
      }
    }
  }
View Full Code Here

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

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

      boolean found = false;
      for (AuthIds authCtx : auth.getPolicyContexts()) {
        if (authCtx.getPolicyId().equals(policyId)) {
          if(!authCtx.getBucketId().equals(bucketId)){
            // Auth should not exist in another bucket
            found = true;
          }
View Full Code Here

      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

    String authToken = cachingTableAuthIdToAuthToken.get(authId);
    if (authToken == null)
      throw new InvalidIDException("An Authorization with that ID [" + authId + "] doesn't exist");

    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())) {
        auth.getPolicyContexts().remove(authCtx);
        cachingTableAuth.set(authToken, auth);
        break;
      }
    }
  }
View Full Code Here

  @Test
  public void testAddGetRemoveAuth() {

    // Add a new Auth
    Auth auth = new Auth();
    auth.setId("id2");
    auth.setAuthDetail(new AuthDetail());
    auth.getAuthDetail().setUsername("username");
    auth.getAuthDetail().setType(NBAuthType.AUTHKEY);
    auth.getAuthDetail().setAuthKeyValue("authKey");
    dataManager.addAuth(auth);

    // Now, get the "simple" Auth and check that it's OK
    Auth auth2 = dataManager.getAuthById("id2");
    assertNotNull("Auth was added/returned", auth2);
    assertNull("Auth  details is null", auth2.getAuthDetail());

    // Now, get the "full" Auth and check that it's OK
    Auth auth3 = dataManager.getAuthById("id2", true);
    assertNotNull("Auth was added/returned", auth3);
    assertEquals("Auth values are correct", auth.getAuthDetail().getUsername(), auth3.getAuthDetail().getUsername());

    dataManager.removeAuth("id2");

    boolean isInvalidID = false;
View Full Code Here

      String authToken = cachingTableAuthIdToAuthToken.get(authId);
      if (authToken == null)
        continue;

      Auth auth = cachingTableAuth.get(authToken);
      if (auth == null)
        continue;

      // Remove policy from auth
      for (AuthIds authCtx : auth.getPolicyContexts()) {
        if (authCtx.getPolicyId().equals(policy.getId())) {
          auth.getPolicyContexts().remove(authCtx);
          cachingTableAuth.set(authToken, auth);
          break;
        }
      }
    }
View Full Code Here

TOP

Related Classes of com.alu.e3.data.model.Auth

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.