class HttpBasicExecutor implements IAuthExecutor {

	@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;
	}

	public  HttpBasicExecutor(IAuthDataAccess dataAcccess);

}