blob: 6f7ab07423ba2e48069fe6443eeea2a8cb3145f9 [file] [log] [blame]
margaretha835178d2018-08-15 19:04:03 +02001package de.ids_mannheim.korap.oauth2.dto;
2
margaretha79f01442022-05-04 12:03:47 +02003import java.time.ZonedDateTime;
4
margaretha835178d2018-08-15 19:04:03 +02005import com.fasterxml.jackson.annotation.JsonInclude;
6import com.fasterxml.jackson.annotation.JsonInclude.Include;
margarethad7163122022-04-11 09:42:41 +02007import com.fasterxml.jackson.annotation.JsonProperty;
margaretha977fabe2022-04-28 09:23:47 +02008import com.fasterxml.jackson.databind.JsonNode;
margaretha835178d2018-08-15 19:04:03 +02009
margarethad7163122022-04-11 09:42:41 +020010import de.ids_mannheim.korap.exceptions.KustvaktException;
margaretha835178d2018-08-15 19:04:03 +020011import de.ids_mannheim.korap.oauth2.constant.OAuth2ClientType;
12import de.ids_mannheim.korap.oauth2.entity.OAuth2Client;
margarethad7163122022-04-11 09:42:41 +020013import de.ids_mannheim.korap.utils.JsonUtils;
margaretha835178d2018-08-15 19:04:03 +020014
margaretha79f01442022-05-04 12:03:47 +020015/**
16 * Describes information about an OAuth2 client.
margaretha398f4722019-01-09 19:07:20 +010017 *
18 * @author margaretha
19 *
20 */
margaretha835178d2018-08-15 19:04:03 +020021@JsonInclude(Include.NON_EMPTY)
margaretha64755022024-06-18 10:30:59 +020022public class OAuth2ClientInfoDto implements Comparable<OAuth2ClientInfoDto>{
margaretha79f01442022-05-04 12:03:47 +020023 @JsonProperty("super")
24 private boolean isSuper;
margaretha835178d2018-08-15 19:04:03 +020025
margaretha79f01442022-05-04 12:03:47 +020026 @JsonProperty("client_id")
27 private String clientId;
28 @JsonProperty("client_name")
29 private String clientName;
30 @JsonProperty("client_type")
31 private OAuth2ClientType clientType;
32 @JsonProperty("client_description")
margaretha835178d2018-08-15 19:04:03 +020033 private String description;
margaretha79f01442022-05-04 12:03:47 +020034 @JsonProperty("client_url")
margarethac20cd342019-11-14 10:59:39 +010035 private String url;
margaretha79f01442022-05-04 12:03:47 +020036 @JsonProperty("client_redirect_uri")
margaretha3ef1b812022-04-06 11:32:54 +020037 private String redirect_uri;
margarethad7163122022-04-11 09:42:41 +020038 @JsonProperty("registration_date")
39 private String registrationDate;
margaretha79f01442022-05-04 12:03:47 +020040 @JsonProperty("registered_by")
41 private String registeredBy;
margaretha977fabe2022-04-28 09:23:47 +020042 @JsonProperty("refresh_token_expiry")
margaretha60b65d42024-06-06 09:05:16 +020043 @JsonInclude(Include.NON_DEFAULT)
margaretha977fabe2022-04-28 09:23:47 +020044 private int refreshTokenExpiry; // in seconds
margaretha79f01442022-05-04 12:03:47 +020045
margarethad7163122022-04-11 09:42:41 +020046 @JsonProperty("permitted")
47 private boolean isPermitted;
48 private JsonNode source;
margaretha835178d2018-08-15 19:04:03 +020049
margarethad7163122022-04-11 09:42:41 +020050 public OAuth2ClientInfoDto (OAuth2Client client) throws KustvaktException {
margaretha60b65d42024-06-06 09:05:16 +020051 this(client,true);
52 }
53
54 public OAuth2ClientInfoDto (OAuth2Client client, boolean showAllInfo) throws KustvaktException {
margaretha79f01442022-05-04 12:03:47 +020055 this.setClientId(client.getId());
56 this.setClientName(client.getName());
57 this.setDescription(client.getDescription());
58 this.setClientType(client.getType());
59 this.setUrl(client.getUrl());
60 this.setClientType(client.getType());
margaretha79f01442022-05-04 12:03:47 +020061 this.setPermitted(client.isPermitted());
margaretha60b65d42024-06-06 09:05:16 +020062
margarethad7163122022-04-11 09:42:41 +020063 String source = client.getSource();
margaretha60b65d42024-06-06 09:05:16 +020064
65 if (showAllInfo) {
66 this.setSuper(client.isSuper());
67 this.setRedirect_uri(client.getRedirectURI());
68 this.setRegisteredBy(client.getRegisteredBy());
69 ZonedDateTime registrationDate = client.getRegistrationDate();
70 if (registrationDate != null) {
71 this.setRegistrationDate(registrationDate.toString());
72 }
73 if (client.getType().equals(OAuth2ClientType.CONFIDENTIAL)) {
74 this.setRefreshTokenExpiry(client.getRefreshTokenExpiry());
75 }
76
77 if (source != null && !source.isEmpty()) {
78 this.source = JsonUtils.readTree(source);
79 }
margarethad7163122022-04-11 09:42:41 +020080 }
margaretha60b65d42024-06-06 09:05:16 +020081 else { //plugins
82 if (source != null && !source.isEmpty()) {
83 this.source = JsonUtils.readTree(source);
84 }
85 }
margaretha835178d2018-08-15 19:04:03 +020086 }
margaretha64755022024-06-18 10:30:59 +020087
88 @Override
89 public int compareTo (OAuth2ClientInfoDto o) {
90 return this.getClientName().compareTo(o.getClientName());
91 }
92
margaretha835178d2018-08-15 19:04:03 +020093
margaretha79f01442022-05-04 12:03:47 +020094 public boolean isSuper () {
margaretha835178d2018-08-15 19:04:03 +020095 return isSuper;
96 }
97
margaretha79f01442022-05-04 12:03:47 +020098 public void setSuper (boolean isSuper) {
margaretha835178d2018-08-15 19:04:03 +020099 this.isSuper = isSuper;
100 }
101
margaretha835178d2018-08-15 19:04:03 +0200102 public String getRegisteredBy () {
103 return registeredBy;
104 }
105
106 public void setRegisteredBy (String registeredBy) {
107 this.registeredBy = registeredBy;
108 }
109
margaretha79f01442022-05-04 12:03:47 +0200110 public String getClientId () {
111 return clientId;
margaretha835178d2018-08-15 19:04:03 +0200112 }
113
margaretha79f01442022-05-04 12:03:47 +0200114 public void setClientId (String clientId) {
115 this.clientId = clientId;
116 }
117
118 public String getClientName () {
119 return clientName;
120 }
121
122 public void setClientName (String clientName) {
123 this.clientName = clientName;
124 }
125
126 public OAuth2ClientType getClientType () {
127 return clientType;
128 }
129
130 public void setClientType (OAuth2ClientType clientType) {
131 this.clientType = clientType;
132 }
133
134 public String getDescription () {
135 return description;
136 }
137
138 public void setDescription (String description) {
139 this.description = description;
140 }
141
142 public String getUrl () {
143 return url;
144 }
145
146 public void setUrl (String url) {
147 this.url = url;
margaretha835178d2018-08-15 19:04:03 +0200148 }
149
margaretha3ef1b812022-04-06 11:32:54 +0200150 public String getRedirect_uri () {
151 return redirect_uri;
152 }
153
154 public void setRedirect_uri (String redirect_uri) {
155 this.redirect_uri = redirect_uri;
156 }
margaretha79f01442022-05-04 12:03:47 +0200157
margarethad7163122022-04-11 09:42:41 +0200158 public String getRegistrationDate () {
159 return registrationDate;
160 }
margaretha79f01442022-05-04 12:03:47 +0200161
margarethad7163122022-04-11 09:42:41 +0200162 public void setRegistrationDate (String registrationDate) {
163 this.registrationDate = registrationDate;
164 }
margaretha79f01442022-05-04 12:03:47 +0200165
margaretha977fabe2022-04-28 09:23:47 +0200166 public int getRefreshTokenExpiry () {
167 return refreshTokenExpiry;
168 }
margaretha79f01442022-05-04 12:03:47 +0200169
margaretha977fabe2022-04-28 09:23:47 +0200170 public void setRefreshTokenExpiry (int refreshTokenExpiry) {
171 this.refreshTokenExpiry = refreshTokenExpiry;
172 }
margaretha3ef1b812022-04-06 11:32:54 +0200173
margaretha79f01442022-05-04 12:03:47 +0200174 public boolean isPermitted () {
175 return isPermitted;
176 }
177
178 public void setPermitted (boolean isPermitted) {
179 this.isPermitted = isPermitted;
180 }
181
182 public JsonNode getSource () {
183 return source;
184 }
185
186 public void setSource (JsonNode source) {
187 this.source = source;
188 }
margaretha835178d2018-08-15 19:04:03 +0200189}