summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/security/AuthorizationConfiguration.java40
-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);