001/*******************************************************************************
002 * Copyright 2018 The MIT Internet Trust Consortium
003 *
004 * Portions copyright 2011-2013 The MITRE Corporation
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 *******************************************************************************/
018package org.mitre.openid.connect.model;
019
020import java.util.Set;
021
022import javax.persistence.Basic;
023import javax.persistence.CollectionTable;
024import javax.persistence.Column;
025import javax.persistence.ElementCollection;
026import javax.persistence.Entity;
027import javax.persistence.FetchType;
028import javax.persistence.GeneratedValue;
029import javax.persistence.GenerationType;
030import javax.persistence.Id;
031import javax.persistence.JoinColumn;
032import javax.persistence.NamedQueries;
033import javax.persistence.NamedQuery;
034import javax.persistence.Table;
035
036/**
037 * Indicator that login to a site should be automatically granted
038 * without user interaction.
039 * @author jricher, aanganes
040 *
041 */
042@Entity
043@Table(name="whitelisted_site")
044@NamedQueries({
045        @NamedQuery(name = WhitelistedSite.QUERY_ALL, query = "select w from WhitelistedSite w"),
046        @NamedQuery(name = WhitelistedSite.QUERY_BY_CLIENT_ID, query = "select w from WhitelistedSite w where w.clientId = :" + WhitelistedSite.PARAM_CLIENT_ID),
047        @NamedQuery(name = WhitelistedSite.QUERY_BY_CREATOR, query = "select w from WhitelistedSite w where w.creatorUserId = :" + WhitelistedSite.PARAM_USER_ID)
048})
049public class WhitelistedSite {
050
051        public static final String QUERY_BY_CREATOR = "WhitelistedSite.getByCreatoruserId";
052        public static final String QUERY_BY_CLIENT_ID = "WhitelistedSite.getByClientId";
053        public static final String QUERY_ALL = "WhitelistedSite.getAll";
054
055        public static final String PARAM_USER_ID = "userId";
056        public static final String PARAM_CLIENT_ID = "clientId";
057
058        // unique id
059        private Long id;
060
061        // Reference to the admin user who created this entry
062        private String creatorUserId;
063
064        // which OAuth2 client is this tied to
065        private String clientId;
066
067        // what scopes be allowed by default
068        // this should include all information for what data to access
069        private Set<String> allowedScopes;
070
071        /**
072         * Empty constructor
073         */
074        public WhitelistedSite() {
075
076        }
077
078        /**
079         * @return the id
080         */
081        @Id
082        @GeneratedValue(strategy = GenerationType.IDENTITY)
083        @Column(name = "id")
084        public Long getId() {
085                return id;
086        }
087
088        /**
089         * @param id the id to set
090         */
091        public void setId(Long id) {
092                this.id = id;
093        }
094
095        /**
096         * @return the clientId
097         */
098        @Basic
099        @Column(name="client_id")
100        public String getClientId() {
101                return clientId;
102        }
103
104        /**
105         * @param clientId the clientId to set
106         */
107        public void setClientId(String clientId) {
108                this.clientId = clientId;
109        }
110
111        /**
112         * @return the allowedScopes
113         */
114        @ElementCollection(fetch = FetchType.EAGER)
115        @CollectionTable(
116                        name="whitelisted_site_scope",
117                        joinColumns=@JoinColumn(name="owner_id")
118                        )
119        @Column(name="scope")
120        public Set<String> getAllowedScopes() {
121                return allowedScopes;
122        }
123
124        /**
125         * @param allowedScopes the allowedScopes to set
126         */
127        public void setAllowedScopes(Set<String> allowedScopes) {
128                this.allowedScopes = allowedScopes;
129        }
130
131        @Basic
132        @Column(name="creator_user_id")
133        public String getCreatorUserId() {
134                return creatorUserId;
135        }
136
137        public void setCreatorUserId(String creatorUserId) {
138                this.creatorUserId = creatorUserId;
139        }
140}