Package com.alu.e3.common.camel

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


public class MockAppKeyExecutor implements IAuthExecutor {

  @Override
  public AuthReport checkAllowed(Exchange exchange, Api api) {
   
    AuthReport authReport = new AuthReport();
   
    if(exchange.getIn().getHeaders().size() > 0) {
      AuthIdentity authIdentity = new AuthIdentity();
      authIdentity.setAppId("1234");
      authReport.setAuthIdentity(authIdentity);
      authReport.setApiActive(true);
      authReport.setAuthActive(true);
    } else {
      authReport.setBadRequest(true);
    }
   
    //return exchange.getIn().getHeaders().size() > 0 ? new AuthIdentity("1234") : null;
   
    return authReport;
View Full Code Here


    // This one should be denied because the MockData is rigged to return null
    exchange.getIn().setHeader(AuthHttpHeaders.Authorization.toString(), "Basic "+new String(Base64.encodeBase64("win:blarg".getBytes())));
    HttpBasicExecutor executor = new HttpBasicExecutor(new MockAuthDataAccess(null, null, null));
   
    AuthReport authReport = executor.checkAllowed(exchange, api);
   
    assertNull("This authentication should have failed", authReport.getAuthIdentity());
  }
View Full Code Here

public class MockHttpBasicExecutor implements IAuthExecutor {

  @Override
  public AuthReport checkAllowed(Exchange exchange, Api api) {
   
    AuthReport authReport = new AuthReport();
   
    if(exchange.getIn().getHeader(AuthHttpHeaders.Authorization.toString()) != null) {
      AuthIdentity authIdentity = new AuthIdentity();
      authIdentity.setAppId("1234");
      authReport.setAuthIdentity(authIdentity);
      authReport.setApiActive(true);
      authReport.setAuthActive(true);
    }
   
    //return exchange.getIn().getHeader(AuthHeaders.AuthHttpHeaders.key)==null?null:new AppIdentity("1234");
   
    return authReport;   
View Full Code Here

  }
 
  @Override
  public AuthReport checkAllowed(Api api) {
   
    AuthReport authReport = new AuthReport();
   
    if(api != null) {   

      // check if the API is active (status)
      authReport.setApiActive((api.getStatus().isActive()));
      // For noAuth, Auth is always active
      authReport.setAuthActive(true);
     
      if(authReport.isApiActive()) {

        List<CallDescriptor> descriptors = this.dataManager.getMatchingPolicies(api);
       
        if(descriptors != null) {
          authReport.setAuthIdentity(new AuthIdentity());
          authReport.getAuthIdentity().setApi(api);
          authReport.getAuthIdentity().getCallDescriptors().addAll(descriptors);         
        } else {
          if(logger.isDebugEnabled()) {
            logger.debug("NoAuth method is not enabled");
          }
          authReport.setNotAuthorized(true);
        }
      }
     
    } else {
      if(logger.isDebugEnabled()) {
        logger.debug("No api found " + api.getId());
      }
      authReport.setApiNotFound(true);
    }
   
   
    return authReport;
 
View Full Code Here

   * @param auth
   * @return authReport instance
   */
  private AuthReport getAuthReport(Api api, Auth auth) {
 
    AuthReport authReport = new AuthReport();
   
    if(api != null) {

      // check if the API is active (status)
      authReport.setApiActive(api.getStatus().isActive());
     
      if(authReport.isApiActive()) {
       
        List<CallDescriptor> descriptors = null;
         
        if(auth != null) {
                 
          authReport.setAuthActive(auth.getStatus().isActive());
         
          // with auth         
          descriptors = this.dataManager.getMatchingPolicies(api, auth);
         
          if (descriptors != null) {
         
            // check if a policy exists
            boolean foundPolicy = false;
            for (CallDescriptor callDescriptor : descriptors) {
              if (callDescriptor.getPolicy() != null) {
                foundPolicy = true;
                break;
              }
            }
           
            if (foundPolicy) {
              authReport.setAuthIdentity(new AuthIdentity());
              authReport.getAuthIdentity().setApi(api);
              authReport.getAuthIdentity().setAuth(auth);
              authReport.getAuthIdentity().getCallDescriptors().addAll(descriptors);
            } else {
              if(logger.isDebugEnabled()) {
                logger.debug("No policy found");
              }
              authReport.setHasNoPolicy(true);
            }
           
          } else {
            if(logger.isDebugEnabled()) {
              logger.debug("Auth does not match with API");
            }
            authReport.setNotAuthorized(true);
          }
        } else {
          if(logger.isDebugEnabled()) {
            logger.debug("No auth found for API");
          }
          authReport.setAuthNotFound(true);
        }
       
      }
           
    } else {
      if(logger.isDebugEnabled()) {
        logger.debug("No api found " + api.getId());
      }
      authReport.setApiNotFound(true);
    }
   
    return authReport;   
  }
View Full Code Here

   * check if an auth key and an app id match.
   */
  @Override
  public AuthReport checkAllowed(Api api, String authKey) {

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

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

  }

  @Override
  public AuthReport checkAllowed(Api api, CanonicalizedIpAddress ipCanonicalized) {
   
    AuthReport authReport = new AuthReport();
   
    String ip = ipCanonicalized.getIp();
   
    String appId = findString(api.getId(), ip);
   
    if(appId != null) {
     
      AuthIdentityHelper authIdentityHelper = new AuthIdentityHelper();

      authIdentityHelper.setApi(api.getId());
      authIdentityHelper.setAppId(appId);
      authIdentityHelper.setAuth(ipCanonicalized);
     
      authReport.setAuthIdentity( authIdentityHelper.getAuthIdentity());
      authReport.setApiActive(true);
     
    } else {
      authReport.setNotAuthorized(true);
    }
   
    return authReport;
 
View Full Code Here

    AuthType authType = AuthType.NO_AUTH;
   
    boolean isAllowed = false;
    AuthIdentity authIdentity = null;
    AuthReport report = null;
    AuthType reportAuth = null;
   
    Iterator<IAuthExecutor> it = executors.iterator();
    while(!isAllowed && it.hasNext()) {
     
      IAuthExecutor executor = it.next();
      AuthReport authReport = executor.checkAllowed(exchange, api)
      isAllowed = authReport.isAllowed();
     
      if (isAllowed) {
        authIdentity = authReport.getAuthIdentity();
        report = authReport;
      } else {
        if (report == null) {
          report = authReport;
          reportAuth = executor.getType();
View Full Code Here

 

  @Override
  public AuthReport checkAllowed(Api api) {
   
    AuthReport authReport = new AuthReport();
    if(logger.isDebugEnabled()) {
      logger.debug("Lookup if noauth is true for appId:" + api.getId());
    }
   
    String appId = findString(api.getId(), "noauth:true");
   
    if(appId != null) {
     
      AuthIdentityHelper authIdentityHelper = new AuthIdentityHelper();

      authIdentityHelper.setApi(api.getId());
      authIdentityHelper.setAppId(appId);
     
      authReport.setAuthIdentity( authIdentityHelper.getAuthIdentity());
      authReport.setApiActive(true);
     
    } else {
      authReport.setNotAuthorized(true);
    }
   
    return authReport;
  }
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.