diff --git a/gedbrowser-renderer/src/main/java/org/schoellerfamily/gedbrowser/renderer/user/HasRoles.java b/gedbrowser-renderer/src/main/java/org/schoellerfamily/gedbrowser/renderer/user/HasRoles.java new file mode 100644 index 00000000..1ffae431 --- /dev/null +++ b/gedbrowser-renderer/src/main/java/org/schoellerfamily/gedbrowser/renderer/user/HasRoles.java @@ -0,0 +1,70 @@ +package org.schoellerfamily.gedbrowser.renderer.user; + +import java.util.HashSet; +import java.util.Set; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.schoellerfamily.gedbrowser.datamodel.users.UserRoleName; + +/** + * @author Dick Schoeller + */ +public class HasRoles { + /** Logger. */ + private final transient Log logger = LogFactory.getLog(getClass()); + + /** */ + private final Set roles = new HashSet<>(); + + /** + * {@inheritDoc} + */ + @SuppressWarnings({ "PMD.OptimizableToArrayCall" }) + public UserRoleName[] getRoles() { + return roles.toArray(new UserRoleName[0]); + } + + /** + * @param role the role to add to the role set + */ + public void addRole(final UserRoleName role) { + roles.add(role); + } + + /** + * {@inheritDoc} + */ + public void addRole(final String role) { + try { + roles.add(UserRoleName.valueOf(role)); + } catch (Exception e) { + logger.warn("Tried to add unrecognized role: " + role); + } + } + + /** + * Clear the role set. + */ + public void clearRoles() { + roles.clear(); + } + + /** + * Check if the user has a particular role. + * + * @param role role that we are looking for + * @return true if the user has the role + */ + public boolean hasRole(final String role) { + return roles.contains(UserRoleName.valueOf(role)); + } + + /** + * {@inheritDoc} + */ + public boolean hasRole(final UserRoleName role) { + return roles.contains(role); + } + +} diff --git a/gedbrowser-renderer/src/main/java/org/schoellerfamily/gedbrowser/renderer/user/UserImpl.java b/gedbrowser-renderer/src/main/java/org/schoellerfamily/gedbrowser/renderer/user/UserImpl.java index 0687a0b4..b1e1d978 100644 --- a/gedbrowser-renderer/src/main/java/org/schoellerfamily/gedbrowser/renderer/user/UserImpl.java +++ b/gedbrowser-renderer/src/main/java/org/schoellerfamily/gedbrowser/renderer/user/UserImpl.java @@ -1,22 +1,13 @@ package org.schoellerfamily.gedbrowser.renderer.user; -import java.util.HashSet; -import java.util.Set; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.schoellerfamily.gedbrowser.datamodel.users.User; -import org.schoellerfamily.gedbrowser.datamodel.users.UserRoleName; /** * A basic user record. * * @author Dick Schoeller */ -public final class UserImpl implements User { - /** Logger. */ - private final transient Log logger = LogFactory.getLog(getClass()); - +public final class UserImpl extends HasRoles implements User { /** */ private String username; @@ -32,9 +23,6 @@ public final class UserImpl implements User { /** */ private String password; - /** */ - private final Set roles = new HashSet<>(); - /** * {@inheritDoc} */ @@ -114,57 +102,4 @@ public String getPassword() { public void setPassword(final String password) { this.password = password; } - - /** - * {@inheritDoc} - */ - @Override - @SuppressWarnings({ "PMD.OptimizableToArrayCall" }) - public UserRoleName[] getRoles() { - return roles.toArray(new UserRoleName[0]); - } - - /** - * @param role the role to add to the role set - */ - public void addRole(final UserRoleName role) { - roles.add(role); - } - - /** - * {@inheritDoc} - */ - @Override - public void addRole(final String role) { - try { - roles.add(UserRoleName.valueOf(role)); - } catch (Exception e) { - logger.warn("Tried to add unrecognized role: " + role); - } - } - - /** - * Clear the role set. - */ - public void clearRoles() { - roles.clear(); - } - - /** - * Check if the user has a particular role. - * - * @param role role that we are looking for - * @return true if the user has the role - */ - public boolean hasRole(final String role) { - return roles.contains(UserRoleName.valueOf(role)); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean hasRole(final UserRoleName role) { - return roles.contains(role); - } }