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