Skip to content

Commit 4b4d86c

Browse files
author
Steve Riesenberg
committed
Add mappings to/from intermediate objects for NoSQL support
This is a draft solution for supporting NoSQL databases. It uses intermediary objects (currently called "Resources", but open to better names) to simplify a transformation to/from JSON. The intermediary objects support full serialization to JSON with the use of the `OAuth2AuthorizationServerJackson2Module`. Supports the following: * Handles iterating/mapping supported token types, removing the need for applications to do this * Converts enumerated types to/from strings with support for "custom" types * Converts authorities to/from strings * Supports custom settings values Issue spring-projectsgh-558
1 parent 165d290 commit 4b4d86c

File tree

7 files changed

+886
-6
lines changed

7 files changed

+886
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.security.oauth2.server.authorization;
17+
18+
import java.util.Set;
19+
20+
/**
21+
* Resource containing the data of an {@link OAuth2AuthorizationConsent} object.
22+
*
23+
* @author Steve Riesenberg
24+
* @since 0.2.2
25+
*/
26+
public class OAuth2AuthorizationConsentResource {
27+
private String registeredClientId;
28+
private String principalName;
29+
private Set<String> authorities;
30+
31+
public String getRegisteredClientId() {
32+
return registeredClientId;
33+
}
34+
35+
public void setRegisteredClientId(String registeredClientId) {
36+
this.registeredClientId = registeredClientId;
37+
}
38+
39+
public String getPrincipalName() {
40+
return principalName;
41+
}
42+
43+
public void setPrincipalName(String principalName) {
44+
this.principalName = principalName;
45+
}
46+
47+
public Set<String> getAuthorities() {
48+
return authorities;
49+
}
50+
51+
public void setAuthorities(Set<String> authorities) {
52+
this.authorities = authorities;
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
* Copyright 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.security.oauth2.server.authorization;
17+
18+
import java.time.Instant;
19+
import java.util.Map;
20+
import java.util.Set;
21+
22+
/**
23+
* Resource containing the data of an {@link OAuth2Authorization} object.
24+
*
25+
* @author Steve Riesenberg
26+
* @since 0.2.2
27+
*/
28+
public class OAuth2AuthorizationResource {
29+
private String id;
30+
private String registeredClientId;
31+
private String principalName;
32+
private String authorizationGrantType;
33+
private String state;
34+
private Set<String> scopes;
35+
private Map<String, Object> attributes;
36+
private Map<String, OAuth2TokenResource> tokens;
37+
38+
public String getId() {
39+
return id;
40+
}
41+
42+
public void setId(String id) {
43+
this.id = id;
44+
}
45+
46+
public String getRegisteredClientId() {
47+
return registeredClientId;
48+
}
49+
50+
public void setRegisteredClientId(String registeredClientId) {
51+
this.registeredClientId = registeredClientId;
52+
}
53+
54+
public String getPrincipalName() {
55+
return principalName;
56+
}
57+
58+
public void setPrincipalName(String principalName) {
59+
this.principalName = principalName;
60+
}
61+
62+
public String getAuthorizationGrantType() {
63+
return authorizationGrantType;
64+
}
65+
66+
public void setAuthorizationGrantType(String authorizationGrantType) {
67+
this.authorizationGrantType = authorizationGrantType;
68+
}
69+
70+
public String getState() {
71+
return state;
72+
}
73+
74+
public void setState(String state) {
75+
this.state = state;
76+
}
77+
78+
public Set<String> getScopes() {
79+
return scopes;
80+
}
81+
82+
public void setScopes(Set<String> scopes) {
83+
this.scopes = scopes;
84+
}
85+
86+
public Map<String, Object> getAttributes() {
87+
return attributes;
88+
}
89+
90+
public void setAttributes(Map<String, Object> attributes) {
91+
this.attributes = attributes;
92+
}
93+
94+
public Map<String, OAuth2TokenResource> getTokens() {
95+
return tokens;
96+
}
97+
98+
public void setTokens(Map<String, OAuth2TokenResource> tokens) {
99+
this.tokens = tokens;
100+
}
101+
102+
public static class OAuth2TokenResource {
103+
private String tokenValue;
104+
private Instant issuedAt;
105+
private Instant expiresAt;
106+
private Map<String, Object> metadata;
107+
108+
public String getTokenValue() {
109+
return tokenValue;
110+
}
111+
112+
public void setTokenValue(String tokenValue) {
113+
this.tokenValue = tokenValue;
114+
}
115+
116+
public Instant getIssuedAt() {
117+
return issuedAt;
118+
}
119+
120+
public void setIssuedAt(Instant issuedAt) {
121+
this.issuedAt = issuedAt;
122+
}
123+
124+
public Instant getExpiresAt() {
125+
return expiresAt;
126+
}
127+
128+
public void setExpiresAt(Instant expiresAt) {
129+
this.expiresAt = expiresAt;
130+
}
131+
132+
public Map<String, Object> getMetadata() {
133+
return metadata;
134+
}
135+
136+
public void setMetadata(Map<String, Object> metadata) {
137+
this.metadata = metadata;
138+
}
139+
}
140+
}

0 commit comments

Comments
 (0)