-
Notifications
You must be signed in to change notification settings - Fork 827
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move OAuth2 classes BaseClientDetails to UaaClientDetails (#2806)
* 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
Showing
146 changed files
with
1,871 additions
and
1,074 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
model/src/main/java/org/cloudfoundry/identity/uaa/client/InMemoryClientDetailsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
...src/main/java/org/cloudfoundry/identity/uaa/client/Jackson2ArrayOrStringDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>>() { | ||
}); | ||
} | ||
} |
Oops, something went wrong.