[Minor] wrote some java docs
This commit is contained in:
parent
a3e2515f38
commit
6c5b266f67
|
@ -11,6 +11,7 @@
|
|||
package ch.eitchnet.privilege.handler;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Map;
|
||||
|
@ -22,13 +23,34 @@ import ch.eitchnet.privilege.helper.XmlConstants;
|
|||
import ch.eitchnet.privilege.i18n.PrivilegeException;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This default {@link EncryptionHandler} creates nokens by using a {@link SecureRandom} object. Hashing is done by
|
||||
* using {@link MessageDigest} and the configured algorithm which is passed in the parameters
|
||||
* </p>
|
||||
*
|
||||
* Required parameters:
|
||||
* <ul>
|
||||
* <li> {@link XmlConstants#XML_PARAM_HASH_ALGORITHM}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author rvonburg
|
||||
*
|
||||
*/
|
||||
public class DefaultEncryptionHandler implements EncryptionHandler {
|
||||
|
||||
/**
|
||||
* The log4j logger used in this instance
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger(DefaultEncryptionHandler.class);
|
||||
|
||||
/**
|
||||
* The {@link SecureRandom} which is used to create new tokens
|
||||
*/
|
||||
private SecureRandom secureRandom;
|
||||
|
||||
/**
|
||||
* The configured hash algorithm for this instance
|
||||
*/
|
||||
private String hashAlgorithm;
|
||||
|
||||
/**
|
||||
|
|
|
@ -151,8 +151,8 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
|||
}
|
||||
|
||||
// create new user
|
||||
User user = new User(userRep.getUsername(), passwordHash, userRep.getFirstname(), userRep.getSurname(), userRep
|
||||
.getUserState(), userRep.getRoles(), userRep.getLocale());
|
||||
User user = new User(userRep.getUserId(), userRep.getUsername(), passwordHash, userRep.getFirstname(), userRep
|
||||
.getSurname(), userRep.getUserState(), userRep.getRoles(), userRep.getLocale());
|
||||
|
||||
// delegate to persistence handler
|
||||
this.persistenceHandler.addOrReplaceUser(user);
|
||||
|
@ -229,8 +229,8 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
|||
Set<String> newRoles = new HashSet<String>(currentRoles);
|
||||
newRoles.add(roleName);
|
||||
|
||||
User newUser = new User(user.getUsername(), user.getPassword(), user.getFirstname(), user.getSurname(), user
|
||||
.getState(), newRoles, user.getLocale());
|
||||
User newUser = new User(user.getUserId(), user.getUsername(), user.getPassword(), user.getFirstname(), user
|
||||
.getSurname(), user.getUserState(), newRoles, user.getLocale());
|
||||
|
||||
// delegate user replacement to persistence handler
|
||||
this.persistenceHandler.addOrReplaceUser(newUser);
|
||||
|
@ -334,8 +334,8 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
|||
// create new user
|
||||
Set<String> newRoles = new HashSet<String>(currentRoles);
|
||||
newRoles.remove(roleName);
|
||||
User newUser = new User(user.getUsername(), user.getPassword(), user.getFirstname(), user.getSurname(), user
|
||||
.getState(), newRoles, user.getLocale());
|
||||
User newUser = new User(user.getUserId(), user.getUsername(), user.getPassword(), user.getFirstname(), user
|
||||
.getSurname(), user.getUserState(), newRoles, user.getLocale());
|
||||
|
||||
// delegate user replacement to persistence handler
|
||||
this.persistenceHandler.addOrReplaceUser(newUser);
|
||||
|
@ -483,8 +483,8 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
|||
}
|
||||
|
||||
// create new user
|
||||
User newUser = new User(user.getUsername(), user.getPassword(), user.getFirstname(), user.getSurname(), user
|
||||
.getState(), user.getRoles(), locale);
|
||||
User newUser = new User(user.getUserId(), user.getUsername(), user.getPassword(), user.getFirstname(), user
|
||||
.getSurname(), user.getUserState(), user.getRoles(), locale);
|
||||
|
||||
// delegate user replacement to persistence handler
|
||||
this.persistenceHandler.addOrReplaceUser(newUser);
|
||||
|
@ -507,8 +507,8 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
|||
}
|
||||
|
||||
// create new user
|
||||
User newUser = new User(user.getUsername(), user.getPassword(), firstname, surname, user.getState(), user
|
||||
.getRoles(), user.getLocale());
|
||||
User newUser = new User(user.getUserId(), user.getUsername(), user.getPassword(), firstname, surname, user
|
||||
.getUserState(), user.getRoles(), user.getLocale());
|
||||
|
||||
// delegate user replacement to persistence handler
|
||||
this.persistenceHandler.addOrReplaceUser(newUser);
|
||||
|
@ -541,8 +541,8 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
|||
}
|
||||
|
||||
// create new user
|
||||
User newUser = new User(user.getUsername(), passwordHash, user.getFirstname(), user.getSurname(), user
|
||||
.getState(), user.getRoles(), user.getLocale());
|
||||
User newUser = new User(user.getUserId(), user.getUsername(), passwordHash, user.getFirstname(), user
|
||||
.getSurname(), user.getUserState(), user.getRoles(), user.getLocale());
|
||||
|
||||
// delegate user replacement to persistence handler
|
||||
this.persistenceHandler.addOrReplaceUser(newUser);
|
||||
|
@ -565,8 +565,8 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
|||
}
|
||||
|
||||
// create new user
|
||||
User newUser = new User(user.getUsername(), user.getPassword(), user.getFirstname(), user.getSurname(), state,
|
||||
user.getRoles(), user.getLocale());
|
||||
User newUser = new User(user.getUserId(), user.getUsername(), user.getPassword(), user.getFirstname(), user
|
||||
.getSurname(), state, user.getRoles(), user.getLocale());
|
||||
|
||||
// delegate user replacement to persistence handler
|
||||
this.persistenceHandler.addOrReplaceUser(newUser);
|
||||
|
@ -604,8 +604,8 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
|||
throw new AccessDeniedException("Password is incorrect for " + username + " / ***...");
|
||||
|
||||
// validate if user is allowed to login
|
||||
if (user.getState() != UserState.ENABLED)
|
||||
throw new AccessDeniedException("User " + username + " is not ENABLED. State is: " + user.getState());
|
||||
if (user.getUserState() != UserState.ENABLED)
|
||||
throw new AccessDeniedException("User " + username + " is not ENABLED. State is: " + user.getUserState());
|
||||
|
||||
// validate user has at least one role
|
||||
if (user.getRoles().isEmpty()) {
|
||||
|
@ -819,7 +819,7 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
|||
// validate who is doing this
|
||||
validateIsPrivilegeAdmin(certificate);
|
||||
|
||||
return this.persistenceHandler.persist(certificate);
|
||||
return this.persistenceHandler.persist();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -850,12 +850,22 @@ public class DefaultPrivilegeHandler implements PrivilegeHandler {
|
|||
* @author rvonburg
|
||||
*/
|
||||
private class CertificateSessionPair {
|
||||
/**
|
||||
* The {@link Session}
|
||||
*/
|
||||
public final Session session;
|
||||
/**
|
||||
* The {@link Certificate}
|
||||
*/
|
||||
public final Certificate certificate;
|
||||
|
||||
/**
|
||||
* Creates a new {@link CertificateSessionPair} with the given session and certificate
|
||||
*
|
||||
* @param session
|
||||
* the session
|
||||
* @param certificate
|
||||
* the certificate
|
||||
*/
|
||||
public CertificateSessionPair(Session session, Certificate certificate) {
|
||||
this.session = session;
|
||||
|
|
|
@ -38,8 +38,8 @@ public interface EncryptionHandler {
|
|||
public String convertToHash(String string);
|
||||
|
||||
/**
|
||||
* Initialize the concrete {@link EncryptionHandler}. The passed parameter map contains any configuration this map
|
||||
* might need
|
||||
* Initialize the concrete {@link EncryptionHandler}. The passed parameter map contains any configuration the
|
||||
* concrete {@link EncryptionHandler} might need
|
||||
*
|
||||
* @param parameterMap
|
||||
* a map containing configuration properties
|
||||
|
|
|
@ -12,7 +12,6 @@ package ch.eitchnet.privilege.handler;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import ch.eitchnet.privilege.model.Certificate;
|
||||
import ch.eitchnet.privilege.model.Restrictable;
|
||||
import ch.eitchnet.privilege.model.internal.Privilege;
|
||||
import ch.eitchnet.privilege.model.internal.Role;
|
||||
|
@ -136,14 +135,18 @@ public interface PersistenceHandler {
|
|||
public void addOrReplacePrivilege(Privilege privilege);
|
||||
|
||||
/**
|
||||
* @param certificate
|
||||
* Informs this {@link PersistenceHandler} to persist any changes which need to be saved
|
||||
*
|
||||
* @return
|
||||
* @return true if changes were persisted successfully, false if something went wrong
|
||||
*/
|
||||
public boolean persist(Certificate certificate);
|
||||
public boolean persist();
|
||||
|
||||
/**
|
||||
* Initialize the concrete {@link PersistenceHandler}. The passed parameter map contains any configuration the
|
||||
* concrete {@link PersistenceHandler} might need
|
||||
*
|
||||
* @param parameterMap
|
||||
* a map containing configuration properties
|
||||
*/
|
||||
public void initialize(Map<String, String> parameterMap);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import ch.eitchnet.privilege.model.Restrictable;
|
|||
import ch.eitchnet.privilege.model.RoleRep;
|
||||
import ch.eitchnet.privilege.model.UserRep;
|
||||
import ch.eitchnet.privilege.model.UserState;
|
||||
import ch.eitchnet.privilege.model.internal.Privilege;
|
||||
import ch.eitchnet.privilege.model.internal.Role;
|
||||
import ch.eitchnet.privilege.model.internal.User;
|
||||
import ch.eitchnet.privilege.policy.PrivilegePolicy;
|
||||
|
@ -33,118 +34,195 @@ import ch.eitchnet.privilege.policy.PrivilegePolicy;
|
|||
public interface PrivilegeHandler {
|
||||
|
||||
/**
|
||||
* This is the role users must have, if they are allowed to modify objects
|
||||
* value = PrivilegeAdmin: This is the role users must have, if they are allowed to modify objects
|
||||
*/
|
||||
public static final String PRIVILEGE_ADMIN_ROLE = "PrivilegeAdmin";
|
||||
|
||||
/**
|
||||
* @param username
|
||||
* Returns a {@link UserRep} for the given username
|
||||
*
|
||||
* @return
|
||||
* @param username
|
||||
* the name of the {@link UserRep} to return
|
||||
*
|
||||
* @return the {@link UserRep} for the given username, or null if it was not found
|
||||
*/
|
||||
public UserRep getUser(String username);
|
||||
|
||||
/**
|
||||
* @param roleName
|
||||
* Returns a {@link RoleRep} for the given roleName
|
||||
*
|
||||
* @return
|
||||
* @param roleName
|
||||
* the name of the {@link RoleRep} to return
|
||||
*
|
||||
* @return the {@link RoleRep} for the given roleName, or null if it was not found
|
||||
*/
|
||||
public RoleRep getRole(String roleName);
|
||||
|
||||
/**
|
||||
* @param privilegeName
|
||||
* Returns a {@link PrivilegeRep} for the given privilegeName
|
||||
*
|
||||
* @return
|
||||
* @param privilegeName
|
||||
* the name of the {@link PrivilegeRep} to return
|
||||
*
|
||||
* @return the {@link PrivilegeRep} for the given privilegeName, or null if it was not found
|
||||
*/
|
||||
public PrivilegeRep getPrivilege(String privilegeName);
|
||||
|
||||
/**
|
||||
* @param policyName
|
||||
* Returns a {@link PrivilegePolicy} for the given policyName
|
||||
*
|
||||
* @return
|
||||
* @param policyName
|
||||
* the name of the {@link PrivilegePolicy} to return
|
||||
*
|
||||
* @return the {@link PrivilegePolicy} for the given policyName, or null if it was not found
|
||||
*/
|
||||
public PrivilegePolicy getPolicy(String policyName);
|
||||
|
||||
/**
|
||||
* @param certificate
|
||||
* @param username
|
||||
* Removes the user with the given username
|
||||
*
|
||||
* @return
|
||||
* @param certificate
|
||||
* the {@link Certificate} of the user which has the privilege to perform this action
|
||||
* @param username
|
||||
* the username of the user to remove
|
||||
*
|
||||
* @return the {@link UserRep} of the user removed, or null if the user did not exist
|
||||
*/
|
||||
public UserRep removeUser(Certificate certificate, String username);
|
||||
|
||||
/**
|
||||
* Removes the role with the given roleName from the user with the given username
|
||||
*
|
||||
* @param certificate
|
||||
* the {@link Certificate} of the user which has the privilege to perform this action
|
||||
* @param username
|
||||
* the username of the user from which the role is to be removed
|
||||
* @param roleName
|
||||
* the rolename of the role to remove from the user
|
||||
*/
|
||||
public void removeRoleFromUser(Certificate certificate, String username, String roleName);
|
||||
|
||||
/**
|
||||
* @param certificate
|
||||
* @param roleName
|
||||
* Removes the role with the given roleName
|
||||
*
|
||||
* @return
|
||||
* @param certificate
|
||||
* the {@link Certificate} of the user which has the privilege to perform this action
|
||||
* @param roleName
|
||||
* the roleName of the role to remove
|
||||
*
|
||||
* @return the {@link RoleRep} of the role removed, or null if the role did not exist
|
||||
*/
|
||||
public RoleRep removeRole(Certificate certificate, String roleName);
|
||||
|
||||
/**
|
||||
* Removes the privilege with the given privilegeName from the role with the given roleName
|
||||
*
|
||||
* @param certificate
|
||||
* the {@link Certificate} of the user which has the privilege to perform this action
|
||||
* @param roleName
|
||||
* the roleName of the role from which the privilege is to be removed
|
||||
* @param privilegeName
|
||||
* the privilegeName of the privilege to remove from the role
|
||||
*/
|
||||
public void removePrivilegeFromRole(Certificate certificate, String roleName, String privilegeName);
|
||||
|
||||
/**
|
||||
* @param certificate
|
||||
* @param privilegeName
|
||||
* Removes the privilege with the given privilegeName
|
||||
*
|
||||
* @return
|
||||
* @param certificate
|
||||
* the {@link Certificate} of the user which has the privilege to perform this action
|
||||
* @param privilegeName
|
||||
* the privilegeName of the privilege to remove
|
||||
*
|
||||
* @return the {@link PrivilegeRep} of the privilege removed, or null if the privilege did not exist
|
||||
*/
|
||||
public PrivilegeRep removePrivilege(Certificate certificate, String privilegeName);
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Adds a new user, or replaces the user with the information from this {@link UserRep} if the user already exists
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* If the password given is null, then the user is created, but can not not login! Otherwise the password must meet
|
||||
* the requirements of the implementation under {@link PrivilegeHandler#validatePassword(String)}
|
||||
* </p>
|
||||
*
|
||||
* @param certificate
|
||||
* the {@link Certificate} of the user which has the privilege to perform this action
|
||||
* @param userRep
|
||||
* the {@link UserRep} containing the information to create the new {@link User}
|
||||
* @param password
|
||||
* the password of the new user. If the password is null, then this is accepted but the user can not
|
||||
* login, otherwise the password must be validated against
|
||||
* {@link PrivilegeHandler#validatePassword(String)}
|
||||
*/
|
||||
public void addOrReplaceUser(Certificate certificate, UserRep userRep, String password);
|
||||
|
||||
/**
|
||||
* Adds a new role, or replaces the role with the information from this {@link RoleRep} if the role already exists
|
||||
*
|
||||
* @param certificate
|
||||
* the {@link Certificate} of the user which has the privilege to perform this action
|
||||
* @param roleRep
|
||||
* the {@link RoleRep} containing the information to create the new {@link Role}
|
||||
*/
|
||||
public void addOrReplaceRole(Certificate certificate, RoleRep roleRep);
|
||||
|
||||
/**
|
||||
* Adds a new privilege, or replaces the privilege with the information from this {@link PrivilegeRep} if the
|
||||
* privilege already exists
|
||||
*
|
||||
* @param certificate
|
||||
* the {@link Certificate} of the user which has the privilege to perform this action
|
||||
* @param privilegeRep
|
||||
* the {@link PrivilegeRep} containing the information to create the new {@link Privilege}
|
||||
*/
|
||||
public void addOrReplacePrivilege(Certificate certificate, PrivilegeRep privilegeRep);
|
||||
|
||||
/**
|
||||
* Adds the role with the given roleName to the {@link User} with the given username
|
||||
*
|
||||
* @param certificate
|
||||
* the {@link Certificate} of the user which has the privilege to perform this action
|
||||
* @param username
|
||||
* the username of the {@link User} to which the role should be added
|
||||
* @param roleName
|
||||
* the roleName of the {@link Role} which should be added to the {@link User}
|
||||
*/
|
||||
public void addRoleToUser(Certificate certificate, String username, String roleName);
|
||||
|
||||
/**
|
||||
* Adds the privilege with the given privilegeName to the {@link Role} with the given roleName
|
||||
*
|
||||
* @param certificate
|
||||
* the {@link Certificate} of the user which has the privilege to perform this action
|
||||
* @param roleName
|
||||
* the roleName of the {@link Role} to which the privilege should be added
|
||||
* @param privilegeName
|
||||
* the privilegeName of the {@link Privilege} which should be added to the {@link Role}
|
||||
*/
|
||||
public void addPrivilegeToRole(Certificate certificate, String roleName, String privilegeName);
|
||||
|
||||
/**
|
||||
* Changes the password for the {@link User} with the given username. If the password is null, then the {@link User}
|
||||
* can not login anymore. Otherwise the password must meet the requirements of the implementation under
|
||||
* {@link PrivilegeHandler#validatePassword(String)}
|
||||
*
|
||||
* @param certificate
|
||||
* the {@link Certificate} of the user which has the privilege to perform this action
|
||||
* @param username
|
||||
* the username of the {@link User} for which the password is to be changed
|
||||
* @param password
|
||||
* the new password for this user. If the password is null, then the {@link User} can not login anymore.
|
||||
* Otherwise the password must meet the requirements of the implementation under
|
||||
* {@link PrivilegeHandler#validatePassword(String)}
|
||||
*/
|
||||
public void setUserPassword(Certificate certificate, String username, String password);
|
||||
|
||||
/**
|
||||
* @param certificate
|
||||
* the {@link Certificate} of the user which has the privilege to perform this action
|
||||
* @param username
|
||||
* @param firstname
|
||||
* @param surname
|
||||
|
@ -153,6 +231,7 @@ public interface PrivilegeHandler {
|
|||
|
||||
/**
|
||||
* @param certificate
|
||||
* the {@link Certificate} of the user which has the privilege to perform this action
|
||||
* @param username
|
||||
* @param state
|
||||
*/
|
||||
|
@ -160,6 +239,7 @@ public interface PrivilegeHandler {
|
|||
|
||||
/**
|
||||
* @param certificate
|
||||
* the {@link Certificate} of the user which has the privilege to perform this action
|
||||
* @param username
|
||||
* @param locale
|
||||
*/
|
||||
|
@ -167,6 +247,7 @@ public interface PrivilegeHandler {
|
|||
|
||||
/**
|
||||
* @param certificate
|
||||
* the {@link Certificate} of the user which has the privilege to perform this action
|
||||
* @param privilegeName
|
||||
* @param policyName
|
||||
*/
|
||||
|
@ -174,6 +255,7 @@ public interface PrivilegeHandler {
|
|||
|
||||
/**
|
||||
* @param certificate
|
||||
* the {@link Certificate} of the user which has the privilege to perform this action
|
||||
* @param privilegeName
|
||||
* @param allAllowed
|
||||
*/
|
||||
|
@ -181,6 +263,7 @@ public interface PrivilegeHandler {
|
|||
|
||||
/**
|
||||
* @param certificate
|
||||
* the {@link Certificate} of the user which has the privilege to perform this action
|
||||
* @param privilegeName
|
||||
* @param denyList
|
||||
*/
|
||||
|
@ -188,6 +271,7 @@ public interface PrivilegeHandler {
|
|||
|
||||
/**
|
||||
* @param certificate
|
||||
* the {@link Certificate} of the user which has the privilege to perform this action
|
||||
* @param privilegeName
|
||||
* @param allowList
|
||||
*/
|
||||
|
@ -206,6 +290,7 @@ public interface PrivilegeHandler {
|
|||
|
||||
/**
|
||||
* @param certificate
|
||||
* the {@link Certificate} of the user which has the privilege to perform this action
|
||||
* @param restrictable
|
||||
*
|
||||
* @return
|
||||
|
@ -276,14 +361,19 @@ public interface PrivilegeHandler {
|
|||
|
||||
/**
|
||||
* @param certificate
|
||||
* the {@link Certificate} of the user which has the privilege to perform this action
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean persist(Certificate certificate);
|
||||
|
||||
/**
|
||||
* Initialize the concrete {@link EncryptionHandler}. The passed parameter map contains any configuration this map
|
||||
* might need
|
||||
*
|
||||
* @param parameterMap
|
||||
* a map containing configuration properties
|
||||
*
|
||||
* @param encryptionHandler
|
||||
* @param persistenceHandler
|
||||
*/
|
||||
|
|
|
@ -28,7 +28,6 @@ import ch.eitchnet.privilege.helper.ClassHelper;
|
|||
import ch.eitchnet.privilege.helper.XmlConstants;
|
||||
import ch.eitchnet.privilege.helper.XmlHelper;
|
||||
import ch.eitchnet.privilege.i18n.PrivilegeException;
|
||||
import ch.eitchnet.privilege.model.Certificate;
|
||||
import ch.eitchnet.privilege.model.UserState;
|
||||
import ch.eitchnet.privilege.model.internal.Privilege;
|
||||
import ch.eitchnet.privilege.model.internal.Role;
|
||||
|
@ -159,10 +158,10 @@ public class XmlPersistenceHandler implements PersistenceHandler {
|
|||
}
|
||||
|
||||
/**
|
||||
* @see ch.eitchnet.privilege.handler.PersistenceHandler#persist(ch.eitchnet.privilege.model.Certificate)
|
||||
* @see ch.eitchnet.privilege.handler.PersistenceHandler#persist()
|
||||
*/
|
||||
@Override
|
||||
public boolean persist(Certificate certificate) {
|
||||
public boolean persist() {
|
||||
|
||||
// USERS
|
||||
// get users file name
|
||||
|
@ -404,6 +403,8 @@ public class XmlPersistenceHandler implements PersistenceHandler {
|
|||
List<Element> userElements = usersRootElement.elements(XmlConstants.XML_USER);
|
||||
for (Element userElement : userElements) {
|
||||
|
||||
String userId = userElement.attributeValue(XmlConstants.XML_ATTR_USER_ID);
|
||||
|
||||
String username = userElement.attributeValue(XmlConstants.XML_ATTR_USERNAME);
|
||||
String password = userElement.attributeValue(XmlConstants.XML_ATTR_PASSWORD);
|
||||
|
||||
|
@ -430,8 +431,8 @@ public class XmlPersistenceHandler implements PersistenceHandler {
|
|||
}
|
||||
|
||||
// create user
|
||||
User user = new User(username, password, firstname, surname, userState, Collections.unmodifiableSet(roles),
|
||||
locale);
|
||||
User user = new User(userId, username, password, firstname, surname, userState, Collections
|
||||
.unmodifiableSet(roles), locale);
|
||||
|
||||
// put user in map
|
||||
this.userMap.put(username, user);
|
||||
|
@ -605,6 +606,7 @@ public class XmlPersistenceHandler implements PersistenceHandler {
|
|||
|
||||
// create the user element
|
||||
Element userElement = documentFactory.createElement(XmlConstants.XML_USER);
|
||||
userElement.addAttribute(XmlConstants.XML_ATTR_USER_ID, user.getUserId());
|
||||
userElement.addAttribute(XmlConstants.XML_ATTR_USERNAME, user.getUsername());
|
||||
userElement.addAttribute(XmlConstants.XML_ATTR_PASSWORD, user.getPassword());
|
||||
|
||||
|
@ -620,7 +622,7 @@ public class XmlPersistenceHandler implements PersistenceHandler {
|
|||
|
||||
// add state element
|
||||
Element stateElement = documentFactory.createElement(XmlConstants.XML_STATE);
|
||||
stateElement.setText(user.getState().toString());
|
||||
stateElement.setText(user.getUserState().toString());
|
||||
userElement.add(stateElement);
|
||||
|
||||
// add locale element
|
||||
|
|
|
@ -46,6 +46,7 @@ public class XmlConstants {
|
|||
public static final String XML_ATTR_NAME = "name";
|
||||
public static final String XML_ATTR_VALUE = "value";
|
||||
public static final String XML_ATTR_POLICY = "policy";
|
||||
public static final String XML_ATTR_USER_ID = "userId";
|
||||
public static final String XML_ATTR_USERNAME = "username";
|
||||
public static final String XML_ATTR_PASSWORD = "password";
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ public class UserRep implements Serializable {
|
|||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final String userId;
|
||||
private String username;
|
||||
private String firstname;
|
||||
private String surname;
|
||||
|
@ -30,6 +31,7 @@ public class UserRep implements Serializable {
|
|||
private Locale locale;
|
||||
|
||||
/**
|
||||
* @param userId
|
||||
* @param username
|
||||
* @param firstname
|
||||
* @param surname
|
||||
|
@ -37,8 +39,9 @@ public class UserRep implements Serializable {
|
|||
* @param roles
|
||||
* @param locale
|
||||
*/
|
||||
public UserRep(String username, String firstname, String surname, UserState userState, Set<String> roles,
|
||||
Locale locale) {
|
||||
public UserRep(String userId, String username, String firstname, String surname, UserState userState,
|
||||
Set<String> roles, Locale locale) {
|
||||
this.userId = userId;
|
||||
this.username = username;
|
||||
this.firstname = firstname;
|
||||
this.surname = surname;
|
||||
|
@ -47,6 +50,13 @@ public class UserRep implements Serializable {
|
|||
this.locale = locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the userId
|
||||
*/
|
||||
public String getUserId() {
|
||||
return this.userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the username
|
||||
*/
|
||||
|
|
|
@ -24,6 +24,8 @@ import ch.eitchnet.privilege.model.UserState;
|
|||
*/
|
||||
public final class User {
|
||||
|
||||
private final String userId;
|
||||
|
||||
private final String username;
|
||||
private final String password;
|
||||
|
||||
|
@ -37,7 +39,7 @@ public final class User {
|
|||
private final Locale locale;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userId
|
||||
* @param username
|
||||
* @param password
|
||||
* @param firstname
|
||||
|
@ -46,9 +48,11 @@ public final class User {
|
|||
* @param roles
|
||||
* @param locale
|
||||
*/
|
||||
public User(String username, String password, String firstname, String surname, UserState userState,
|
||||
public User(String userId, String username, String password, String firstname, String surname, UserState userState,
|
||||
Set<String> roles, Locale locale) {
|
||||
|
||||
this.userId = userId;
|
||||
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.userState = userState;
|
||||
|
@ -61,6 +65,13 @@ public final class User {
|
|||
this.locale = locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the userId
|
||||
*/
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the username
|
||||
*/
|
||||
|
@ -101,7 +112,7 @@ public final class User {
|
|||
/**
|
||||
* @return the userState
|
||||
*/
|
||||
public UserState getState() {
|
||||
public UserState getUserState() {
|
||||
return this.userState;
|
||||
}
|
||||
|
||||
|
@ -133,7 +144,7 @@ public final class User {
|
|||
* @return a {@link UserRep} which is a representation of this object used to serialize and view on clients
|
||||
*/
|
||||
public UserRep asUserRep() {
|
||||
return new UserRep(this.username, this.firstname, this.surname, this.userState,
|
||||
return new UserRep(this.userId, this.username, this.firstname, this.surname, this.userState,
|
||||
new HashSet<String>(this.roles), this.locale);
|
||||
}
|
||||
|
||||
|
@ -143,7 +154,9 @@ public final class User {
|
|||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("User [username=");
|
||||
builder.append("User [userId=");
|
||||
builder.append(this.userId);
|
||||
builder.append(", username=");
|
||||
builder.append(this.username);
|
||||
builder.append(", firstname=");
|
||||
builder.append(this.firstname);
|
||||
|
|
|
@ -90,7 +90,7 @@ public class PrivilegeTest {
|
|||
Certificate certificate = privilegeHandler.authenticate("eitch", "1234567890");
|
||||
|
||||
// let's add a new user bob
|
||||
UserRep userRep = new UserRep("bob", "Bob", "Newman", UserState.NEW, new HashSet<String>(), null);
|
||||
UserRep userRep = new UserRep("1", "bob", "Bob", "Newman", UserState.NEW, new HashSet<String>(), null);
|
||||
privilegeHandler.addOrReplaceUser(certificate, userRep, null);
|
||||
logger.info("Added user bob");
|
||||
|
||||
|
@ -154,7 +154,7 @@ public class PrivilegeTest {
|
|||
org.junit.Assert.assertTrue("Certificate is null!", certificate != null);
|
||||
|
||||
// let's add a new user bob
|
||||
UserRep userRep = new UserRep("bob", "Bob", "Newman", UserState.NEW, new HashSet<String>(), null);
|
||||
UserRep userRep = new UserRep("1", "bob", "Bob", "Newman", UserState.NEW, new HashSet<String>(), null);
|
||||
privilegeHandler.addOrReplaceUser(certificate, userRep, null);
|
||||
logger.info("Added user bob");
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ public class PrivilegeTest {
|
|||
org.junit.Assert.assertTrue("Certificate is null!", certificate != null);
|
||||
|
||||
// let's add a new user ted
|
||||
UserRep userRep = new UserRep("ted", "Ted", "Newman", UserState.NEW, new HashSet<String>(), null);
|
||||
UserRep userRep = new UserRep("2", "ted", "Ted", "Newman", UserState.NEW, new HashSet<String>(), null);
|
||||
privilegeHandler.addOrReplaceUser(certificate, userRep, null);
|
||||
logger.info("Added user bob");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue