HttpRequestHandler { public void checkAccess(String pHost, String pAddress, String pOrigin) { if (!backendManager.isRemoteAccessAllowed(pHost, pAddress)) { throw new SecurityException("No access from client " + pAddress + " allowed"); } if (!backendManager.isOriginAllowed(pOrigin,true)) { throw new SecurityException("Origin " + pOrigin + " is not allowed to call this agent"); } } HttpRequestHandler(Configuration pConfig, BackendManager pBackendManager, LogHandler pLogHandler); JSONAware handleGetRequest(String pUri, String pPathInfo, Map<String, String[]> pParameterMap); JSONAware handlePostRequest(String pUri, InputStream pInputStream, String pEncoding, Map<String, String[]>  pParameterMap); Map<String, String> handleCorsPreflightRequest(String pOrigin, String pRequestHeaders); JSONObject handleThrowable(Throwable pThrowable); JSONObject getErrorJSON(int pErrorCode, Throwable pExp, JmxRequest pJmxReq); void checkAccess(String pHost, String pAddress, String pOrigin); String extractCorsOrigin(String pOrigin);  }
@Test public void accessAllowed() { expect(backend.isRemoteAccessAllowed("localhost","127.0.0.1")).andReturn(true); expect(backend.isOriginAllowed((String) isNull(), eq(true))).andReturn(true); replay(backend); handler.checkAccess("localhost", "127.0.0.1",null); }
@Test(expectedExceptions = { SecurityException.class }) public void accessDenied() { expect(backend.isRemoteAccessAllowed("localhost","127.0.0.1")).andReturn(false); replay(backend); handler.checkAccess("localhost", "127.0.0.1",null); }
@Test(expectedExceptions = { SecurityException.class }) public void accessDeniedViaOrigin() { expect(backend.isRemoteAccessAllowed("localhost","127.0.0.1")).andReturn(true); expect(backend.isOriginAllowed("www.jolokia.org",true)).andReturn(false); replay(backend); handler.checkAccess("localhost", "127.0.0.1","www.jolokia.org"); }