Commit e090c517 authored by Matija Obreza's avatar Matija Obreza
Browse files

OAuthClient management

- Load OAuthClient#roles list
- Expose grantTypes, redirectUris, scopes
- OAuthClient#apply only copies simple properties, lists and sets must be done manually.
- On update, flatten() was not executed
parent 4d7f9d54
......@@ -33,6 +33,7 @@ import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.PostLoad;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Table;
import javax.persistence.Transient;
......@@ -60,7 +61,7 @@ public class OAuthClient extends AuditedVersionedModel implements ClientDetails,
/** The client id. */
@JsonView(JsonViews.Public.class)
@Column(unique = true, nullable = false, length = 100)
@Column(unique = true, nullable = false, updatable = false, length = 100)
private String clientId;
/** The client secret. */
......@@ -152,6 +153,7 @@ public class OAuthClient extends AuditedVersionedModel implements ClientDetails,
* Flatten.
*/
@PrePersist
@PreUpdate
private void flatten() {
resource = resourceIds.stream().collect(Collectors.joining(";"));
scope = scopes.stream().collect(Collectors.joining(";"));
......@@ -536,4 +538,29 @@ public class OAuthClient extends AuditedVersionedModel implements ClientDetails,
// Unsupported
return null;
}
@Override
public OAuthClient apply(OAuthClient source) {
Copyable.super.apply(source);
this.autoApproveScopes.clear();
this.autoApproveScopes.addAll(source.autoApproveScopes);
this.grantTypes.clear();
this.grantTypes.addAll(source.grantTypes);
this.redirectUris.clear();
this.redirectUris.addAll(source.redirectUris);
this.resourceIds.clear();
this.resourceIds.addAll(source.resourceIds);
this.roles.clear();
this.roles.addAll(source.roles);
this.scopes.clear();
this.scopes.addAll(source.scopes);
return this;
}
}
......@@ -107,7 +107,13 @@ public class OAuthServiceImpl implements OAuthClientDetailsService, OAuthTokenSt
if (client == null) {
throw new NoSuchClientException(clientId);
}
client.getRoles().size();
return lazyLoad(client);
}
private OAuthClient lazyLoad(OAuthClient client) {
if (client != null) {
client.getRoles().size();
}
return client;
}
......@@ -584,7 +590,10 @@ public class OAuthServiceImpl implements OAuthClientDetailsService, OAuthTokenSt
*/
@Override
public OAuthClient getClient(final String clientId) {
return oauthClientRepository.findByClientId(clientId);
OAuthClient client = oauthClientRepository.findByClientId(clientId);
if (client != null)
client.getRoles().size();
return client;
}
/*
......@@ -639,9 +648,9 @@ public class OAuthServiceImpl implements OAuthClientDetailsService, OAuthTokenSt
@Override
@Transactional
public OAuthClient updateClient(final long id, final int version, final OAuthClient updates) {
final OAuthClient client = oauthClientRepository.findByIdAndVersion(id, version);
OAuthClient client = oauthClientRepository.findByIdAndVersion(id, version);
client.apply(updates);
return oauthClientRepository.save(client);
return lazyLoad(oauthClientRepository.save(client));
}
@Override
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment