001package ca.cdr.api.model.json; 002 003/*- 004 * #%L 005 * Smile CDR - CDR 006 * %% 007 * Copyright (C) 2016 - 2025 Smile CDR, Inc. 008 * %% 009 * All rights reserved. 010 * #L% 011 */ 012 013import com.fasterxml.jackson.annotation.JsonProperty; 014import com.fasterxml.jackson.annotation.JsonPropertyOrder; 015import io.swagger.v3.oas.annotations.media.Schema; 016import jakarta.validation.constraints.NotBlank; 017import org.springframework.security.oauth2.provider.ClientDetails; 018 019import java.io.Serial; 020import java.util.HashMap; 021import java.util.Map; 022import java.util.regex.Pattern; 023 024@Schema(name = "OAuth2Client", description = "Represents an OpenID Connect client") 025@JsonPropertyOrder( 026 value = { 027 OAuth2WritableClientDetailsJson.PID, 028 OAuth2ClientDetailsJson.NODE_ID, 029 OAuth2ClientDetailsJson.MODULE_ID, 030 OAuth2WritableClientDetailsJson.CLIENT_ID, 031 OAuth2WritableClientDetailsJson.CLIENT_NAME, 032 OAuth2WritableClientDetailsJson.ENABLED 033 }, 034 alphabetic = true) 035public class OAuth2ClientDetailsJson extends OAuth2WritableClientDetailsJson 036 implements ClientDetails, IModelJson, IOAuth2ClientDetails, IHasUserData { 037 038 public static final String MODULEID_PATTERN_CHARS = "[a-zA-Z0-9._-]"; 039 public static final int CLIENT_ID_MAX_LENGTH = 200; 040 public static final String CLIENT_ID_PATTERN = MODULEID_PATTERN_CHARS + "{1," + CLIENT_ID_MAX_LENGTH + "}"; 041 public static final Pattern CLIENT_ID_PATTERN_P = Pattern.compile(CLIENT_ID_PATTERN); 042 public static final String MODULE_ID = "moduleId"; 043 public static final String NODE_ID = "nodeId"; 044 045 @Serial 046 private static final long serialVersionUID = 1L; 047 048 @NotBlank 049 @JsonProperty(MODULE_ID) 050 @Schema(description = "The Module ID that this client is registered against") 051 private String myModuleId; 052 053 @NotBlank 054 @JsonProperty(NODE_ID) 055 @Schema(description = "The Node ID that this client is registered against") 056 private String myNodeId; 057 058 @Schema(description = "The user data for this session.") 059 @JsonProperty("userData") 060 private Map<String, Object> myUserData; 061 062 /** 063 * Constructor 064 */ 065 public OAuth2ClientDetailsJson() { 066 super(); 067 } 068 069 /** 070 * Copy constructor 071 */ 072 public OAuth2ClientDetailsJson(OAuth2ClientDetailsJson theClientDetailsJson) { 073 super(theClientDetailsJson); 074 myModuleId = theClientDetailsJson.myModuleId; 075 myNodeId = theClientDetailsJson.myNodeId; 076 } 077 078 @Override 079 public String getModuleId() { 080 return myModuleId; 081 } 082 083 public void setModuleId(String theModuleId) { 084 myModuleId = theModuleId; 085 } 086 087 @Override 088 public String getNodeId() { 089 return myNodeId; 090 } 091 092 public void setNodeId(String theNodeId) { 093 myNodeId = theNodeId; 094 } 095 096 @Override 097 public OAuth2ClientDetailsJson setPid(Long myPid) { 098 super.setPid(myPid); 099 return this; 100 } 101 102 @Override 103 public Map<String, Object> getClientPopulatedUserData(boolean theCreateIfNull) { 104 if (theCreateIfNull && myUserData == null) { 105 myUserData = new HashMap<>(); 106 } 107 return myUserData; 108 } 109}