@GET @Path("/intruder") @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8") public Response doGetAppIntruderData(@QueryParam("maximum") int maximum) throws ChaiUnavailableException, PwmUnrecoverableException { maximum = maximum > 0 ? maximum : 10 * 1000; final RestRequestBean restRequestBean; try { final ServicePermissions servicePermissions = new ServicePermissions(); servicePermissions.setAdminOnly(true); servicePermissions.setAuthRequired(true); servicePermissions.setBlockExternal(true); restRequestBean = RestServerHelper.initializeRestRequest(request, response, servicePermissions, null); } catch (PwmUnrecoverableException e) { return RestResultBean.fromError(e.getErrorInformation()).asJsonResponse(); } if (!restRequestBean .getPwmSession() .getSessionManager() .checkPermission(restRequestBean.getPwmApplication(), Permission.PWMADMIN)) { final ErrorInformation errorInfo = PwmError.ERROR_UNAUTHORIZED.toInfo(); return RestResultBean.fromError(errorInfo, restRequestBean).asJsonResponse(); } final TreeMap<String, Object> returnData = new TreeMap<>(); try { for (final RecordType recordType : RecordType.values()) { returnData.put( recordType.toString(), restRequestBean .getPwmApplication() .getIntruderManager() .getRecords(recordType, maximum)); } } catch (PwmOperationalException e) { final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_UNKNOWN, e.getMessage()); return RestResultBean.fromError(errorInfo, restRequestBean).asJsonResponse(); } final RestResultBean restResultBean = new RestResultBean(); restResultBean.setData(returnData); return restResultBean.asJsonResponse(); }
@GET @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8") @Path("/client") public Response doGetAppClientData( @QueryParam("pageUrl") String pageUrl, @PathParam(value = "eTagUri") final String eTagUri, @Context HttpServletRequest request, @Context HttpServletResponse response) throws PwmUnrecoverableException, IOException, ChaiUnavailableException { final int maxCacheAgeSeconds = 60 * 5; final RestRequestBean restRequestBean; try { restRequestBean = RestServerHelper.initializeRestRequest( request, response, ServicePermissions.PUBLIC, null); } catch (PwmUnrecoverableException e) { return RestResultBean.fromError(e.getErrorInformation()).asJsonResponse(); } final String eTagValue = makeClientEtag( restRequestBean.getPwmApplication(), restRequestBean.getPwmSession(), request); // check the incoming header; final String ifNoneMatchValue = request.getHeader("If-None-Match"); if (ifNoneMatchValue != null && ifNoneMatchValue.equals(eTagValue) && eTagValue.equals(eTagUri)) { return Response.notModified().build(); } response.setHeader("ETag", eTagValue); response.setDateHeader("Expires", System.currentTimeMillis() + (maxCacheAgeSeconds * 1000)); response.setHeader("Cache-Control", "public, max-age=" + maxCacheAgeSeconds); final AppData appData = makeAppData( restRequestBean.getPwmApplication(), restRequestBean.getPwmSession(), request, response, pageUrl); final RestResultBean restResultBean = new RestResultBean(); restResultBean.setData(appData); return restResultBean.asJsonResponse(); }
@GET @Path("/audit") @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8") public Response doGetAppAuditData(@QueryParam("maximum") int maximum) throws ChaiUnavailableException, PwmUnrecoverableException { maximum = maximum > 0 ? maximum : 10 * 1000; final RestRequestBean restRequestBean; try { final ServicePermissions servicePermissions = new ServicePermissions(); servicePermissions.setAdminOnly(true); servicePermissions.setAuthRequired(true); servicePermissions.setBlockExternal(true); restRequestBean = RestServerHelper.initializeRestRequest(request, response, servicePermissions, null); } catch (PwmUnrecoverableException e) { return RestResultBean.fromError(e.getErrorInformation()).asJsonResponse(); } final ArrayList<UserAuditRecord> userRecords = new ArrayList<>(); final ArrayList<HelpdeskAuditRecord> helpdeskRecords = new ArrayList<>(); final ArrayList<SystemAuditRecord> systemRecords = new ArrayList<>(); final Iterator<AuditRecord> iterator = restRequestBean.getPwmApplication().getAuditManager().readVault(); int counter = 0; while (iterator.hasNext() && counter <= maximum) { final AuditRecord loopRecord = iterator.next(); counter++; if (loopRecord instanceof SystemAuditRecord) { systemRecords.add((SystemAuditRecord) loopRecord); } else if (loopRecord instanceof HelpdeskAuditRecord) { helpdeskRecords.add((HelpdeskAuditRecord) loopRecord); } else if (loopRecord instanceof UserAuditRecord) { userRecords.add((UserAuditRecord) loopRecord); } } final HashMap<String, List> outputMap = new HashMap<>(); outputMap.put("user", userRecords); outputMap.put("helpdesk", helpdeskRecords); outputMap.put("system", systemRecords); final RestResultBean restResultBean = new RestResultBean(); restResultBean.setData(outputMap); LOGGER.debug(restRequestBean.getPwmSession(), "output " + counter + " audit records."); return restResultBean.asJsonResponse(); }
@GET @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8") @Path("/strings/{bundle}") public Response doGetStringData(@PathParam(value = "bundle") final String bundleName) throws PwmUnrecoverableException, IOException, ChaiUnavailableException { final int maxCacheAgeSeconds = 60 * 5; final RestRequestBean restRequestBean; try { restRequestBean = RestServerHelper.initializeRestRequest( request, response, ServicePermissions.PUBLIC, null); } catch (PwmUnrecoverableException e) { return RestResultBean.fromError(e.getErrorInformation()).asJsonResponse(); } final String eTagValue = makeClientEtag( restRequestBean.getPwmApplication(), restRequestBean.getPwmSession(), request); response.setHeader("ETag", eTagValue); response.setDateHeader("Expires", System.currentTimeMillis() + (maxCacheAgeSeconds * 1000)); response.setHeader("Cache-Control", "public, max-age=" + maxCacheAgeSeconds); try { final LinkedHashMap<String, String> displayData = new LinkedHashMap<>( makeDisplayData( restRequestBean.getPwmApplication(), restRequestBean.getPwmSession(), bundleName)); final RestResultBean restResultBean = new RestResultBean(); restResultBean.setData(displayData); return restResultBean.asJsonResponse(); } catch (Exception e) { final String errorMSg = "error during rest /strings call for bundle " + bundleName + ", error: " + e.getMessage(); final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMSg); return RestResultBean.fromError(errorInformation).asJsonResponse(); } }
@GET @Path("/session") @Produces(MediaType.APPLICATION_JSON + ";charset=UTF-8") public Response doGetAppSessionData(@QueryParam("maximum") int maximum) throws ChaiUnavailableException, PwmUnrecoverableException { maximum = maximum > 0 ? maximum : 10 * 1000; final RestRequestBean restRequestBean; try { final ServicePermissions servicePermissions = new ServicePermissions(); servicePermissions.setAdminOnly(true); servicePermissions.setAuthRequired(true); servicePermissions.setBlockExternal(true); restRequestBean = RestServerHelper.initializeRestRequest(request, response, servicePermissions, null); } catch (PwmUnrecoverableException e) { return RestResultBean.fromError(e.getErrorInformation()).asJsonResponse(); } if (!restRequestBean .getPwmSession() .getSessionManager() .checkPermission(restRequestBean.getPwmApplication(), Permission.PWMADMIN)) { final ErrorInformation errorInfo = PwmError.ERROR_UNAUTHORIZED.toInfo(); return RestResultBean.fromError(errorInfo, restRequestBean).asJsonResponse(); } final ArrayList<SessionStateInfoBean> gridData = new ArrayList<>(); int counter = 0; final Iterator<SessionStateInfoBean> infos = restRequestBean.getPwmApplication().getSessionTrackService().getSessionInfoIterator(); while (counter < maximum && infos.hasNext()) { gridData.add(infos.next()); counter++; } final RestResultBean restResultBean = new RestResultBean(); restResultBean.setData(gridData); return restResultBean.asJsonResponse(); }