Package com.alu.e3.common.tools

Examples of com.alu.e3.common.tools.CanonicalizedIpAddress


  public void process(Exchange exchange) throws Exception {
    Api api = this.dataManager.getApiById(apiId, false);
    HttpServletRequest request = (HttpServletRequest) exchange.getIn().getHeader(Exchange.HTTP_SERVLET_REQUEST);
    //retrieve the real IP adress from the request
    String remoteAddr = CommonTools.remoteAddr(request);
    CanonicalizedIpAddress ip = new CanonicalizedIpAddress(remoteAddr);
    if(this.dataManager.isIpAllowed(api, ip.getIp())) {
      exchange.setProperty(ExchangeConstantKeys.E3_API.toString(), api);   
    }
    else {
      Exception exception = new GatewayException(GatewayExceptionCode.AUTHORIZATION, "Not Authorized from this IP address");
      exchange.setException(exception);     
View Full Code Here


   
    fileData = new FileData(fileURL.getPath());
   
    assertNotNull(fileData.checkAllowed(api, "appKey1234").getAuthIdentity());
    assertNotNull(fileData.checkAllowed(api, "user", "pass").getAuthIdentity());
    assertNotNull(fileData.checkAllowed(api, new CanonicalizedIpAddress("127.0.0.1")).getAuthIdentity());
    assertNotNull(fileData.checkAllowed(api).getAuthIdentity());
   
    api.setId("apiASDF");
   
    assertNull(fileData.checkAllowed(api, "badbad").getAuthIdentity());
    assertNull(fileData.checkAllowed(api, "bad", "bad").getAuthIdentity());
    assertNull(fileData.checkAllowed(api, new CanonicalizedIpAddress("10.0.0.1")).getAuthIdentity());
    assertNull(fileData.checkAllowed(api, "badbad", "badbad").getAuthIdentity());
    assertNull(fileData.checkAllowed(api).getAuthIdentity());
  }
View Full Code Here

   
    if(request != null) {
      //retrieve the real IP adress from the request
      String remoteAddr = CommonTools.remoteAddr(request);
         
          CanonicalizedIpAddress ip = new CanonicalizedIpAddress(remoteAddr);
      authReport = dataAccess.checkAllowed(api, ip);
    } else {
      authReport.setBadRequest(true);
    }
     
View Full Code Here

    mockDataManager.setApi(api);
   
    // no auth found
    assertNull(dataAccess.checkAllowed(api, "authKey").getAuthIdentity());
    assertNull(dataAccess.checkAllowed(api, "username", "password").getAuthIdentity());
    assertNull(dataAccess.checkAllowed(api, new CanonicalizedIpAddress("127.0.0.1")).getAuthIdentity());
   
    Auth auth = new Auth();
    auth.setStatus(StatusType.ACTIVE);
    mockDataManager.setAuth(auth);
   
    // No policy found
    assertNull(dataAccess.checkAllowed(api, "authKey").getAuthIdentity());
    assertNull(dataAccess.checkAllowed(api, "username", "password").getAuthIdentity());
    assertNull(dataAccess.checkAllowed(api, new CanonicalizedIpAddress("127.0.0.1")).getAuthIdentity());
   
    Policy policy = new Policy();
    mockDataManager.getCallDescriptors().add(new CallDescriptor(policy, 1, 2));
   
    AuthIdentity authIdentity = dataAccess.checkAllowed(api, "authKey").getAuthIdentity();
    assertNotNull(authIdentity);   
    assertNotNull(authIdentity.getApi() == api); // compare memory reference
    assertNotNull(authIdentity.getAuth() == auth); // compare memory reference
    assertNotNull(authIdentity.getCallDescriptors().get(0).getPolicy() == policy); // compare memory reference

    authIdentity = dataAccess.checkAllowed(api, "username", "password").getAuthIdentity();
    assertNotNull(authIdentity);   
    assertNotNull(authIdentity.getApi() == api); // compare memory reference
    assertNotNull(authIdentity.getAuth() == auth); // compare memory reference
    assertNotNull(authIdentity.getCallDescriptors().get(0).getPolicy() == policy); // compare memory reference
   
   
    authIdentity = dataAccess.checkAllowed(api, new CanonicalizedIpAddress("127.0.0.1")).getAuthIdentity();
    assertNotNull(authIdentity)
    assertNotNull(authIdentity.getApi() == api); // compare memory reference
    assertNotNull(authIdentity.getAuth() == auth); // compare memory reference
    assertNotNull(authIdentity.getCallDescriptors().get(0).getPolicy() == policy); // compare memory reference
   
View Full Code Here

    // Create, then begin a transaction
    TransactionContext transactionState1 = executor1.submit( new Callable<TransactionContext>() {
      @Override
      public TransactionContext call() throws Exception {
        ITransactionManager txMnger = new TransactionManager();
        ITransaction tx = txMnger.getNewTransaction();
        tx.begin();
        return txMnger.getTransactionContext();
      }
    }).get();

    assertNotNull(transactionState1);
    assertNotNull(transactionState1.getTransactionId());
   
    // Later, a method in the same thread stack should be able to deal with the same transaction context
    TransactionContext transactionState2 = executor1.submit( new Callable<TransactionContext>() {
      @Override
      public TransactionContext call() throws Exception {
        ITransactionManager txMnger = new TransactionManager();
        return txMnger.getTransactionContext();
      }
    }).get();
   
    assertNotNull(transactionState2);
    assertNotNull(transactionState2.getTransactionId());
    assertEquals(transactionState1.getTransactionId(), transactionState2.getTransactionId());

    // The transaction in a thread must not be viewable from another thread
    ExecutorService executor2 = Executors.newSingleThreadScheduledExecutor();
    TransactionContext transactionState3 = executor2.submit( new Callable<TransactionContext>() {
      @Override
      public TransactionContext call() throws Exception {
        ITransactionManager txMnger = new TransactionManager();
        return txMnger.getTransactionContext();
      }
    }).get();
    assertNull (transactionState3);
   
    transactionState3 = executor2.submit( new Callable<TransactionContext>() {
      @Override
      public TransactionContext call() throws Exception {
        ITransactionManager txMnger = new TransactionManager();
        ITransaction tx = txMnger.getNewTransaction();
        tx.begin();
        return txMnger.getTransactionContext();
      }
    }).get();
   
    assertNotNull (transactionState3);
View Full Code Here

public class TestTransactionManagement {

  @Test
  public void testTransactionInCurrentThread() throws Exception {
    ITransactionManager txMnger = new TransactionManager();
    assertNull(txMnger.getTransactionContext());

    // create, begin, commit, end
    ITransaction tx = txMnger.getNewTransaction();
    assertNotNull(tx);

    // Not transaction id until the transaction has begun
    assertNull(tx.getTransactionId());
    // Not transaction context until the transaction has begun
    assertNull(txMnger.getTransactionContext());


    tx.begin();
    assertNotNull (tx.getTransactionId());
    assertNotNull (txMnger.getTransactionContext().getTransactionId());
    assertEquals (txMnger.getTransactionContext().getTransactionId(), tx.getTransactionId());

    tx.commit();
    assertNotNull (tx.getTransactionId());
    assertNotNull (txMnger.getTransactionContext().getTransactionId());
    assertEquals (txMnger.getTransactionContext().getTransactionId(), tx.getTransactionId());

    tx.end();
    assertNull(tx.getTransactionId());
    assertNull(txMnger.getTransactionContext());

    // create, begin, rollback
    tx = txMnger.getNewTransaction();
    assertNull(tx.getTransactionId());
    assertNull(txMnger.getTransactionContext());

    tx.begin();
    assertNotNull (tx.getTransactionId());
    assertNotNull (txMnger.getTransactionContext().getTransactionId());
    assertEquals (txMnger.getTransactionContext().getTransactionId(), tx.getTransactionId());

    tx.rollback();
    assertNull(tx.getTransactionId());
    assertNull(txMnger.getTransactionContext());

    // begin, commit, rollback
    tx = txMnger.getNewTransaction();
    assertNull(tx.getTransactionId());
    assertNull(txMnger.getTransactionContext());

    tx.begin();
    assertNotNull (tx.getTransactionId());
    assertNotNull (txMnger.getTransactionContext().getTransactionId());
    assertEquals (txMnger.getTransactionContext().getTransactionId(), tx.getTransactionId());

    tx.commit();
    assertNotNull (tx.getTransactionId());
    assertNotNull (txMnger.getTransactionContext().getTransactionId());
    assertEquals (txMnger.getTransactionContext().getTransactionId(), tx.getTransactionId());

    tx.rollback();
    assertNull(tx.getTransactionId());
    assertNull(txMnger.getTransactionContext());
  }
View Full Code Here

    this.apiId = apiId;
  }
 
  @Override
  public void process(Exchange exchange) throws Exception {
    Api api = this.dataManager.getApiById(apiId, false);
    HttpServletRequest request = (HttpServletRequest) exchange.getIn().getHeader(Exchange.HTTP_SERVLET_REQUEST);
    //retrieve the real IP adress from the request
    String remoteAddr = CommonTools.remoteAddr(request);
    CanonicalizedIpAddress ip = new CanonicalizedIpAddress(remoteAddr);
    if(this.dataManager.isIpAllowed(api, ip.getIp())) {
View Full Code Here

    Map<String, String> properties = (Map<String,String>) exchange.getProperty(ExchangeConstantKeys.E3_MODEL_PROPERTIES.toString());
    if(properties == null)
      properties = new HashMap<String, String>();

    // First add the TDRs from the API
    Api api = identity.getApi();
    if (api != null)
      if(doStatic)
        processTdrGenerationRuleStatic(api.getTdrGenerationRule(), exchange, properties);
      else
        processTdrGenerationRuleDynamic(api.getTdrGenerationRule(), exchange, properties, efType);

    // Next add all of the tdr values for the Policies
    Iterator<CallDescriptor> it = identity.getCallDescriptors().iterator();
    while(it.hasNext()){
      CallDescriptor cd = it.next();
View Full Code Here


  protected List<CallDescriptor> checkSubscriberIdAuth(String subscriberId, AuthIdentity authIdentity) throws GatewayException {

    // Get subscriber matching CallDescriptors
    Auth auth;
    try {
      auth = dataManager.getAuthById(subscriberId);
    } catch (InvalidIDException e) {
      throw new GatewayException(GatewayExceptionCode.AUTHORIZATION, e.getMessage() );
    }

    if (auth == null || !auth.getStatus().isActive()) {
      throw new GatewayException(GatewayExceptionCode.AUTHORIZATION, "Authorization status is invalid");
    }

    return   dataManager.getMatchingPolicies(authIdentity.getApi(), auth);
View Full Code Here

          processTdrGenerationRuleDynamic(policy.getTdrGenerationRule(), exchange, properties, efType);
      }
    }

    // Finally add the values from the Auth
    Auth auth = identity.getAuth();
    if(auth != null)
      if(doStatic)
        processTdrGenerationRuleStatic(auth.getTdrGenerationRule(), exchange, properties);
      else
        processTdrGenerationRuleDynamic(auth.getTdrGenerationRule(), exchange, properties, efType);
  }
View Full Code Here

TOP

Related Classes of com.alu.e3.common.tools.CanonicalizedIpAddress

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.