Skip to content

Commit 064f36e

Browse files
committed
clean up resource sets when clients are deleted
1 parent f6c20ad commit 064f36e

File tree

9 files changed

+49
-2
lines changed

9 files changed

+49
-2
lines changed

openid-connect-common/src/main/java/org/mitre/uma/model/ResourceSet.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@
4141
@NamedQueries ({
4242
@NamedQuery(name = ResourceSet.QUERY_BY_OWNER, query = "select r from ResourceSet r where r.owner = :" + ResourceSet.PARAM_OWNER),
4343
@NamedQuery(name = ResourceSet.QUERY_BY_OWNER_AND_CLIENT, query = "select r from ResourceSet r where r.owner = :" + ResourceSet.PARAM_OWNER + " and r.clientId = :" + ResourceSet.PARAM_CLIENTID),
44+
@NamedQuery(name = ResourceSet.QUERY_BY_CLIENT, query = "select r from ResourceSet r where r.clientId = :" + ResourceSet.PARAM_CLIENTID),
4445
@NamedQuery(name = ResourceSet.QUERY_ALL, query = "select r from ResourceSet r")
4546
})
4647
public class ResourceSet {
4748

4849
public static final String QUERY_BY_OWNER = "ResourceSet.queryByOwner";
4950
public static final String QUERY_BY_OWNER_AND_CLIENT = "ResourceSet.queryByOwnerAndClient";
51+
public static final String QUERY_BY_CLIENT = "ResourceSet.queryByClient";
5052
public static final String QUERY_ALL = "ResourceSet.queryAll";
5153

5254
public static final String PARAM_OWNER = "owner";

openid-connect-common/src/main/java/org/mitre/uma/repository/ResourceSetRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ public interface ResourceSetRepository {
3939

4040
public Collection<ResourceSet> getAll();
4141

42+
public Collection<ResourceSet> getAllForClient(String clientId);
43+
4244
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.util.Collection;
2020

21+
import org.mitre.oauth2.model.ClientDetailsEntity;
2122
import org.mitre.uma.model.ResourceSet;
2223

2324
/**
@@ -41,4 +42,6 @@ public interface ResourceSetService {
4142

4243
public Collection<ResourceSet> getAllForOwnerAndClient(String owner, String authClientId);
4344

45+
public Collection<ResourceSet> getAllForClient(ClientDetailsEntity client);
46+
4447
}

openid-connect-server-webapp/src/main/webapp/WEB-INF/data-context.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
<!-- The following files are for safely bootstrapping users and clients into the database -->
3939
<jdbc:script location="classpath:/db/tables/loading_temp_tables.sql"/>
4040
<jdbc:script location="classpath:/db/users.sql"/>
41-
<jdbc:script location="classpath:/db/clients.sql"/>
42-
<jdbc:script location="classpath:/db/scopes.sql"/>
41+
<!-- <jdbc:script location="classpath:/db/clients.sql"/> -->
42+
<!-- <jdbc:script location="classpath:/db/scopes.sql"/> -->
4343
</jdbc:initialize-database>
4444

4545
<bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
import org.mitre.openid.connect.service.BlacklistedSiteService;
4343
import org.mitre.openid.connect.service.StatsService;
4444
import org.mitre.openid.connect.service.WhitelistedSiteService;
45+
import org.mitre.uma.model.ResourceSet;
46+
import org.mitre.uma.service.ResourceSetService;
4547
import org.slf4j.Logger;
4648
import org.slf4j.LoggerFactory;
4749
import org.springframework.beans.factory.annotation.Autowired;
@@ -88,6 +90,9 @@ public class DefaultOAuth2ClientDetailsEntityService implements ClientDetailsEnt
8890
@Autowired
8991
private StatsService statsService;
9092

93+
@Autowired
94+
private ResourceSetService resourceSetService;
95+
9196
@Autowired
9297
private ConfigurationPropertiesBean config;
9398

@@ -235,6 +240,12 @@ public void deleteClient(ClientDetailsEntity client) throws InvalidClientExcepti
235240
if (whitelistedSite != null) {
236241
whitelistedSiteService.remove(whitelistedSite);
237242
}
243+
244+
// clear out resource sets registered for this client
245+
Collection<ResourceSet> resourceSets = resourceSetService.getAllForClient(client);
246+
for (ResourceSet rs : resourceSets) {
247+
resourceSetService.remove(rs);
248+
}
238249

239250
// take care of the client itself
240251
clientRepository.deleteClient(client);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Collection;
2121
import java.util.Collections;
2222

23+
import org.mitre.oauth2.model.ClientDetailsEntity;
2324
import org.mitre.uma.model.ResourceSet;
2425
import org.mitre.uma.service.ResourceSetService;
2526
import org.springframework.stereotype.Service;
@@ -64,4 +65,9 @@ public Collection<ResourceSet> getAllForOwnerAndClient(String owner, String auth
6465
return Collections.emptySet();
6566
}
6667

68+
@Override
69+
public Collection<ResourceSet> getAllForClient(ClientDetailsEntity client) {
70+
return Collections.emptySet();
71+
}
72+
6773
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,9 @@ private void readPermissionTickets(JsonReader reader) throws IOException {
885885
reader.endObject();
886886
Permission saved = permissionRepository.saveRawPermission(p);
887887
permissionToResourceRefs.put(saved.getId(), rsid);
888+
ticket.setPermission(saved);
888889
} else if (name.equals(TICKET)) {
890+
ticket.setTicket(reader.nextString());
889891
} else {
890892
logger.debug("Found unexpected entry");
891893
reader.skipValue();
@@ -1225,6 +1227,7 @@ private void readAccessTokens(JsonReader reader) throws IOException {
12251227
continue;
12261228
}
12271229
}
1230+
reader.endObject();
12281231
p.setScopes(scope);
12291232
Permission saved = permissionRepository.saveRawPermission(p);
12301233
permissionToResourceRefs.put(saved.getId(), rsid);
@@ -1807,6 +1810,7 @@ private void fixObjectReferences() {
18071810
ResourceSet rs = resourceSetRepository.getById(newResourceId);
18081811
p.setResourceSet(rs);
18091812
permissionRepository.saveRawPermission(p);
1813+
logger.debug("Mapping rsid " + oldResourceId + " to " + newResourceId + " for permission " + permissionId);
18101814
}
18111815
permissionToResourceRefs.clear();
18121816
resourceSetOldToNewIdMap.clear();

uma-server/src/main/java/org/mitre/uma/repository/impl/JpaResourceSetRepository.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,14 @@ public Collection<ResourceSet> getAll() {
8585
return query.getResultList();
8686
}
8787

88+
/* (non-Javadoc)
89+
* @see org.mitre.uma.repository.ResourceSetRepository#getAllForClient(org.mitre.oauth2.model.ClientDetailsEntity)
90+
*/
91+
@Override
92+
public Collection<ResourceSet> getAllForClient(String clientId) {
93+
TypedQuery<ResourceSet> query = em.createNamedQuery(ResourceSet.QUERY_BY_CLIENT, ResourceSet.class);
94+
query.setParameter(ResourceSet.PARAM_CLIENTID, clientId);
95+
return query.getResultList();
96+
}
97+
8898
}

uma-server/src/main/java/org/mitre/uma/service/impl/DefaultResourceSetService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.util.Collection;
2121

22+
import org.mitre.oauth2.model.ClientDetailsEntity;
2223
import org.mitre.oauth2.model.OAuth2AccessTokenEntity;
2324
import org.mitre.oauth2.repository.OAuth2TokenRepository;
2425
import org.mitre.uma.model.PermissionTicket;
@@ -137,5 +138,13 @@ private boolean checkScopeConsistency(ResourceSet rs) {
137138
// we've checked everything, we're good
138139
return true;
139140
}
141+
142+
/* (non-Javadoc)
143+
* @see org.mitre.uma.service.ResourceSetService#getAllForClient(org.mitre.oauth2.model.ClientDetailsEntity)
144+
*/
145+
@Override
146+
public Collection<ResourceSet> getAllForClient(ClientDetailsEntity client) {
147+
return repository.getAllForClient(client.getClientId());
148+
}
140149

141150
}

0 commit comments

Comments
 (0)