diff options
author | Thomas <> | 2023-05-11 12:34:27 +0200 |
---|---|---|
committer | Thomas <> | 2023-05-11 12:34:27 +0200 |
commit | 13da938658e0f799a7c89faadcfbbfee95a220d8 (patch) | |
tree | bbe38aa00660f760e3d7c19b756f790e1f673e30 /eaaf-springboot-utils/src | |
parent | 342ec1478cb6f15deb1f359d429f521bac5f04c8 (diff) | |
download | EAAF-Components-13da938658e0f799a7c89faadcfbbfee95a220d8.tar.gz EAAF-Components-13da938658e0f799a7c89faadcfbbfee95a220d8.tar.bz2 EAAF-Components-13da938658e0f799a7c89faadcfbbfee95a220d8.zip |
feat(spring): add authorisation configuration for multi-modul projects
Diffstat (limited to 'eaaf-springboot-utils/src')
-rw-r--r-- | eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/security/AuthorizationConfiguration.java | 40 | ||||
-rw-r--r-- | eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/security/IBasicAuthSecurityCollector.java (renamed from eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/security/IBasicAuthUserCollector.java) | 10 | ||||
-rw-r--r-- | eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/utils/BasicSecurityConfigTest.java (renamed from eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/utils/BasicAuthUserTest.java) | 15 |
3 files changed, 62 insertions, 3 deletions
diff --git a/eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/security/AuthorizationConfiguration.java b/eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/security/AuthorizationConfiguration.java new file mode 100644 index 00000000..b62d4761 --- /dev/null +++ b/eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/security/AuthorizationConfiguration.java @@ -0,0 +1,40 @@ +package at.gv.egiz.eaaf.utils.springboot.security; + +import java.util.List; + +import lombok.Builder; +import lombok.Getter; +import lombok.Singular; + +/** + * Configuration holder for Spring Security end-point authorization. + * + * @author tlenz + * + */ +@Builder +@Getter +public class AuthorizationConfiguration { + + /** + * Role String that is required for that end-points. + */ + private final String role; + + /** + * List of end-points. + */ + @Singular + private List<String> endpoints; + + /** + * List of end-points as Java Array. + * + * @return end-points. + */ + public String[] getEndPointsArray() { + return endpoints.stream().toArray(String[]::new); + + } + +} diff --git a/eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/security/IBasicAuthUserCollector.java b/eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/security/IBasicAuthSecurityCollector.java index 1986d52b..2bf65af7 100644 --- a/eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/security/IBasicAuthUserCollector.java +++ b/eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/security/IBasicAuthSecurityCollector.java @@ -11,7 +11,7 @@ import javax.annotation.Nonnull; * @author tlenz * */ -public interface IBasicAuthUserCollector { +public interface IBasicAuthSecurityCollector { /** * Get all users that shall be added for Spring Security Basic-Auth. @@ -21,4 +21,12 @@ public interface IBasicAuthUserCollector { @Nonnull List<BasicAuthUser> getEnabledUsers(); + /** + * Get end-point security configuration for Spring Security antMatchers. + * + * @return List of end-point security configuration-elements + */ + @Nonnull + List<AuthorizationConfiguration> getAntMatchersConfiguration(); + } diff --git a/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/utils/BasicAuthUserTest.java b/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/utils/BasicSecurityConfigTest.java index 95bd5dcb..83117253 100644 --- a/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/utils/BasicAuthUserTest.java +++ b/eaaf-springboot-utils/src/test/java/at/gv/egiz/eaaf/utils/springboot/test/utils/BasicSecurityConfigTest.java @@ -9,13 +9,14 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.BlockJUnit4ClassRunner; +import at.gv.egiz.eaaf.utils.springboot.security.AuthorizationConfiguration; import at.gv.egiz.eaaf.utils.springboot.security.BasicAuthUser; @RunWith(BlockJUnit4ClassRunner.class) -public class BasicAuthUserTest { +public class BasicSecurityConfigTest { @Test - public void simpleTest() { + public void userConfig() { assertFalse("username", BasicAuthUser.builder().password(rand()).role(rand()).build().isValid()); assertFalse("password", @@ -33,6 +34,16 @@ public class BasicAuthUserTest { } + @Test + public void authoriseConfig() { + + assertEquals("endpoint size", 2, + AuthorizationConfiguration.builder().role(rand()) + .endpoint(rand()).endpoint(rand()).build() + .getEndPointsArray().length); + + } + private String rand() { return RandomStringUtils.randomAlphanumeric(5); |