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 ******************************************************************************/
017/**
018 * 
019 */
020package org.mitre.oauth2.model;
021
022import javax.persistence.Basic;
023import javax.persistence.Column;
024import javax.persistence.Entity;
025import javax.persistence.GeneratedValue;
026import javax.persistence.GenerationType;
027import javax.persistence.Id;
028import javax.persistence.NamedQueries;
029import javax.persistence.NamedQuery;
030import javax.persistence.Table;
031import javax.persistence.Transient;
032
033/**
034 * @author jricher
035 *
036 */
037@Entity
038@Table(name = "system_scope")
039@NamedQueries({
040        @NamedQuery(name = "SystemScope.findAll", query = "select s from SystemScope s ORDER BY s.id"),
041        @NamedQuery(name = "SystemScope.getByValue", query = "select s from SystemScope s WHERE s.value = :value")
042})
043public class SystemScope {
044
045        private Long id;
046        private String value; // scope value
047        private String description; // human-readable description
048        private String icon; // class of the icon to display on the auth page
049        private boolean allowDynReg = false; // can a dynamically registered client ask for this scope?
050        private boolean defaultScope = false; // is this a default scope for newly-registered clients?
051        private boolean structured = false; // is this a default scope for newly-registered clients?
052        private String structuredParamDescription;
053        private String structuredValue;
054
055        /**
056         * Make a blank system scope with no value
057         */
058        public SystemScope() {
059
060        }
061
062        /**
063         * Make a system scope with the given scope value
064         * @param value
065         */
066        public SystemScope(String value) {
067                this.value = value;
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         * @param id the id to set
081         */
082        public void setId(Long id) {
083                this.id = id;
084        }
085        /**
086         * @return the value
087         */
088        @Basic
089        @Column(name = "scope")
090        public String getValue() {
091                return value;
092        }
093        /**
094         * @param value the value to set
095         */
096        public void setValue(String value) {
097                this.value = value;
098        }
099        /**
100         * @return the description
101         */
102        @Basic
103        @Column(name = "description")
104        public String getDescription() {
105                return description;
106        }
107        /**
108         * @param description the description to set
109         */
110        public void setDescription(String description) {
111                this.description = description;
112        }
113        /**
114         * @return the icon
115         */
116        @Basic
117        @Column(name = "icon")
118        public String getIcon() {
119                return icon;
120        }
121        /**
122         * @param icon the icon to set
123         */
124        public void setIcon(String icon) {
125                this.icon = icon;
126        }
127        /**
128         * @return the allowDynReg
129         */
130        @Basic
131        @Column(name = "allow_dyn_reg")
132        public boolean isAllowDynReg() {
133                return allowDynReg;
134        }
135        /**
136         * @param allowDynReg the allowDynReg to set
137         */
138        public void setAllowDynReg(boolean allowDynReg) {
139                this.allowDynReg = allowDynReg;
140        }
141
142        /**
143         * @return the defaultScope
144         */
145        @Basic
146        @Column(name = "default_scope")
147        public boolean isDefaultScope() {
148                return defaultScope;
149        }
150
151        /**
152         * @param defaultScope the defaultScope to set
153         */
154        public void setDefaultScope(boolean defaultScope) {
155                this.defaultScope = defaultScope;
156        }
157
158        /**
159         * @return the isStructured status
160         */
161        @Basic
162        @Column(name = "structured")
163        public boolean isStructured() {
164                return structured;
165        }
166
167        /**
168         * @param structured the structured to set
169         */
170        public void setStructured(boolean structured) {
171                this.structured = structured;
172        }
173
174        @Basic
175        @Column(name = "structured_param_description")
176        public String getStructuredParamDescription() {
177                return structuredParamDescription;
178        }
179
180        /**
181         * @param isStructured the isStructured to set
182         */
183        public void setStructuredParamDescription(String d) {
184                this.structuredParamDescription = d;
185        }
186
187
188        /**
189         * @return the structuredValue
190         */
191        @Transient // we don't save the value of a system scope separately
192        public String getStructuredValue() {
193                return structuredValue;
194        }
195
196        /**
197         * @param structuredValue the structuredValue to set
198         */
199        public void setStructuredValue(String structuredValue) {
200                this.structuredValue = structuredValue;
201        }
202
203
204        /* (non-Javadoc)
205         * @see java.lang.Object#hashCode()
206         */
207        @Override
208        public int hashCode() {
209                final int prime = 31;
210                int result = 1;
211                result = prime * result + (allowDynReg ? 1231 : 1237);
212                result = prime * result + (defaultScope ? 1231 : 1237);
213                result = prime * result + ((description == null) ? 0 : description.hashCode());
214                result = prime * result + ((icon == null) ? 0 : icon.hashCode());
215                result = prime * result + ((id == null) ? 0 : id.hashCode());
216                result = prime * result + (structured ? 1231 : 1237);
217                result = prime * result + ((structuredParamDescription == null) ? 0 : structuredParamDescription.hashCode());
218                result = prime * result + ((structuredValue == null) ? 0 : structuredValue.hashCode());
219                result = prime * result + ((value == null) ? 0 : value.hashCode());
220                return result;
221        }
222
223        /* (non-Javadoc)
224         * @see java.lang.Object#equals(java.lang.Object)
225         */
226        @Override
227        public boolean equals(Object obj) {
228                if (this == obj) {
229                        return true;
230                }
231                if (obj == null) {
232                        return false;
233                }
234                if (!(obj instanceof SystemScope)) {
235                        return false;
236                }
237                SystemScope other = (SystemScope) obj;
238                if (allowDynReg != other.allowDynReg) {
239                        return false;
240                }
241                if (defaultScope != other.defaultScope) {
242                        return false;
243                }
244                if (description == null) {
245                        if (other.description != null) {
246                                return false;
247                        }
248                } else if (!description.equals(other.description)) {
249                        return false;
250                }
251                if (icon == null) {
252                        if (other.icon != null) {
253                                return false;
254                        }
255                } else if (!icon.equals(other.icon)) {
256                        return false;
257                }
258                if (id == null) {
259                        if (other.id != null) {
260                                return false;
261                        }
262                } else if (!id.equals(other.id)) {
263                        return false;
264                }
265                if (structured != other.structured) {
266                        return false;
267                }
268                if (structuredParamDescription == null) {
269                        if (other.structuredParamDescription != null) {
270                                return false;
271                        }
272                } else if (!structuredParamDescription.equals(other.structuredParamDescription)) {
273                        return false;
274                }
275                if (structuredValue == null) {
276                        if (other.structuredValue != null) {
277                                return false;
278                        }
279                } else if (!structuredValue.equals(other.structuredValue)) {
280                        return false;
281                }
282                if (value == null) {
283                        if (other.value != null) {
284                                return false;
285                        }
286                } else if (!value.equals(other.value)) {
287                        return false;
288                }
289                return true;
290        }
291
292        /* (non-Javadoc)
293         * @see java.lang.Object#toString()
294         */
295        @Override
296        public String toString() {
297                return "SystemScope [id=" + id + ", value=" + value + ", description=" + description + ", icon=" + icon + ", allowDynReg=" + allowDynReg + ", defaultScope=" + defaultScope + ", structured=" + structured + ", structuredParamDescription=" + structuredParamDescription + ", structuredValue="
298                                + structuredValue + "]";
299        }
300
301}