/* * Copyright 2012 Nodeable Inc * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.streamreduce.core.model; import com.google.code.morphia.annotations.Entity; import com.google.code.morphia.annotations.Indexed; import java.util.Arrays; import java.util.HashSet; import java.util.Set; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import org.hibernate.validator.constraints.NotEmpty; /** * Model object that represents a security role. */ @Entity(value = "roles", noClassnameStored = true) public class Role extends ObjectWithId { private static final long serialVersionUID = -1187250966502639721L; @Indexed(unique = true) @NotEmpty private String name; @Size(max = 256) private String description; @NotNull private Set<String> permissions = new HashSet<>(); protected Role() { } public Role(String name) { this.name = name; } public Role(String name, String description) { this.name = name; this.description = description; } public Role(String name, String description, Set<String> permissions) { this.name = name; this.description = description; this.permissions = permissions; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Set<String> getPermissions() { return permissions; } public void setPermissions(Set<String> permissions) { this.permissions = permissions; } public void addPermissions(String... permission) { Set<String> set = new HashSet<>(); set.addAll(Arrays.asList(permission)); this.permissions = set; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Role role = (Role) o; if (name != null ? !name.equals(role.name) : role.name != null) return false; return true; } @Override public int hashCode() { return name != null ? name.hashCode() : 0; } }