use of org.openremote.model.rules.TenantRuleset in project openremote by openremote.
the class RulesetResourceImpl method deleteTenantRuleset.
@Override
public void deleteTenantRuleset(@BeanParam RequestParams requestParams, Long id) {
TenantRuleset ruleset = rulesetStorageService.findById(TenantRuleset.class, id);
if (ruleset == null) {
return;
}
Tenant tenant = identityService.getIdentityProvider().getTenantForRealmId(ruleset.getRealmId());
if (tenant == null) {
throw new WebApplicationException(BAD_REQUEST);
}
if (!isTenantActiveAndAccessible(tenant) || isRestrictedUser()) {
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
rulesetStorageService.delete(TenantRuleset.class, id);
}
use of org.openremote.model.rules.TenantRuleset in project openremote by openremote.
the class RulesetResourceImpl method getTenantRuleset.
@Override
public TenantRuleset getTenantRuleset(@BeanParam RequestParams requestParams, Long id) {
TenantRuleset ruleset = rulesetStorageService.findById(TenantRuleset.class, id);
if (ruleset == null) {
throw new WebApplicationException(NOT_FOUND);
}
Tenant tenant = identityService.getIdentityProvider().getTenantForRealmId(ruleset.getRealmId());
if (tenant == null) {
throw new WebApplicationException(BAD_REQUEST);
}
if (!isTenantActiveAndAccessible(tenant) || isRestrictedUser()) {
LOG.fine("Forbidden access for user '" + getUsername() + "': " + tenant);
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
return ruleset;
}
use of org.openremote.model.rules.TenantRuleset in project openremote by openremote.
the class RulesetResourceImpl method updateTenantRuleset.
@Override
public void updateTenantRuleset(@BeanParam RequestParams requestParams, Long id, TenantRuleset ruleset) {
TenantRuleset existingRuleset = rulesetStorageService.findById(TenantRuleset.class, id);
if (existingRuleset == null) {
throw new WebApplicationException(NOT_FOUND);
}
Tenant tenant = identityService.getIdentityProvider().getTenantForRealmId(existingRuleset.getRealmId());
if (tenant == null) {
throw new WebApplicationException(BAD_REQUEST);
}
if (!isTenantActiveAndAccessible(tenant) || isRestrictedUser()) {
LOG.fine("Forbidden access for user '" + getUsername() + "': " + tenant);
throw new WebApplicationException(Response.Status.FORBIDDEN);
}
if (!id.equals(ruleset.getId())) {
throw new WebApplicationException("Requested ID and ruleset ID don't match", BAD_REQUEST);
}
if (!existingRuleset.getRealmId().equals(ruleset.getRealmId())) {
throw new WebApplicationException("Requested realm and existing ruleset realm must match", BAD_REQUEST);
}
rulesetStorageService.merge(ruleset);
}
Aggregations