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.Collection;
020import java.util.Date;
021
022import javax.persistence.Basic;
023import javax.persistence.CascadeType;
024import javax.persistence.Column;
025import javax.persistence.Entity;
026import javax.persistence.FetchType;
027import javax.persistence.GeneratedValue;
028import javax.persistence.GenerationType;
029import javax.persistence.Id;
030import javax.persistence.JoinColumn;
031import javax.persistence.JoinTable;
032import javax.persistence.NamedQueries;
033import javax.persistence.NamedQuery;
034import javax.persistence.OneToMany;
035import javax.persistence.OneToOne;
036import javax.persistence.Table;
037import javax.persistence.Temporal;
038import javax.persistence.TemporalType;
039
040/**
041 *
042 * An UMA permission, used in the protection API.
043 *
044 * @author jricher
045 *
046 */
047@Entity
048@Table(name = "permission_ticket")
049@NamedQueries({
050        @NamedQuery(name = PermissionTicket.QUERY_TICKET, query = "select p from PermissionTicket p where p.ticket = :" + PermissionTicket.PARAM_TICKET),
051        @NamedQuery(name = PermissionTicket.QUERY_ALL, query = "select p from PermissionTicket p"),
052        @NamedQuery(name = PermissionTicket.QUERY_BY_RESOURCE_SET, query = "select p from PermissionTicket p where p.permission.resourceSet.id = :" + PermissionTicket.PARAM_RESOURCE_SET_ID)
053})
054public class PermissionTicket {
055
056        public static final String QUERY_TICKET = "PermissionTicket.queryByTicket";
057        public static final String QUERY_ALL = "PermissionTicket.queryAll";
058        public static final String QUERY_BY_RESOURCE_SET = "PermissionTicket.queryByResourceSet";
059
060        public static final String PARAM_TICKET = "ticket";
061        public static final String PARAM_RESOURCE_SET_ID = "rsid";
062
063        private Long id;
064        private Permission permission;
065        private String ticket;
066        private Date expiration;
067        private Collection<Claim> claimsSupplied;
068
069        /**
070         * @return the id
071         */
072        @Id
073        @GeneratedValue(strategy = GenerationType.IDENTITY)
074        @Column(name = "id")
075        public Long getId() {
076                return id;
077        }
078
079        /**
080         * @param id the id to set
081         */
082        public void setId(Long id) {
083                this.id = id;
084        }
085
086        /**
087         * @return the permission
088         */
089        @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
090        @JoinColumn(name = "permission_id")
091        public Permission getPermission() {
092                return permission;
093        }
094
095        /**
096         * @param permission the permission to set
097         */
098        public void setPermission(Permission permission) {
099                this.permission = permission;
100        }
101
102        /**
103         * @return the ticket
104         */
105        @Basic
106        @Column(name = "ticket")
107        public String getTicket() {
108                return ticket;
109        }
110
111        /**
112         * @param ticket the ticket to set
113         */
114        public void setTicket(String ticket) {
115                this.ticket = ticket;
116        }
117
118        /**
119         * @return the expiration
120         */
121        @Basic
122        @Temporal(TemporalType.TIMESTAMP)
123        @Column(name = "expiration")
124        public Date getExpiration() {
125                return expiration;
126        }
127
128        /**
129         * @param expiration the expiration to set
130         */
131        public void setExpiration(Date expiration) {
132                this.expiration = expiration;
133        }
134
135        /**
136         * @return the claimsSupplied
137         */
138        @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
139        @JoinTable(
140                        name = "claim_to_permission_ticket",
141                        joinColumns = @JoinColumn(name = "permission_ticket_id"),
142                        inverseJoinColumns = @JoinColumn(name = "claim_id")
143                        )
144        public Collection<Claim> getClaimsSupplied() {
145                return claimsSupplied;
146        }
147
148        /**
149         * @param claimsSupplied the claimsSupplied to set
150         */
151        public void setClaimsSupplied(Collection<Claim> claimsSupplied) {
152                this.claimsSupplied = claimsSupplied;
153        }
154
155
156}