diff options
author | Thomas <> | 2023-05-10 16:39:14 +0200 |
---|---|---|
committer | Thomas <> | 2023-05-10 16:39:14 +0200 |
commit | 121ab60782e2728543ca2f455c656040cbd340a1 (patch) | |
tree | c33657aff59c3b7a465387c339112ae99d8e36c7 /eaaf-springboot-utils/src/main | |
parent | aedac2d9232b605295981dee88236c0f56e339d1 (diff) | |
download | EAAF-Components-121ab60782e2728543ca2f455c656040cbd340a1.tar.gz EAAF-Components-121ab60782e2728543ca2f455c656040cbd340a1.tar.bz2 EAAF-Components-121ab60782e2728543ca2f455c656040cbd340a1.zip |
feat(spring): add BasicAuth user object and new Interface to load users in multi-module projects
Diffstat (limited to 'eaaf-springboot-utils/src/main')
2 files changed, 80 insertions, 0 deletions
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<String> 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 <code>true</code> 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<BasicAuthUser> getEnabledUsers(); + +} |