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 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/security/BasicAuthUser.java (limited to 'eaaf-springboot-utils/src/main/java/at/gv/egiz/eaaf/utils/springboot/security/BasicAuthUser.java') 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(); + + } + +} -- cgit v1.2.3