001/******************************************************************************* 002 * Copyright 2017 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 *******************************************************************************/ 018/** 019 * 020 */ 021package org.mitre.oauth2.model; 022 023import javax.persistence.Basic; 024import javax.persistence.Column; 025import javax.persistence.Entity; 026import javax.persistence.GeneratedValue; 027import javax.persistence.GenerationType; 028import javax.persistence.Id; 029import javax.persistence.NamedQueries; 030import javax.persistence.NamedQuery; 031import javax.persistence.Table; 032 033/** 034 * @author jricher 035 * 036 */ 037@Entity 038@Table(name = "system_scope") 039@NamedQueries({ 040 @NamedQuery(name = SystemScope.QUERY_ALL, query = "select s from SystemScope s ORDER BY s.id"), 041 @NamedQuery(name = SystemScope.QUERY_BY_VALUE, query = "select s from SystemScope s WHERE s.value = :" + SystemScope.PARAM_VALUE) 042}) 043public class SystemScope { 044 045 public static final String QUERY_BY_VALUE = "SystemScope.getByValue"; 046 public static final String QUERY_ALL = "SystemScope.findAll"; 047 048 public static final String PARAM_VALUE = "value"; 049 050 private Long id; 051 private String value; // scope value 052 private String description; // human-readable description 053 private String icon; // class of the icon to display on the auth page 054 private boolean defaultScope = false; // is this a default scope for newly-registered clients? 055 private boolean restricted = false; // is this scope restricted to admin-only registration access? 056 057 /** 058 * Make a blank system scope with no value 059 */ 060 public SystemScope() { 061 062 } 063 064 /** 065 * Make a system scope with the given scope value 066 * @param value 067 */ 068 public SystemScope(String value) { 069 this.value = value; 070 } 071 072 /** 073 * @return the id 074 */ 075 @Id 076 @GeneratedValue(strategy = GenerationType.IDENTITY) 077 @Column(name = "id") 078 public Long getId() { 079 return id; 080 } 081 /** 082 * @param id the id to set 083 */ 084 public void setId(Long id) { 085 this.id = id; 086 } 087 /** 088 * @return the value 089 */ 090 @Basic 091 @Column(name = "scope") 092 public String getValue() { 093 return value; 094 } 095 /** 096 * @param value the value to set 097 */ 098 public void setValue(String value) { 099 this.value = value; 100 } 101 /** 102 * @return the description 103 */ 104 @Basic 105 @Column(name = "description") 106 public String getDescription() { 107 return description; 108 } 109 /** 110 * @param description the description to set 111 */ 112 public void setDescription(String description) { 113 this.description = description; 114 } 115 /** 116 * @return the icon 117 */ 118 @Basic 119 @Column(name = "icon") 120 public String getIcon() { 121 return icon; 122 } 123 /** 124 * @param icon the icon to set 125 */ 126 public void setIcon(String icon) { 127 this.icon = icon; 128 } 129 130 /** 131 * @return the defaultScope 132 */ 133 @Basic 134 @Column(name = "default_scope") 135 public boolean isDefaultScope() { 136 return defaultScope; 137 } 138 139 /** 140 * @param defaultScope the defaultScope to set 141 */ 142 public void setDefaultScope(boolean defaultScope) { 143 this.defaultScope = defaultScope; 144 } 145 146 /** 147 * @return the restricted 148 */ 149 @Basic 150 @Column(name = "restricted") 151 public boolean isRestricted() { 152 return restricted; 153 } 154 155 /** 156 * @param restricted the restricted to set 157 */ 158 public void setRestricted(boolean restricted) { 159 this.restricted = restricted; 160 } 161 162 /* (non-Javadoc) 163 * @see java.lang.Object#hashCode() 164 */ 165 @Override 166 public int hashCode() { 167 final int prime = 31; 168 int result = 1; 169 result = prime * result + (defaultScope ? 1231 : 1237); 170 result = prime * result 171 + ((description == null) ? 0 : description.hashCode()); 172 result = prime * result + ((icon == null) ? 0 : icon.hashCode()); 173 result = prime * result + ((id == null) ? 0 : id.hashCode()); 174 result = prime * result + (restricted ? 1231 : 1237); 175 result = prime * result + ((value == null) ? 0 : value.hashCode()); 176 return result; 177 } 178 179 /* (non-Javadoc) 180 * @see java.lang.Object#equals(java.lang.Object) 181 */ 182 @Override 183 public boolean equals(Object obj) { 184 if (this == obj) { 185 return true; 186 } 187 if (obj == null) { 188 return false; 189 } 190 if (getClass() != obj.getClass()) { 191 return false; 192 } 193 SystemScope other = (SystemScope) obj; 194 if (defaultScope != other.defaultScope) { 195 return false; 196 } 197 if (description == null) { 198 if (other.description != null) { 199 return false; 200 } 201 } else if (!description.equals(other.description)) { 202 return false; 203 } 204 if (icon == null) { 205 if (other.icon != null) { 206 return false; 207 } 208 } else if (!icon.equals(other.icon)) { 209 return false; 210 } 211 if (id == null) { 212 if (other.id != null) { 213 return false; 214 } 215 } else if (!id.equals(other.id)) { 216 return false; 217 } 218 if (restricted != other.restricted) { 219 return false; 220 } 221 if (value == null) { 222 if (other.value != null) { 223 return false; 224 } 225 } else if (!value.equals(other.value)) { 226 return false; 227 } 228 return true; 229 } 230 231 /* (non-Javadoc) 232 * @see java.lang.Object#toString() 233 */ 234 @Override 235 public String toString() { 236 return "SystemScope [id=" + id + ", value=" + value + ", description=" 237 + description + ", icon=" + icon + ", defaultScope=" 238 + defaultScope + ", restricted=" + restricted + "]"; 239 } 240 241}