001/*******************************************************************************
002 * Copyright 2017 The MIT Internet Trust Consortium
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *   http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *******************************************************************************/
016
017package org.mitre.uma.model;
018
019import java.util.Set;
020
021import javax.persistence.CollectionTable;
022import javax.persistence.Column;
023import javax.persistence.ElementCollection;
024import javax.persistence.Entity;
025import javax.persistence.FetchType;
026import javax.persistence.GeneratedValue;
027import javax.persistence.GenerationType;
028import javax.persistence.Id;
029import javax.persistence.JoinColumn;
030import javax.persistence.ManyToOne;
031import javax.persistence.Table;
032
033/**
034 * @author  jricher
035 */
036@Entity
037@Table(name = "permission")
038public class Permission {
039
040        private Long id;
041        private ResourceSet resourceSet;
042        private Set<String> scopes;
043
044        /**
045         * @return the id
046         */
047        @Id
048        @GeneratedValue(strategy = GenerationType.IDENTITY)
049        @Column(name = "id")
050        public Long getId() {
051                return id;
052        }
053
054        /**
055         * @param id the id to set
056         */
057        public void setId(Long id) {
058                this.id = id;
059        }
060
061        /**
062         * @return the resourceSet
063         */
064        @ManyToOne(fetch = FetchType.EAGER)
065        @JoinColumn(name = "resource_set_id")
066        public ResourceSet getResourceSet() {
067                return resourceSet;
068        }
069
070        /**
071         * @param resourceSet the resourceSet to set
072         */
073        public void setResourceSet(ResourceSet resourceSet) {
074                this.resourceSet = resourceSet;
075        }
076
077        /**
078         * @return the scopes
079         */
080        @ElementCollection(fetch = FetchType.EAGER)
081        @Column(name = "scope")
082        @CollectionTable(
083                        name = "permission_scope",
084                        joinColumns = @JoinColumn(name = "owner_id")
085                        )
086        public Set<String> getScopes() {
087                return scopes;
088        }
089
090        /**
091         * @param scopes the scopes to set
092         */
093        public void setScopes(Set<String> scopes) {
094                this.scopes = scopes;
095        }
096}