Skip to content
This repository was archived by the owner on Sep 28, 2022. It is now read-only.

Commit a445565

Browse files
author
Dominik Frantisek Bucik
committed
refactor: 💡 Refactored all models
1 parent f85cd5c commit a445565

29 files changed

+693
-1385
lines changed

perun-oidc-server/src/main/java/cz/muni/ics/oauth2/model/ClientDetailsEntity.java

Lines changed: 208 additions & 607 deletions
Large diffs are not rendered by default.

perun-oidc-server/src/main/java/cz/muni/ics/oauth2/model/RegisteredClient.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,27 @@
2626
import com.nimbusds.jose.JWSAlgorithm;
2727
import com.nimbusds.jose.jwk.JWKSet;
2828
import com.nimbusds.jwt.JWT;
29+
import cz.muni.ics.oauth2.model.enums.AppType;
30+
import cz.muni.ics.oauth2.model.enums.AuthMethod;
31+
import cz.muni.ics.oauth2.model.enums.SubjectType;
2932
import java.util.Date;
3033
import java.util.Map;
3134
import java.util.Set;
35+
import lombok.AllArgsConstructor;
36+
import lombok.EqualsAndHashCode;
37+
import lombok.Getter;
38+
import lombok.Setter;
39+
import lombok.ToString;
3240
import org.springframework.security.core.GrantedAuthority;
3341

3442
/**
3543
* @author jricher
3644
*/
45+
@Getter
46+
@Setter
47+
@ToString
48+
@EqualsAndHashCode
49+
@AllArgsConstructor
3750
public class RegisteredClient {
3851

3952
private String registrationAccessToken;
@@ -57,14 +70,6 @@ public RegisteredClient(ClientDetailsEntity client, String registrationAccessTok
5770
this.registrationClientUri = registrationClientUri;
5871
}
5972

60-
public ClientDetailsEntity getClient() {
61-
return client;
62-
}
63-
64-
public void setClient(ClientDetailsEntity client) {
65-
this.client = client;
66-
}
67-
6873
public String getClientDescription() {
6974
return client.getClientDescription();
7075
}
@@ -201,11 +206,11 @@ public Map<String, Object> getAdditionalInformation() {
201206
return client.getAdditionalInformation();
202207
}
203208

204-
public ClientDetailsEntity.AppType getApplicationType() {
209+
public AppType getApplicationType() {
205210
return client.getApplicationType();
206211
}
207212

208-
public void setApplicationType(ClientDetailsEntity.AppType applicationType) {
213+
public void setApplicationType(AppType applicationType) {
209214
client.setApplicationType(applicationType);
210215
}
211216

@@ -217,19 +222,19 @@ public void setClientName(String clientName) {
217222
client.setClientName(clientName);
218223
}
219224

220-
public ClientDetailsEntity.AuthMethod getTokenEndpointAuthMethod() {
225+
public AuthMethod getTokenEndpointAuthMethod() {
221226
return client.getTokenEndpointAuthMethod();
222227
}
223228

224-
public void setTokenEndpointAuthMethod(ClientDetailsEntity.AuthMethod tokenEndpointAuthMethod) {
229+
public void setTokenEndpointAuthMethod(AuthMethod tokenEndpointAuthMethod) {
225230
client.setTokenEndpointAuthMethod(tokenEndpointAuthMethod);
226231
}
227232

228-
public ClientDetailsEntity.SubjectType getSubjectType() {
233+
public SubjectType getSubjectType() {
229234
return client.getSubjectType();
230235
}
231236

232-
public void setSubjectType(ClientDetailsEntity.SubjectType subjectType) {
237+
public void setSubjectType(SubjectType subjectType) {
233238
client.setSubjectType(subjectType);
234239
}
235240

perun-oidc-server/src/main/java/cz/muni/ics/oauth2/model/SystemScope.java

Lines changed: 28 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
*/
2121
package cz.muni.ics.oauth2.model;
2222

23+
import static cz.muni.ics.oauth2.model.SystemScope.*;
24+
2325
import javax.persistence.Basic;
2426
import javax.persistence.Column;
2527
import javax.persistence.Entity;
@@ -29,15 +31,31 @@
2931
import javax.persistence.NamedQueries;
3032
import javax.persistence.NamedQuery;
3133
import javax.persistence.Table;
34+
import lombok.AllArgsConstructor;
35+
import lombok.EqualsAndHashCode;
36+
import lombok.Getter;
37+
import lombok.NoArgsConstructor;
38+
import lombok.Setter;
39+
import lombok.ToString;
3240

3341
/**
3442
* @author jricher
3543
*/
44+
@Getter
45+
@Setter
46+
@ToString
47+
@EqualsAndHashCode
48+
@NoArgsConstructor
49+
@AllArgsConstructor
50+
// DB ANNOTATIONS
3651
@Entity
3752
@Table(name = "system_scope")
3853
@NamedQueries({
39-
@NamedQuery(name = SystemScope.QUERY_ALL, query = "select s from SystemScope s ORDER BY s.id"),
40-
@NamedQuery(name = SystemScope.QUERY_BY_VALUE, query = "select s from SystemScope s WHERE s.value = :" + SystemScope.PARAM_VALUE)
54+
@NamedQuery(name = QUERY_ALL,
55+
query = "SELECT s FROM SystemScope s ORDER BY s.id"),
56+
@NamedQuery(name = QUERY_BY_VALUE,
57+
query = "SELECT s FROM SystemScope s " +
58+
"WHERE s.value = :" + PARAM_VALUE)
4159
})
4260
public class SystemScope {
4361

@@ -46,145 +64,28 @@ public class SystemScope {
4664

4765
public static final String PARAM_VALUE = "value";
4866

49-
private Long id;
50-
private String value; // scope value
51-
private String description; // human-readable description
52-
private String icon; // class of the icon to display on the auth page
53-
private boolean defaultScope = false; // is this a default scope for newly-registered clients?
54-
private boolean restricted = false; // is this scope restricted to admin-only registration access?
55-
56-
public SystemScope() { }
57-
58-
public SystemScope(String value) {
59-
this.value = value;
60-
}
61-
6267
@Id
6368
@GeneratedValue(strategy = GenerationType.IDENTITY)
6469
@Column(name = "id")
65-
public Long getId() {
66-
return id;
67-
}
68-
69-
public void setId(Long id) {
70-
this.id = id;
71-
}
70+
private Long id;
7271

73-
@Basic
7472
@Column(name = "scope")
75-
public String getValue() {
76-
return value;
77-
}
73+
private String value;
7874

79-
public void setValue(String value) {
80-
this.value = value;
81-
}
82-
83-
@Basic
8475
@Column(name = "description")
85-
public String getDescription() {
86-
return description;
87-
}
88-
89-
public void setDescription(String description) {
90-
this.description = description;
91-
}
76+
private String description; // human-readable description
9277

93-
@Basic
9478
@Column(name = "icon")
95-
public String getIcon() {
96-
return icon;
97-
}
98-
99-
public void setIcon(String icon) {
100-
this.icon = icon;
101-
}
79+
private String icon; // class of the icon to display on the auth page
10280

103-
@Basic
10481
@Column(name = "default_scope")
105-
public boolean isDefaultScope() {
106-
return defaultScope;
107-
}
108-
109-
public void setDefaultScope(boolean defaultScope) {
110-
this.defaultScope = defaultScope;
111-
}
82+
private boolean defaultScope = false; // is this a default scope for newly-registered clients?
11283

113-
@Basic
11484
@Column(name = "restricted")
115-
public boolean isRestricted() {
116-
return restricted;
117-
}
118-
119-
public void setRestricted(boolean restricted) {
120-
this.restricted = restricted;
121-
}
122-
123-
@Override
124-
public int hashCode() {
125-
final int prime = 31;
126-
int result = 1;
127-
result = prime * result + (defaultScope ? 1231 : 1237);
128-
result = prime * result
129-
+ ((description == null) ? 0 : description.hashCode());
130-
result = prime * result + ((icon == null) ? 0 : icon.hashCode());
131-
result = prime * result + ((id == null) ? 0 : id.hashCode());
132-
result = prime * result + (restricted ? 1231 : 1237);
133-
result = prime * result + ((value == null) ? 0 : value.hashCode());
134-
return result;
135-
}
136-
137-
@Override
138-
public boolean equals(Object obj) {
139-
if (this == obj) {
140-
return true;
141-
}
142-
if (obj == null) {
143-
return false;
144-
}
145-
if (getClass() != obj.getClass()) {
146-
return false;
147-
}
148-
SystemScope other = (SystemScope) obj;
149-
if (defaultScope != other.defaultScope) {
150-
return false;
151-
}
152-
if (description == null) {
153-
if (other.description != null) {
154-
return false;
155-
}
156-
} else if (!description.equals(other.description)) {
157-
return false;
158-
}
159-
if (icon == null) {
160-
if (other.icon != null) {
161-
return false;
162-
}
163-
} else if (!icon.equals(other.icon)) {
164-
return false;
165-
}
166-
if (id == null) {
167-
if (other.id != null) {
168-
return false;
169-
}
170-
} else if (!id.equals(other.id)) {
171-
return false;
172-
}
173-
if (restricted != other.restricted) {
174-
return false;
175-
}
176-
if (value == null) {
177-
return other.value == null;
178-
} else {
179-
return value.equals(other.value);
180-
}
181-
}
85+
private boolean restricted = false; // is this scope restricted to admin-only registration access?
18286

183-
@Override
184-
public String toString() {
185-
return "SystemScope [id=" + id + ", value=" + value + ", description="
186-
+ description + ", icon=" + icon + ", defaultScope="
187-
+ defaultScope + ", restricted=" + restricted + "]";
87+
public SystemScope(String value) {
88+
this.value = value;
18889
}
18990

19091
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package cz.muni.ics.oauth2.model.enums;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
import lombok.AllArgsConstructor;
6+
import lombok.Getter;
7+
8+
@Getter
9+
@AllArgsConstructor
10+
public enum AppType {
11+
WEB("web"), NATIVE("native");
12+
13+
private final String value;
14+
15+
// map to aid reverse lookup
16+
private static final Map<String, AppType> lookup = new HashMap<>();
17+
static {
18+
for (AppType a : AppType.values()) {
19+
lookup.put(a.getValue(), a);
20+
}
21+
}
22+
23+
public static AppType getByValue(String value) {
24+
return lookup.get(value);
25+
}
26+
27+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package cz.muni.ics.oauth2.model.enums;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
import lombok.AllArgsConstructor;
6+
import lombok.Getter;
7+
8+
@Getter
9+
@AllArgsConstructor
10+
public enum AuthMethod {
11+
SECRET_POST("client_secret_post"),
12+
SECRET_BASIC("client_secret_basic"),
13+
SECRET_JWT("client_secret_jwt"),
14+
PRIVATE_KEY("private_key_jwt"),
15+
NONE("none");
16+
17+
private final String value;
18+
19+
// map to aid reverse lookup
20+
private static final Map<String, AuthMethod> lookup = new HashMap<>();
21+
static {
22+
for (AuthMethod a : AuthMethod.values()) {
23+
lookup.put(a.getValue(), a);
24+
}
25+
}
26+
27+
public static AuthMethod getByValue(String value) {
28+
return lookup.get(value);
29+
}
30+
31+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package cz.muni.ics.oauth2.model.enums;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
import lombok.AllArgsConstructor;
6+
import lombok.Getter;
7+
8+
@Getter
9+
@AllArgsConstructor
10+
public enum SubjectType {
11+
12+
PAIRWISE("pairwise"), PUBLIC("public");
13+
14+
private final String value;
15+
16+
// map to aid reverse lookup
17+
private static final Map<String, SubjectType> lookup = new HashMap<>();
18+
static {
19+
for (SubjectType u : SubjectType.values()) {
20+
lookup.put(u.getValue(), u);
21+
}
22+
}
23+
24+
public static SubjectType getByValue(String value) {
25+
return lookup.get(value);
26+
}
27+
}

0 commit comments

Comments
 (0)