Skip to content

Commit

Permalink
Move OAuth2 classes BaseClientDetails to UaaClientDetails (#2806)
Browse files Browse the repository at this point in the history
* Move to UaaBaseClientDetails

* Cleanup

* Cleanup

* Test cleanup flaky
because of parallel tests

* Use string compare instead of regex

* Rename main class

* Cleanup

* Tests moved into model

* Tests added, not used methods removed

* Tests fix

* Test coverage equals

* Sonar smells

* Sonar smells

* Sonar smells

* Sonar smells

* Added documentation about move of classes
  • Loading branch information
strehle authored Apr 11, 2024
1 parent a295d29 commit fc3f63c
Show file tree
Hide file tree
Showing 146 changed files with 1,871 additions and 1,074 deletions.
5 changes: 5 additions & 0 deletions model/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ dependencies {

implementation(libraries.slf4jApi)

testImplementation(libraries.springBootStarterTest)
testImplementation(libraries.hamcrest)
testImplementation(libraries.junit5JupiterApi)
testImplementation(libraries.junit5JupiterParams)

testImplementation(libraries.junit)

testImplementation(libraries.jsonAssert)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.cloudfoundry.identity.uaa.client;

import org.cloudfoundry.identity.uaa.provider.ClientAlreadyExistsException;
import org.cloudfoundry.identity.uaa.provider.ClientRegistrationException;
import org.cloudfoundry.identity.uaa.provider.NoSuchClientException;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
* Moved class InMemoryClientDetailsService implementation of from spring-security-oauth2 into UAA
*
* The class was taken over from the legacy project with minor refactorings
* based on sonar.
*
* Serves mainly for tests
*/
public class InMemoryClientDetailsService implements ClientDetailsService {

private Map<String, UaaClientDetails> clientDetailsStore = new HashMap<>();

public UaaClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
UaaClientDetails details = clientDetailsStore.get(clientId);
if (details == null) {
throw new NoSuchClientException("No client with requested id");
}
return details;
}

protected void addClientDetails(ClientDetails clientDetails) throws ClientAlreadyExistsException {
String clientId = Optional.ofNullable(clientDetails).orElseThrow(() -> new ClientRegistrationException("No details")).getClientId();
UaaClientDetails details = clientDetailsStore.get(clientId);
if (details != null) {
throw new ClientAlreadyExistsException("Client with this id exists aleady");
}
clientDetailsStore.put(clientId, new UaaClientDetails(clientDetails));
}

public void setClientDetailsStore(Map<String, ? extends UaaClientDetails> clientDetailsStore) {
this.clientDetailsStore = new HashMap<>(clientDetailsStore);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.cloudfoundry.identity.uaa.client;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.type.SimpleType;
import org.springframework.util.StringUtils;

import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;

/**
* Moved class Jackson2ArrayOrStringDeserializer implementation of from spring-security-oauth2 into UAA
*
* The class was taken over from the legacy project with minor refactorings
* based on sonar.
*
*/
@SuppressWarnings("serial")
public class Jackson2ArrayOrStringDeserializer extends StdDeserializer<Set<String>> {

public Jackson2ArrayOrStringDeserializer() {
super(Set.class);
}

@Override
public JavaType getValueType() {
return SimpleType.construct(String.class);
}

@Override
public Set<String> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
JsonToken token = jp.getCurrentToken();
if (token.isScalarValue()) {
String list = jp.getText();
list = list.replaceAll("\\s+", ",");
return new LinkedHashSet<>(Arrays.asList(StringUtils.commaDelimitedListToStringArray(list)));
}
return jp.readValueAs(new TypeReference<Set<String>>() {
});
}
}
Loading

0 comments on commit fc3f63c

Please sign in to comment.