FileData implements IAuthDataAccess { @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; } FileData(String filePath); @Override AuthReport checkAllowed(Api api, String authKey); @Override AuthReport checkAllowed(Api api, String username, String password); @Override AuthReport checkAllowed(Api api, String username, String passwordDigest, boolean isPasswordText, String nonce, String created); @Override AuthReport checkAllowed(Api api, CanonicalizedIpAddress ipCanonicalized); @Override AuthReport checkAllowed(Api api); @Override AuthReport checkOAuthAllowed(Api api, String clientId, String clientSecret);  }
@Test public void test1() throws Exception { Api api = new Api(); api.setId("test"); fileData = new FileData("/notAValidFile.db"); assertNotNull(fileData); assertNull(fileData.checkAllowed(api, "test").getAuthIdentity()); }
@Test public void testIsAssociated() throws Exception { Api api = new Api(); api.setId("api1234"); URL fileURL = getClass().getResource(DB_PATH); 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()); }