-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40428 from nderwin-forks/feature/test-security-at…
…tribute-values Add test security attribute type handling
- Loading branch information
Showing
6 changed files
with
144 additions
and
1 deletion.
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
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
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
69 changes: 69 additions & 0 deletions
69
test-framework/security/src/main/java/io/quarkus/test/security/AttributeType.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,69 @@ | ||
package io.quarkus.test.security; | ||
|
||
import java.io.StringReader; | ||
import java.util.Set; | ||
|
||
import jakarta.json.Json; | ||
import jakarta.json.JsonReader; | ||
|
||
public enum AttributeType { | ||
LONG { | ||
@Override | ||
Object convert(String value) { | ||
return Long.valueOf(value); | ||
} | ||
}, | ||
INTEGER { | ||
@Override | ||
Object convert(String value) { | ||
return Integer.valueOf(value); | ||
} | ||
}, | ||
BOOLEAN { | ||
@Override | ||
Object convert(String value) { | ||
return Boolean.valueOf(value); | ||
} | ||
}, | ||
STRING { | ||
@Override | ||
Object convert(String value) { | ||
return value; | ||
} | ||
}, | ||
STRING_SET { | ||
/** | ||
* Returns a Set of String values, parsed from the given value. | ||
* | ||
* @param value a comma separated list of values | ||
*/ | ||
@Override | ||
Object convert(String value) { | ||
return Set.of(value.split(",")); | ||
} | ||
}, | ||
JSON_ARRAY { | ||
@Override | ||
Object convert(String value) { | ||
try (JsonReader reader = Json.createReader(new StringReader(value))) { | ||
return reader.readArray(); | ||
} | ||
} | ||
}, | ||
JSON_OBJECT { | ||
@Override | ||
Object convert(String value) { | ||
try (JsonReader reader = Json.createReader(new StringReader(value))) { | ||
return reader.readObject(); | ||
} | ||
} | ||
}, | ||
DEFAULT { | ||
@Override | ||
Object convert(String value) { | ||
return value; | ||
} | ||
}; | ||
|
||
abstract Object convert(String value); | ||
} |
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
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 |
---|---|---|
|
@@ -10,4 +10,6 @@ | |
String key(); | ||
|
||
String value(); | ||
|
||
AttributeType type() default AttributeType.DEFAULT; | ||
} |