use of org.keycloak.representations.idm.authorization.AbstractPolicyRepresentation in project keycloak by keycloak.
the class Permissions method update.
public void update(String name, AbstractPolicyRepresentation representation, boolean save) {
for (WebElement row : permissions().rows()) {
PolicyRepresentation actual = permissions().toRepresentation(row);
if (actual.getName().equalsIgnoreCase(name)) {
clickLink(row.findElements(tagName("a")).get(0));
WaitUtils.waitForPageToLoad();
String type = representation.getType();
if ("resource".equals(type)) {
resourcePermission.form().populate((ResourcePermissionRepresentation) representation, save);
} else if ("scope".equals(type)) {
scopePermission.form().populate((ScopePermissionRepresentation) representation, save);
}
return;
}
}
}
use of org.keycloak.representations.idm.authorization.AbstractPolicyRepresentation in project keycloak by keycloak.
the class PolicyResourceService method update.
@PUT
@Consumes("application/json")
@Produces("application/json")
@NoCache
public Response update(String payload) {
if (auth != null) {
this.auth.realm().requireManageAuthorization();
}
AbstractPolicyRepresentation representation = doCreateRepresentation(payload);
if (policy == null) {
return Response.status(Status.NOT_FOUND).build();
}
representation.setId(policy.getId());
RepresentationToModel.toModel(representation, authorization, policy);
audit(representation, OperationType.UPDATE);
return Response.status(Status.CREATED).build();
}
use of org.keycloak.representations.idm.authorization.AbstractPolicyRepresentation in project keycloak by keycloak.
the class PolicyService method create.
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@NoCache
public Response create(String payload, @Context KeycloakSession session) {
if (auth != null) {
this.auth.realm().requireManageAuthorization();
}
AbstractPolicyRepresentation representation = doCreateRepresentation(payload);
Policy policy = create(representation);
representation.setId(policy.getId());
audit(representation, representation.getId(), OperationType.CREATE, session);
return Response.status(Status.CREATED).entity(representation).build();
}
use of org.keycloak.representations.idm.authorization.AbstractPolicyRepresentation in project keycloak by keycloak.
the class PolicyTypeService method doCreateRepresentation.
@Override
protected AbstractPolicyRepresentation doCreateRepresentation(String payload) {
PolicyProviderFactory provider = getPolicyProviderFactory(type);
Class<? extends AbstractPolicyRepresentation> representationType = provider.getRepresentationType();
if (representationType == null) {
throw new RuntimeException("Policy provider for type [" + type + "] returned a null representation type.");
}
AbstractPolicyRepresentation representation;
try {
representation = JsonSerialization.readValue(payload, representationType);
} catch (IOException e) {
throw new RuntimeException("Failed to deserialize JSON using policy provider for type [" + type + "].", e);
}
representation.setType(type);
return representation;
}
use of org.keycloak.representations.idm.authorization.AbstractPolicyRepresentation in project keycloak by keycloak.
the class RepresentationToModel method toModel.
public static Policy toModel(AbstractPolicyRepresentation representation, AuthorizationProvider authorization, Policy model) {
model.setName(representation.getName());
model.setDescription(representation.getDescription());
model.setDecisionStrategy(representation.getDecisionStrategy());
model.setLogic(representation.getLogic());
Set resources = representation.getResources();
Set scopes = representation.getScopes();
Set policies = representation.getPolicies();
if (representation instanceof PolicyRepresentation) {
PolicyRepresentation policy = PolicyRepresentation.class.cast(representation);
if (resources == null) {
String resourcesConfig = policy.getConfig().get("resources");
if (resourcesConfig != null) {
try {
resources = JsonSerialization.readValue(resourcesConfig, Set.class);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
if (scopes == null) {
String scopesConfig = policy.getConfig().get("scopes");
if (scopesConfig != null) {
try {
scopes = JsonSerialization.readValue(scopesConfig, Set.class);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
if (policies == null) {
String policiesConfig = policy.getConfig().get("applyPolicies");
if (policiesConfig != null) {
try {
policies = JsonSerialization.readValue(policiesConfig, Set.class);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
model.setConfig(policy.getConfig());
}
StoreFactory storeFactory = authorization.getStoreFactory();
updateResources(resources, model, storeFactory);
updateScopes(scopes, model, storeFactory);
updateAssociatedPolicies(policies, model, storeFactory);
PolicyProviderFactory provider = authorization.getProviderFactory(model.getType());
if (representation instanceof PolicyRepresentation) {
provider.onImport(model, PolicyRepresentation.class.cast(representation), authorization);
} else if (representation.getId() == null) {
provider.onCreate(model, representation, authorization);
} else {
provider.onUpdate(model, representation, authorization);
}
representation.setId(model.getId());
return model;
}
Aggregations