/** * Get unregistered required actions * * <p>Returns a list of unregistered required actions. */ @Path("unregistered-required-actions") @GET @Produces(MediaType.APPLICATION_JSON) @NoCache public List<Map<String, String>> getUnregisteredRequiredActions() { auth.requireView(); List<ProviderFactory> factories = session.getKeycloakSessionFactory().getProviderFactories(RequiredActionProvider.class); List<Map<String, String>> unregisteredList = new LinkedList<>(); for (ProviderFactory factory : factories) { RequiredActionFactory requiredActionFactory = (RequiredActionFactory) factory; boolean found = false; for (RequiredActionProviderModel model : realm.getRequiredActionProviders()) { if (model.getProviderId().equals(factory.getId())) { found = true; break; } } if (!found) { Map<String, String> data = new HashMap<>(); data.put("name", requiredActionFactory.getDisplayText()); data.put("providerId", requiredActionFactory.getId()); unregisteredList.add(data); } } return unregisteredList; }
/** * Update required action * * @param alias Alias of required action * @param rep JSON describing new state of required action */ @Path("required-actions/{alias}") @PUT @Consumes(MediaType.APPLICATION_JSON) public void updateRequiredAction( @PathParam("alias") String alias, RequiredActionProviderRepresentation rep) { auth.requireManage(); RequiredActionProviderModel model = realm.getRequiredActionProviderByAlias(alias); if (model == null) { throw new NotFoundException("Failed to find required action"); } RequiredActionProviderModel update = new RequiredActionProviderModel(); update.setId(model.getId()); update.setName(rep.getName()); update.setAlias(rep.getAlias()); update.setProviderId(model.getProviderId()); update.setDefaultAction(rep.isDefaultAction()); update.setEnabled(rep.isEnabled()); update.setConfig(rep.getConfig()); realm.updateRequiredActionProvider(update); adminEvent.operation(OperationType.UPDATE).resourcePath(uriInfo).representation(rep).success(); }