Skip to content

Commit 52d2298

Browse files
committed
begin modularization of data import/export API
1 parent 777b7a2 commit 52d2298

File tree

11 files changed

+907
-22
lines changed

11 files changed

+907
-22
lines changed

openid-connect-client/src/main/java/org/mitre/openid/connect/client/service/RegisteredClientService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
*/
2020
package org.mitre.openid.connect.client.service;
2121

22+
import java.util.List;
23+
2224
import org.mitre.oauth2.model.RegisteredClient;
2325

2426
/**

openid-connect-common/src/main/java/org/mitre/openid/connect/service/MITREidDataService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,13 @@ public interface MITREidDataService {
6060
*/
6161
void importData(JsonReader reader) throws IOException;
6262

63+
/**
64+
* Return true if the this data service supports the given version. This is called before
65+
* handing the service the reader through its importData function.
66+
*
67+
* @param version
68+
* @return
69+
*/
70+
boolean supportsVersion(String version);
71+
6372
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*******************************************************************************
2+
* Copyright 2017 The MITRE Corporation
3+
* and the MIT Internet Trust Consortium
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*******************************************************************************/
17+
18+
package org.mitre.openid.connect.service;
19+
20+
import java.io.IOException;
21+
22+
import com.google.gson.stream.JsonReader;
23+
import com.google.gson.stream.JsonWriter;
24+
25+
/**
26+
* A modular extension to the data import/export layer. Any instances of this need to be
27+
* declared as beans to be picked up by the data services.
28+
*
29+
* @author jricher
30+
*
31+
*/
32+
public interface MITREidDataServiceExtension {
33+
34+
/**
35+
* Export any data for this extension. This is called from the top level object.
36+
* All extensions MUST return the writer to a state such that another member of
37+
* the top level object can be written next.
38+
*
39+
* @param writer
40+
*/
41+
void exportExtensionData(JsonWriter writer) throws IOException;
42+
43+
/**
44+
* Import data that's part of this extension. This is called from the context of
45+
* reading the top level object. All extensions MUST return the reader to a state
46+
* such that another member of the top level object can be read next. The name of
47+
* the data element being imported is passed in as name. If the extension does not
48+
* support this data element, it must return without advancing the reader.
49+
*
50+
* Returns "true" if the item was processed, "false" otherwise.
51+
*
52+
* @param reader
53+
*/
54+
boolean importExtensionData(String name, JsonReader reader) throws IOException;
55+
56+
/**
57+
* Signal the extension to wrap up all object processing and finalize its
58+
*/
59+
void fixExtensionObjectReferences();
60+
61+
/**
62+
* Return
63+
* @param mitreidConnect13
64+
* @return
65+
*/
66+
boolean supportsVersion(String version);
67+
68+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*******************************************************************************
2+
* Copyright 2017 The MITRE Corporation
3+
* and the MIT Internet Trust Consortium
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*******************************************************************************/
17+
18+
package org.mitre.uma.service;
19+
20+
import java.util.Collection;
21+
22+
import org.mitre.oauth2.model.RegisteredClient;
23+
import org.mitre.uma.model.SavedRegisteredClient;
24+
25+
/**
26+
* @author jricher
27+
*
28+
*/
29+
public interface SavedRegisteredClientService {
30+
31+
/**
32+
* Get a list of all the registered clients that we know about.
33+
*
34+
* @return
35+
*/
36+
Collection<SavedRegisteredClient> getAll();
37+
38+
/**
39+
* @param issuer
40+
* @param client
41+
*/
42+
void save(String issuer, RegisteredClient client);
43+
44+
45+
}

openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/MITREidDataService_1_0.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
import java.io.IOException;
2020
import java.text.ParseException;
2121
import java.util.Collection;
22+
import java.util.Collections;
2223
import java.util.Date;
2324
import java.util.HashMap;
2425
import java.util.HashSet;
2526
import java.util.LinkedHashSet;
27+
import java.util.List;
2628
import java.util.Map;
2729
import java.util.Set;
2830

@@ -46,6 +48,7 @@
4648
import org.mitre.openid.connect.repository.BlacklistedSiteRepository;
4749
import org.mitre.openid.connect.repository.WhitelistedSiteRepository;
4850
import org.mitre.openid.connect.service.MITREidDataService;
51+
import org.mitre.openid.connect.service.MITREidDataServiceExtension;
4952
import org.slf4j.Logger;
5053
import org.slf4j.LoggerFactory;
5154
import org.springframework.beans.factory.annotation.Autowired;
@@ -96,6 +99,15 @@ public class MITREidDataService_1_0 extends MITREidDataServiceSupport implements
9699
private OAuth2TokenRepository tokenRepository;
97100
@Autowired
98101
private SystemScopeRepository sysScopeRepository;
102+
@Autowired(required = false)
103+
private List<MITREidDataServiceExtension> extensions = Collections.emptyList();
104+
105+
private static final String THIS_VERSION = MITREID_CONNECT_1_0;
106+
107+
@Override
108+
public boolean supportsVersion(String version) {
109+
return THIS_VERSION.equals(version);
110+
}
99111

100112
/* (non-Javadoc)
101113
* @see org.mitre.openid.connect.service.MITREidDataService#export(com.google.gson.stream.JsonWriter)
@@ -140,6 +152,14 @@ public void importData(JsonReader reader) throws IOException {
140152
} else if (name.equals(SYSTEMSCOPES)) {
141153
readSystemScopes(reader);
142154
} else {
155+
for (MITREidDataServiceExtension extension : extensions) {
156+
if (extension.supportsVersion(THIS_VERSION)) {
157+
if (extension.canImport(name)) {
158+
extension.importExtensionData(reader);
159+
break;
160+
}
161+
}
162+
}
143163
// unknown token, skip it
144164
reader.skipValue();
145165
}
@@ -154,6 +174,12 @@ public void importData(JsonReader reader) throws IOException {
154174
continue; }
155175
}
156176
fixObjectReferences();
177+
for (MITREidDataServiceExtension extension : extensions) {
178+
if (extension.supportsVersion(THIS_VERSION)) {
179+
extension.fixExtensionObjectReferences();
180+
break;
181+
}
182+
}
157183
}
158184
private Map<Long, String> refreshTokenToClientRefs = new HashMap<>();
159185
private Map<Long, Long> refreshTokenToAuthHolderRefs = new HashMap<>();

openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/MITREidDataService_1_1.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
import java.io.Serializable;
2121
import java.text.ParseException;
2222
import java.util.Collection;
23+
import java.util.Collections;
2324
import java.util.Date;
2425
import java.util.HashMap;
2526
import java.util.HashSet;
2627
import java.util.LinkedHashSet;
28+
import java.util.List;
2729
import java.util.Map;
2830
import java.util.Map.Entry;
2931
import java.util.Set;
@@ -48,6 +50,7 @@
4850
import org.mitre.openid.connect.repository.BlacklistedSiteRepository;
4951
import org.mitre.openid.connect.repository.WhitelistedSiteRepository;
5052
import org.mitre.openid.connect.service.MITREidDataService;
53+
import org.mitre.openid.connect.service.MITREidDataServiceExtension;
5154
import org.slf4j.Logger;
5255
import org.slf4j.LoggerFactory;
5356
import org.springframework.beans.factory.annotation.Autowired;
@@ -99,6 +102,15 @@ public class MITREidDataService_1_1 extends MITREidDataServiceSupport implements
99102
private OAuth2TokenRepository tokenRepository;
100103
@Autowired
101104
private SystemScopeRepository sysScopeRepository;
105+
@Autowired(required = false)
106+
private List<MITREidDataServiceExtension> extensions = Collections.emptyList();
107+
108+
private static final String THIS_VERSION = MITREID_CONNECT_1_1;
109+
110+
@Override
111+
public boolean supportsVersion(String version) {
112+
return THIS_VERSION.equals(version);
113+
}
102114

103115
/* (non-Javadoc)
104116
* @see org.mitre.openid.connect.service.MITREidDataService#export(com.google.gson.stream.JsonWriter)
@@ -142,6 +154,14 @@ public void importData(JsonReader reader) throws IOException {
142154
} else if (name.equals(SYSTEMSCOPES)) {
143155
readSystemScopes(reader);
144156
} else {
157+
for (MITREidDataServiceExtension extension : extensions) {
158+
if (extension.supportsVersion(THIS_VERSION)) {
159+
if (extension.canImport(name)) {
160+
extension.importExtensionData(reader);
161+
break;
162+
}
163+
}
164+
}
145165
// unknown token, skip it
146166
reader.skipValue();
147167
}
@@ -157,6 +177,12 @@ public void importData(JsonReader reader) throws IOException {
157177
}
158178
}
159179
fixObjectReferences();
180+
for (MITREidDataServiceExtension extension : extensions) {
181+
if (extension.supportsVersion(THIS_VERSION)) {
182+
extension.fixExtensionObjectReferences();
183+
break;
184+
}
185+
}
160186
}
161187
private Map<Long, String> refreshTokenToClientRefs = new HashMap<>();
162188
private Map<Long, Long> refreshTokenToAuthHolderRefs = new HashMap<>();

openid-connect-server/src/main/java/org/mitre/openid/connect/service/impl/MITREidDataService_1_2.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
import java.io.IOException;
2020
import java.io.Serializable;
2121
import java.text.ParseException;
22+
import java.util.Collections;
2223
import java.util.Date;
2324
import java.util.HashMap;
2425
import java.util.HashSet;
26+
import java.util.List;
2527
import java.util.Map;
2628
import java.util.Map.Entry;
2729
import java.util.Set;
@@ -46,6 +48,7 @@
4648
import org.mitre.openid.connect.repository.BlacklistedSiteRepository;
4749
import org.mitre.openid.connect.repository.WhitelistedSiteRepository;
4850
import org.mitre.openid.connect.service.MITREidDataService;
51+
import org.mitre.openid.connect.service.MITREidDataServiceExtension;
4952
import org.slf4j.Logger;
5053
import org.slf4j.LoggerFactory;
5154
import org.springframework.beans.factory.annotation.Autowired;
@@ -162,6 +165,15 @@ public class MITREidDataService_1_2 extends MITREidDataServiceSupport implements
162165
private OAuth2TokenRepository tokenRepository;
163166
@Autowired
164167
private SystemScopeRepository sysScopeRepository;
168+
@Autowired(required = false)
169+
private List<MITREidDataServiceExtension> extensions = Collections.emptyList();
170+
171+
private static final String THIS_VERSION = MITREID_CONNECT_1_2;
172+
173+
@Override
174+
public boolean supportsVersion(String version) {
175+
return THIS_VERSION.equals(version);
176+
}
165177

166178
/* (non-Javadoc)
167179
* @see org.mitre.openid.connect.service.MITREidDataService#export(com.google.gson.stream.JsonWriter)
@@ -206,6 +218,14 @@ public void importData(JsonReader reader) throws IOException {
206218
} else if (name.equals(SYSTEMSCOPES)) {
207219
readSystemScopes(reader);
208220
} else {
221+
for (MITREidDataServiceExtension extension : extensions) {
222+
if (extension.supportsVersion(THIS_VERSION)) {
223+
if (extension.canImport(name)) {
224+
extension.importExtensionData(reader);
225+
break;
226+
}
227+
}
228+
}
209229
// unknown token, skip it
210230
reader.skipValue();
211231
}
@@ -221,6 +241,12 @@ public void importData(JsonReader reader) throws IOException {
221241
}
222242
}
223243
fixObjectReferences();
244+
for (MITREidDataServiceExtension extension : extensions) {
245+
if (extension.supportsVersion(THIS_VERSION)) {
246+
extension.fixExtensionObjectReferences();
247+
break;
248+
}
249+
}
224250
}
225251
private Map<Long, String> refreshTokenToClientRefs = new HashMap<Long, String>();
226252
private Map<Long, Long> refreshTokenToAuthHolderRefs = new HashMap<Long, Long>();

0 commit comments

Comments
 (0)