WhitelistedSite.java

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

  19. import java.util.Set;

  20. import javax.persistence.Basic;
  21. import javax.persistence.CollectionTable;
  22. import javax.persistence.Column;
  23. import javax.persistence.ElementCollection;
  24. import javax.persistence.Entity;
  25. import javax.persistence.FetchType;
  26. import javax.persistence.GeneratedValue;
  27. import javax.persistence.GenerationType;
  28. import javax.persistence.Id;
  29. import javax.persistence.JoinColumn;
  30. import javax.persistence.NamedQueries;
  31. import javax.persistence.NamedQuery;
  32. import javax.persistence.Table;

  33. /**
  34.  * Indicator that login to a site should be automatically granted
  35.  * without user interaction.
  36.  * @author jricher, aanganes
  37.  *
  38.  */
  39. @Entity
  40. @Table(name="whitelisted_site")
  41. @NamedQueries({
  42.     @NamedQuery(name = WhitelistedSite.QUERY_ALL, query = "select w from WhitelistedSite w"),
  43.     @NamedQuery(name = WhitelistedSite.QUERY_BY_CLIENT_ID, query = "select w from WhitelistedSite w where w.clientId = :" + WhitelistedSite.PARAM_CLIENT_ID),
  44.     @NamedQuery(name = WhitelistedSite.QUERY_BY_CREATOR, query = "select w from WhitelistedSite w where w.creatorUserId = :" + WhitelistedSite.PARAM_USER_ID)
  45. })
  46. public class WhitelistedSite {

  47.     public static final String QUERY_BY_CREATOR = "WhitelistedSite.getByCreatoruserId";
  48.     public static final String QUERY_BY_CLIENT_ID = "WhitelistedSite.getByClientId";
  49.     public static final String QUERY_ALL = "WhitelistedSite.getAll";

  50.     public static final String PARAM_USER_ID = "userId";
  51.     public static final String PARAM_CLIENT_ID = "clientId";

  52.     // unique id
  53.     private Long id;

  54.     // Reference to the admin user who created this entry
  55.     private String creatorUserId;

  56.     // which OAuth2 client is this tied to
  57.     private String clientId;

  58.     // what scopes be allowed by default
  59.     // this should include all information for what data to access
  60.     private Set<String> allowedScopes;

  61.     /**
  62.      * Empty constructor
  63.      */
  64.     public WhitelistedSite() {

  65.     }

  66.     /**
  67.      * @return the id
  68.      */
  69.     @Id
  70.     @GeneratedValue(strategy = GenerationType.IDENTITY)
  71.     @Column(name = "id")
  72.     public Long getId() {
  73.         return id;
  74.     }

  75.     /**
  76.      * @param id the id to set
  77.      */
  78.     public void setId(Long id) {
  79.         this.id = id;
  80.     }

  81.     /**
  82.      * @return the clientId
  83.      */
  84.     @Basic
  85.     @Column(name="client_id")
  86.     public String getClientId() {
  87.         return clientId;
  88.     }

  89.     /**
  90.      * @param clientId the clientId to set
  91.      */
  92.     public void setClientId(String clientId) {
  93.         this.clientId = clientId;
  94.     }

  95.     /**
  96.      * @return the allowedScopes
  97.      */
  98.     @ElementCollection(fetch = FetchType.EAGER)
  99.     @CollectionTable(
  100.             name="whitelisted_site_scope",
  101.             joinColumns=@JoinColumn(name="owner_id")
  102.             )
  103.     @Column(name="scope")
  104.     public Set<String> getAllowedScopes() {
  105.         return allowedScopes;
  106.     }

  107.     /**
  108.      * @param allowedScopes the allowedScopes to set
  109.      */
  110.     public void setAllowedScopes(Set<String> allowedScopes) {
  111.         this.allowedScopes = allowedScopes;
  112.     }

  113.     @Basic
  114.     @Column(name="creator_user_id")
  115.     public String getCreatorUserId() {
  116.         return creatorUserId;
  117.     }

  118.     public void setCreatorUserId(String creatorUserId) {
  119.         this.creatorUserId = creatorUserId;
  120.     }
  121. }