com.cleverpine.viravaspringhelper.dto.Permission Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cp-virava-spring-helper Show documentation
Show all versions of cp-virava-spring-helper Show documentation
Library for Spring Framework projects using Virava
package com.cleverpine.viravaspringhelper.dto;
import com.cleverpine.viravaspringhelper.core.BaseResource;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
public class Permission {
private final BaseResource resource;
private final Set scopeTypes;
private final ScopeHolder scopeHolder;
private Permission(BaseResource resource, Set scopeTypes) {
this.resource = resource;
this.scopeTypes = Collections.unmodifiableSet(scopeTypes);
this.scopeHolder = new ScopeHolder(
scopeTypes.contains(ScopeType.CREATE),
scopeTypes.contains(ScopeType.READ),
scopeTypes.contains(ScopeType.UPDATE),
scopeTypes.contains(ScopeType.DELETE));
}
public static Permission of(PermissionInitializer permissionBuilder) {
return new Permission(permissionBuilder.getResource(), permissionBuilder.getScopeTypes());
}
public static Permission of(BaseResource resource, Scope... scopes) {
var scopeTypes = scopes == null ?
new HashSet() :
Arrays.stream(scopes).flatMap(scope -> scope.getScopeTypes().stream()).collect(Collectors.toSet());
return new Permission(resource, scopeTypes);
}
public BaseResource getResource() {
return resource;
}
public Set getScopeTypes() {
return Set.copyOf(scopeTypes);
}
public ScopeHolder getScopeHolder() {
return scopeHolder;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy