From 121ab60782e2728543ca2f455c656040cbd340a1 Mon Sep 17 00:00:00 2001 From: Thomas <> Date: Wed, 10 May 2023 16:39:14 +0200 Subject: feat(spring): add BasicAuth user object and new Interface to load users in multi-module projects --- .../utils/springboot/security/BasicAuthUser.java | 56 ++++++++++++++++++++++ .../security/IBasicAuthUserCollector.java | 24 ++++++++++ 2 files changed, 80 insertions(+) create mode 100644 eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/security/BasicAuthUser.java create mode 100644 eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/security/IBasicAuthUserCollector.java (limited to 'eaaf-springboot-utils/src/main/java/at/gv') diff --git a/eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/security/BasicAuthUser.java b/eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/security/BasicAuthUser.java new file mode 100644 index 00000000..7644c7ce --- /dev/null +++ b/eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/security/BasicAuthUser.java @@ -0,0 +1,56 @@ +package at.gv.egiz.eaaf.utils.springboot.security; + +import java.util.List; + +import org.apache.commons.lang3.StringUtils; + +import lombok.Builder; +import lombok.Getter; +import lombok.Singular; + +/** + * Simple user configuration object. + * + * @author tlenz + * + */ +@Builder +@Getter +public class BasicAuthUser { + + /** + * Username of an entity. + */ + private final String username; + + /** + * Password of an entity. + */ + private final String password; + + /** + * Roles of an entity. + */ + @Singular + private List roles; + + /** + * Get roles as Array. + * + * @return Array of roles + */ + public String[] getRolesArray() { + return roles.stream().toArray(String[]::new); + } + + /** + * Check if username, password are not blank and roles is not empty. + * + * @return true if it looks like a valid user + */ + public boolean isValid() { + return StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password) && !roles.isEmpty(); + + } + +} 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/IBasicAuthUserCollector.java new file mode 100644 index 00000000..1986d52b --- /dev/null +++ b/eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/security/IBasicAuthUserCollector.java @@ -0,0 +1,24 @@ +package at.gv.egiz.eaaf.utils.springboot.security; + +import java.util.List; + +import javax.annotation.Nonnull; + +/** + * Extension interface to collect Spring Security Basic Auth. users in + * multi-module projects. + * + * @author tlenz + * + */ +public interface IBasicAuthUserCollector { + + /** + * Get all users that shall be added for Spring Security Basic-Auth. + * + * @return + */ + @Nonnull + List getEnabledUsers(); + +} -- cgit v1.2.3