PermissionTicket.java

  1. /*******************************************************************************
  2.  * Copyright 2017 The MIT Internet Trust Consortium
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *   http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  *******************************************************************************/

  16. package org.mitre.uma.model;

  17. import java.util.Collection;
  18. import java.util.Date;

  19. import javax.persistence.Basic;
  20. import javax.persistence.CascadeType;
  21. import javax.persistence.Column;
  22. import javax.persistence.Entity;
  23. import javax.persistence.FetchType;
  24. import javax.persistence.GeneratedValue;
  25. import javax.persistence.GenerationType;
  26. import javax.persistence.Id;
  27. import javax.persistence.JoinColumn;
  28. import javax.persistence.JoinTable;
  29. import javax.persistence.NamedQueries;
  30. import javax.persistence.NamedQuery;
  31. import javax.persistence.OneToMany;
  32. import javax.persistence.OneToOne;
  33. import javax.persistence.Table;
  34. import javax.persistence.Temporal;
  35. import javax.persistence.TemporalType;

  36. /**
  37.  *
  38.  * An UMA permission, used in the protection API.
  39.  *
  40.  * @author jricher
  41.  *
  42.  */
  43. @Entity
  44. @Table(name = "permission_ticket")
  45. @NamedQueries({
  46.     @NamedQuery(name = PermissionTicket.QUERY_TICKET, query = "select p from PermissionTicket p where p.ticket = :" + PermissionTicket.PARAM_TICKET),
  47.     @NamedQuery(name = PermissionTicket.QUERY_ALL, query = "select p from PermissionTicket p"),
  48.     @NamedQuery(name = PermissionTicket.QUERY_BY_RESOURCE_SET, query = "select p from PermissionTicket p where p.permission.resourceSet.id = :" + PermissionTicket.PARAM_RESOURCE_SET_ID)
  49. })
  50. public class PermissionTicket {

  51.     public static final String QUERY_TICKET = "PermissionTicket.queryByTicket";
  52.     public static final String QUERY_ALL = "PermissionTicket.queryAll";
  53.     public static final String QUERY_BY_RESOURCE_SET = "PermissionTicket.queryByResourceSet";

  54.     public static final String PARAM_TICKET = "ticket";
  55.     public static final String PARAM_RESOURCE_SET_ID = "rsid";

  56.     private Long id;
  57.     private Permission permission;
  58.     private String ticket;
  59.     private Date expiration;
  60.     private Collection<Claim> claimsSupplied;

  61.     /**
  62.      * @return the id
  63.      */
  64.     @Id
  65.     @GeneratedValue(strategy = GenerationType.IDENTITY)
  66.     @Column(name = "id")
  67.     public Long getId() {
  68.         return id;
  69.     }

  70.     /**
  71.      * @param id the id to set
  72.      */
  73.     public void setId(Long id) {
  74.         this.id = id;
  75.     }

  76.     /**
  77.      * @return the permission
  78.      */
  79.     @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
  80.     @JoinColumn(name = "permission_id")
  81.     public Permission getPermission() {
  82.         return permission;
  83.     }

  84.     /**
  85.      * @param permission the permission to set
  86.      */
  87.     public void setPermission(Permission permission) {
  88.         this.permission = permission;
  89.     }

  90.     /**
  91.      * @return the ticket
  92.      */
  93.     @Basic
  94.     @Column(name = "ticket")
  95.     public String getTicket() {
  96.         return ticket;
  97.     }

  98.     /**
  99.      * @param ticket the ticket to set
  100.      */
  101.     public void setTicket(String ticket) {
  102.         this.ticket = ticket;
  103.     }

  104.     /**
  105.      * @return the expiration
  106.      */
  107.     @Basic
  108.     @Temporal(TemporalType.TIMESTAMP)
  109.     @Column(name = "expiration")
  110.     public Date getExpiration() {
  111.         return expiration;
  112.     }

  113.     /**
  114.      * @param expiration the expiration to set
  115.      */
  116.     public void setExpiration(Date expiration) {
  117.         this.expiration = expiration;
  118.     }

  119.     /**
  120.      * @return the claimsSupplied
  121.      */
  122.     @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
  123.     @JoinTable(
  124.             name = "claim_to_permission_ticket",
  125.             joinColumns = @JoinColumn(name = "permission_ticket_id"),
  126.             inverseJoinColumns = @JoinColumn(name = "claim_id")
  127.             )
  128.     public Collection<Claim> getClaimsSupplied() {
  129.         return claimsSupplied;
  130.     }

  131.     /**
  132.      * @param claimsSupplied the claimsSupplied to set
  133.      */
  134.     public void setClaimsSupplied(Collection<Claim> claimsSupplied) {
  135.         this.claimsSupplied = claimsSupplied;
  136.     }


  137. }