001/* 002 * JGrapes Event Driven Framework 003 * Copyright (C) 2022 Michael N. Lipp 004 * 005 * This program is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU Affero General Public License as published by 007 * the Free Software Foundation; either version 3 of the License, or 008 * (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, but 011 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 012 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License 013 * for more details. 014 * 015 * You should have received a copy of the GNU Affero General Public License along 016 * with this program; if not, see <http://www.gnu.org/licenses/>. 017 */ 018 019package org.jgrapes.webconlet.oidclogin; 020 021import com.fasterxml.jackson.annotation.JsonProperty; 022import java.net.URL; 023import java.util.Collections; 024import java.util.HashMap; 025import java.util.List; 026import java.util.Map; 027import java.util.regex.Pattern; 028 029/** 030 * The Class OidcProviderData. 031 */ 032@SuppressWarnings("PMD.DataClass") 033public class OidcProviderData { 034 035 private final String name; 036 private final String displayName; 037 private String clientId; 038 private String secret; 039 private URL issuer; 040 private URL configurationEndpoint; 041 private URL authorizationEndpoint; 042 private URL tokenEndpoint; 043 private URL userinfoEndpoint; 044 @SuppressWarnings("PMD.UseConcurrentHashMap") 045 private Map<String, String> popup = new HashMap<>(); 046 private List<String> authorizedRoles = Collections.emptyList(); 047 private List<Map<String, String>> userMappings = Collections.emptyList(); 048 private List<Map<String, String>> roleMappings = Collections.emptyList(); 049 @SuppressWarnings("PMD.UseConcurrentHashMap") 050 private final Map<String, Pattern> patternCache = new HashMap<>(); 051 052 /** 053 * Instantiates a new oidc provider data. 054 * 055 * @param name the name 056 * @param displayName the display name 057 */ 058 public OidcProviderData(@JsonProperty("name") String name, 059 @JsonProperty("displayName") String displayName) { 060 super(); 061 this.name = name; 062 this.displayName = displayName != null ? displayName : name; 063 } 064 065 /** 066 * Gets the name. 067 * 068 * @return the name 069 */ 070 public String name() { 071 return name; 072 } 073 074 /** 075 * Gets the display name. 076 * 077 * @return the display name 078 */ 079 public String displayName() { 080 return displayName; 081 } 082 083 /** 084 * Gets the client id. 085 * 086 * @return the client id 087 */ 088 public String clientId() { 089 return clientId; 090 } 091 092 /** 093 * Sets the client id. 094 * 095 * @param clientId the new client id 096 */ 097 public void setClientId(String clientId) { 098 this.clientId = clientId; 099 } 100 101 /** 102 * Gets the secret. 103 * 104 * @return the secret 105 */ 106 public String secret() { 107 return secret; 108 } 109 110 /** 111 * Sets the secret. 112 * 113 * @param secret the new secret 114 */ 115 public void setSecret(String secret) { 116 this.secret = secret; 117 } 118 119 /** 120 * Gets the issuer. 121 * 122 * @return the issuer 123 */ 124 public URL issuer() { 125 return issuer; 126 } 127 128 /** 129 * Sets the issuer. 130 * 131 * @param issuer the new issuer 132 */ 133 public void setIssuer(URL issuer) { 134 this.issuer = issuer; 135 } 136 137 /** 138 * Gets the configuration endpoint. 139 * 140 * @return the configuration endpoint 141 */ 142 public URL configurationEndpoint() { 143 return configurationEndpoint; 144 } 145 146 /** 147 * Sets the configuration endpoint. 148 * 149 * @param configurationEndpoint the new configuration endpoint 150 */ 151 public void setConfigurationEndpoint(URL configurationEndpoint) { 152 this.configurationEndpoint = configurationEndpoint; 153 } 154 155 /** 156 * Gets the authorization endpoint. 157 * 158 * @return the authorization endpoint 159 */ 160 public URL authorizationEndpoint() { 161 return authorizationEndpoint; 162 } 163 164 /** 165 * Sets the authorization endpoint. 166 * 167 * @param authorizationEp the new authorization endpoint 168 */ 169 public void setAuthorizationEndpoint(URL authorizationEp) { 170 this.authorizationEndpoint = authorizationEp; 171 } 172 173 /** 174 * Gets the token endpoint. 175 * 176 * @return the token endpoint 177 */ 178 public URL tokenEndpoint() { 179 return tokenEndpoint; 180 } 181 182 /** 183 * Sets the token endpoint. 184 * 185 * @param tokenEndpoint the new token endpoint 186 */ 187 public void setTokenEndpoint(URL tokenEndpoint) { 188 this.tokenEndpoint = tokenEndpoint; 189 } 190 191 /** 192 * Gets the userinfo endpoint. 193 * 194 * @return the userinfo endpoint 195 */ 196 public URL userinfoEndpoint() { 197 return userinfoEndpoint; 198 } 199 200 /** 201 * Sets the userinfo endpoint. 202 * 203 * @param userinfoEndpoint the new userinfo endpoint 204 */ 205 public void setUserinfoEndpoint(URL userinfoEndpoint) { 206 this.userinfoEndpoint = userinfoEndpoint; 207 } 208 209 @Override 210 public String toString() { 211 return "Oidc Provider " + name + " (" + displayName 212 + ") at " + configurationEndpoint; 213 } 214 215 /** 216 * Gets the popup options. 217 * 218 * @return the popup 219 */ 220 public Map<String, String> popup() { 221 return popup; 222 } 223 224 /** 225 * Sets the popup option. 226 * 227 * @param popup the popup 228 */ 229 public void setPopup(Map<String, String> popup) { 230 this.popup = popup; 231 } 232 233 /** 234 * Gets the authorized roles. 235 * 236 * @return the authorized roles 237 */ 238 public List<String> authorizedRoles() { 239 return authorizedRoles; 240 } 241 242 /** 243 * Sets the authorized roles. 244 * 245 * @param authorizedRoles the authorized roles 246 */ 247 public void setAuthorizedRoles(List<String> authorizedRoles) { 248 this.authorizedRoles = authorizedRoles; 249 } 250 251 /** 252 * Gets the user mappings. 253 * 254 * @return the user mappings 255 */ 256 public List<Map<String, String>> userMappings() { 257 return userMappings; 258 } 259 260 /** 261 * Sets the user mappings. 262 * 263 * @param userMappings the user mappings 264 */ 265 public void setUserMappings(List<Map<String, String>> userMappings) { 266 this.userMappings = userMappings; 267 } 268 269 /** 270 * Gets the role mappings. 271 * 272 * @return the role mappings 273 */ 274 public List<Map<String, String>> roleMappings() { 275 return roleMappings; 276 } 277 278 /** 279 * Sets the role mappings. 280 * 281 * @param roleMappings the role mappings 282 */ 283 public void setRoleMappings(List<Map<String, String>> roleMappings) { 284 this.roleMappings = roleMappings; 285 } 286 287 /** 288 * Gets the pattern cache. 289 * 290 * @return the pattern cache 291 */ 292 public Map<String, Pattern> patternCache() { 293 return patternCache; 294 } 295}