Skip to content

Commit 3773a7d

Browse files
Remove Scope.java and use String instead. (#2541)
1 parent 2c1a58c commit 3773a7d

4 files changed

Lines changed: 6 additions & 47 deletions

File tree

core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/inConfig/Key.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@
2626
@MCElement(name = "secret", component = false)
2727
public class Key {
2828

29-
private final List<Scope> scopes = new ArrayList<>();
29+
private final List<String> scopes = new ArrayList<>();
3030

3131
private String value;
3232

3333
/**
34-
* @description <scope>...</scope> elements for defining scopes for this key.
34+
* @description Scopes for this key.
3535
*/
3636
@MCChildElement(allowForeign = true)
37-
public void setScopes(List<Scope> scopes) {
37+
public void setScopes(List<String> scopes) {
3838
this.scopes.addAll(scopes);
3939
}
4040

41-
public List<Scope> getScopes() {
41+
public List<String> getScopes() {
4242
return scopes;
4343
}
4444

core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/inConfig/Scope.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/inConfig/SimpleKeyStore.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ public List<Key> getKeys() {
4545
public Optional<Set<String>> getScopes(String apiKey) throws UnauthorizedApiKeyException {
4646
var key = keys.stream().filter(k -> k.getValue().equals(apiKey)).findFirst();
4747
if (key.isPresent()) {
48-
Set<String> scopeValues = key.get().getScopes().stream()
49-
.map(Scope::getValue)
50-
.collect(toSet());
48+
Set<String> scopeValues = new HashSet<>(key.get().getScopes());
5149
return ofNullable(scopeValues.isEmpty() ? null : scopeValues);
5250
} else {
5351
throw new UnauthorizedApiKeyException();

core/src/test/java/com/predic8/membrane/core/interceptor/apikey/stores/inConfig/SimpleKeyStoreTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ void getScopes() throws UnauthorizedApiKeyException {
3232
new Key(){{setValue("12345");}},
3333
new Key(){{
3434
setValue("67890");
35-
setScopes(of(
36-
new Scope(){{setValue("admin");}},
37-
new Scope(){{setValue("user");}})
38-
);
35+
setScopes(of("admin", "user"));
3936
}})
4037
);
4138
assertEquals(empty(), simpleKeyStore.getScopes("12345"));

0 commit comments

Comments
 (0)