Search in sources :

Example 1 with TenantRuleset

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);
}
Also used : Tenant(org.openremote.model.security.Tenant) WebApplicationException(javax.ws.rs.WebApplicationException) TenantRuleset(org.openremote.model.rules.TenantRuleset)

Example 2 with TenantRuleset

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;
}
Also used : Tenant(org.openremote.model.security.Tenant) WebApplicationException(javax.ws.rs.WebApplicationException) TenantRuleset(org.openremote.model.rules.TenantRuleset)

Example 3 with TenantRuleset

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);
}
Also used : Tenant(org.openremote.model.security.Tenant) WebApplicationException(javax.ws.rs.WebApplicationException) TenantRuleset(org.openremote.model.rules.TenantRuleset)

Aggregations

WebApplicationException (javax.ws.rs.WebApplicationException)3 TenantRuleset (org.openremote.model.rules.TenantRuleset)3 Tenant (org.openremote.model.security.Tenant)3