/** * 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; }
public static RequiredActionProviderRepresentation toRepresentation( RequiredActionProviderModel model) { RequiredActionProviderRepresentation rep = new RequiredActionProviderRepresentation(); rep.setAlias(model.getAlias()); rep.setName(model.getName()); rep.setDefaultAction(model.isDefaultAction()); rep.setEnabled(model.isEnabled()); rep.setConfig(model.getConfig()); return rep; }
/** * Register a new required actions * * @param data JSON containing 'providerId', and 'name' attributes. */ @Path("register-required-action") @POST @Consumes(MediaType.APPLICATION_JSON) @NoCache public void registerRequiredAction(Map<String, String> data) { auth.requireManage(); String providerId = data.get("providerId"); String name = data.get("name"); RequiredActionProviderModel requiredAction = new RequiredActionProviderModel(); requiredAction.setAlias(providerId); requiredAction.setName(name); requiredAction.setProviderId(providerId); requiredAction.setDefaultAction(false); requiredAction.setEnabled(true); requiredAction = realm.addRequiredActionProvider(requiredAction); data.put("id", requiredAction.getId()); adminEvent.operation(OperationType.CREATE).resourcePath(uriInfo).representation(data).success(); }
/** * 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(); }