Package com.alu.e3.common.camel

Examples of com.alu.e3.common.camel.AuthReport


  }

  @Override
  public AuthReport checkOAuthAllowed(Api api, String clientId, String clientSecret) {
   
    AuthReport authReport = new AuthReport();
    if(logger.isDebugEnabled()) {
      logger.debug("Lookup if clientId:clientSecret: " + clientId+":"+clientSecret + " is associated with appId:" + api.getId());
    }
   
    String appId = findString(api.getId(), clientId+":"+clientSecret);
   
    if(appId != null) {
     
      AuthIdentityHelper authIdentityHelper = new AuthIdentityHelper();
     
      authIdentityHelper.setApi(api.getId());
      authIdentityHelper.setAppId(appId);
      authIdentityHelper.setOAuth(clientId, clientSecret);
     
      authReport.setAuthIdentity( authIdentityHelper.getAuthIdentity());
      authReport.setApiActive(true);
     
    } else {
      authReport.setNotAuthorized(true);
    }
   
    return authReport;
  }
View Full Code Here


  }
 
  @Override
  public AuthReport checkAllowed(Exchange exchange, Api api) {
   
    AuthReport authReport = new AuthReport();
   
    String authHeader = (String) exchange.getIn().getHeader("Authorization");
   
    if(authHeader != null){
      String[] chunks = authHeader.split(" ");
     
      // Only expect two parts: the auth scheme and the user/pass encoding
      if(chunks.length == 2){
        String scheme = chunks[0];
        if("Basic".equalsIgnoreCase(scheme)){
          String base64 = chunks[1];
          String decoded = new String(Base64.decodeBase64(base64.getBytes()));
          chunks = decoded.split(":");
          if(chunks.length >= 2){
            String user = chunks[0];
            String pass = chunks[1];
            // Checks if the user is allowed to use this service
            authReport = dataAccess.checkAllowed(api, user, pass);
          }
          else{
            if(logger.isDebugEnabled()) {
              logger.debug("Unable to decode user/pass");
            }
            authReport.setBadRequest(true);
          }
        }
        else{
          if(logger.isDebugEnabled()) {
            logger.debug("Auth scheme not Basic ("+scheme+"). Cannot authenticate request");
          }
          authReport.setBadRequest(true);
        }
      }
      else{
        if(logger.isDebugEnabled()) {
          logger.debug("Improperly formed authorization header:"+authHeader);
        }
        authReport.setBadRequest(true);
      }
    }
    else{
      if(logger.isDebugEnabled()) {
        logger.debug("Http Basic Authentication Header is missing");
      }
      authReport.setBadRequest(true);
    }
   
    return authReport;
  }
View Full Code Here

  }

  @Override
  public AuthReport checkAllowed(Exchange exchange, Api api) {
   
    AuthReport authReport = new AuthReport();
    
    if(logger.isDebugEnabled()) {
      logger.debug("Hit the IpWhitelistExecutor.isAllowed");
    }
   
    // magic Jetty stuff
    HttpServletRequest request = (HttpServletRequest) exchange.getIn().getHeader(Exchange.HTTP_SERVLET_REQUEST);
   
    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);
    }
     
    return authReport;
  }
View Full Code Here

  }
 
  @Override
  public AuthReport checkAllowed(Exchange exchange, Api api) {
   
    AuthReport authReport = new AuthReport();
    Object keyObj = null;
   
    Map<?, ?> parameters = exchange.getProperty(ExchangeConstantKeys.E3_REQUEST_PARAMETERS.toString(), Map.class);
    if (parameters == null) {
      if(logger.isDebugEnabled()) {
        logger.debug("Request parameters not set");
      }
      authReport.setBadRequest(true);
    } else {
   
      keyObj = parameters.get(keyName);
      if (keyObj == null) { // No parameter by keyName, checking for a header "headerName"
        keyObj = exchange.getIn().getHeader(headerName, String.class);
        if (keyObj == null) {   
          // Abort
          if(logger.isDebugEnabled()) {
            logger.debug("Unable to find url parameter or header matching the provisioned api key name");
          }
          authReport.setBadRequest(true);
        }
      }
    }
   
    // if not a bad request
    if(!authReport.isBadRequest()) {
   
      String authKey = keyObj.toString();
      if(logger.isDebugEnabled()) {
        logger.debug("authKey= " + authKey);
      }
View Full Code Here

    // Setting the key in the query - should be removed
    exchange.getIn().setHeader(Exchange.HTTP_QUERY, appKeyName + "=asdf");
   
    AppKeyExecutor executor = new AppKeyExecutor(appKeyName, appHeaderName, new MockAuthDataAccess("asdf", null, null));
   
    AuthReport authReport = executor.checkAllowed(exchange, api);
   
    assertNotNull("This authentication should have succeeded", authReport.getAuthIdentity());

    // Check the query parameter
    assertNull("The query parameter should have been removed", exchange.getIn().getHeader(Exchange.HTTP_QUERY));
  }
View Full Code Here

    // Setting the key in the header - should be removed
    exchange.getIn().setHeader(appHeaderName, "asdf");
   
    AppKeyExecutor executor = new AppKeyExecutor(appKeyName, appHeaderName, new MockAuthDataAccess("asdf", null, null));
   
    AuthReport authReport = executor.checkAllowed(exchange, api);
   
    assertNotNull("This authentication should have succeeded", authReport.getAuthIdentity());

    // Check the query parameter
    assertNull("The header should have been removed", exchange.getIn().getHeader(appHeaderName));
  }
View Full Code Here

    parameters.put(appKeyName, "asdf");
    exchange.setProperty(ExchangeConstantKeys.E3_REQUEST_PARAMETERS.toString(), parameters);
   
    AppKeyExecutor executor = new AppKeyExecutor(appKeyName, appHeaderName, new MockAuthDataAccess(null, null, null));

    AuthReport authReport = executor.checkAllowed(exchange, api);
   
    assertNull("This authentication should have failed", authReport.getAuthIdentity());
  }
View Full Code Here

    api.setId("1234");

    // no parameter should fail
    AppKeyExecutor executor = new AppKeyExecutor(appKeyName, appHeaderName, new MockAuthDataAccess("asdf", null, null));
   
    AuthReport authReport = executor.checkAllowed(exchange, api);
   
    assertNull("This authentication should have failed", authReport.getAuthIdentity());
  }
View Full Code Here

   
    Policy policy = new Policy();
    mockDataManager.getCallDescriptors().add(new CallDescriptor(policy, 1, 2));
   
   
    AuthReport authReport = dataAccess.checkAllowed(api);
    AuthIdentity authIdentity = authReport.getAuthIdentity();
    assertNotNull(authIdentity);
   
    assertNotNull(authIdentity.getApi() == api); // compare memory reference
    assertNull(authIdentity.getAuth());
    assertNotNull(authIdentity.getCallDescriptors().get(0).getPolicy() == policy); // compare memory reference
View Full Code Here

    parameters.put(appKeyName.toUpperCase(), "asdf");
    exchange.setProperty(ExchangeConstantKeys.E3_REQUEST_PARAMETERS.toString(), parameters);

    AppKeyExecutor executor = new AppKeyExecutor(appKeyName, appHeaderName, new MockAuthDataAccess("asdf", null, null));
   
    AuthReport authReport = executor.checkAllowed(exchange, api);
   
    assertNull("This authentication should have failed",  authReport.getAuthIdentity());
  }
View Full Code Here

TOP

Related Classes of com.alu.e3.common.camel.AuthReport

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.