GetWSCapabilitiesHandler extends ActionHandler { public void handleAction(ActionParameters params) throws ActionException { if (!params.getUser().hasAnyRoleIn(permittedRoles)) { throw new ActionDeniedException("Unauthorized user tried to proxy via capabilities"); } final String url = params.getRequiredParam(PARM_URL).trim(); final String type = params.getHttpParam(PARM_TYPE, OskariLayer.TYPE_WMS); final String version = params.getHttpParam(PARM_VERSION, ""); final String user = params.getHttpParam(PARM_USER, ""); final String pw = params.getHttpParam(PARM_PW, ""); final String currentCrs = params.getHttpParam(PARM_CRS, "EPSG:3067"); log.debug("Trying to get capabilities for type:", type, "with url:", url); JSONObject capabilities = getCapabilities(url, type, version, user, pw, currentCrs); ResponseHelper.writeResponse(params, capabilities); } GetWSCapabilitiesHandler();  GetWSCapabilitiesHandler(CapabilitiesCacheService capabilitiesService); @Override void init(); void handleAction(ActionParameters params); static JSONObject getWFS3Capabilities(String url, String user, String pw, String currentCrs);  }
@Test(expected = ActionDeniedException.class) public void testHandleActionGuestUser() throws Exception { Map<String, String> parameters = new HashMap<String, String>(); parameters.put("url", "dummyurl"); final ActionParameters params = createActionParams(parameters); handler.handleAction(params); fail("Should not get his far with guest user"); }
@Test(expected = ActionDeniedException.class) public void testHandleActionInvalidUser() throws Exception { Map<String, String> parameters = new HashMap<String, String>(); parameters.put("url", "dummyurl"); final User user = new User(); user.addRole(1, "test role"); final ActionParameters params = createActionParams(parameters); handler.handleAction(params); fail("Should not get his far with user without configured roles"); }