Skip to content

Commit

Permalink
Merge d9aede1 into 12f9820
Browse files Browse the repository at this point in the history
  • Loading branch information
dickschoeller committed May 7, 2019
2 parents 12f9820 + d9aede1 commit 2df4785
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -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<UserRoleName> 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);
}

}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -32,9 +23,6 @@ public final class UserImpl implements User {
/** */
private String password;

/** */
private final Set<UserRoleName> roles = new HashSet<>();

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 2df4785

Please sign in to comment.