use of org.jaffa.applications.jaffa.modules.admin.domain.UserRole in project jaffa-framework by jaffa-projects.
the class UserMaintenanceTx method performUserRoleValidations.
private void performUserRoleValidations(String[] userRole, User domain) throws ApplicationExceptions {
ApplicationExceptions appExps = null;
boolean foundExcludedRole = false;
Roles root = PolicyCache.getRoles();
if (root != null) {
List roleObjects = root.getRole();
if (roleObjects != null) {
for (Iterator it = roleObjects.iterator(); it.hasNext(); ) {
Role role = (Role) it.next();
if (Arrays.binarySearch(userRole, role.getName()) >= 0) {
List includes = role.getInclude();
if (includes != null) {
for (Iterator it2 = includes.iterator(); it2.hasNext(); ) {
Include includedObject = (Include) it2.next();
String includeName = includedObject.getName();
if (Arrays.binarySearch(userRole, includeName) < 0) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(new UserMaintenanceException(UserMaintenanceException.PROP_INCLUDED_ROLE_MISSING, role.getName(), includeName));
}
}
}
List excludes = role.getExclude();
if (excludes != null && !foundExcludedRole) {
for (Iterator it2 = excludes.iterator(); it2.hasNext(); ) {
Exclude excludedObject = (Exclude) it2.next();
String excludeName = excludedObject.getName();
if (Arrays.binarySearch(userRole, excludeName) >= 0) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(new UserMaintenanceException(UserMaintenanceException.PROP_EXCLUDED_ROLE_PRESENT, role.getName(), excludeName));
foundExcludedRole = true;
}
}
}
}
}
}
}
if (appExps != null && appExps.size() > 0)
throw appExps;
}
use of org.jaffa.applications.jaffa.modules.admin.domain.UserRole in project jaffa-framework by jaffa-projects.
the class UserViewerTx method addRelatedDtos.
// .//GEN-END:_buildDto_3_be
// .//GEN-BEGIN:_addRelatedDtos_1_be
private void addRelatedDtos(UOW uow, UserViewerOutDto output, User user) throws UOWException {
// .//GEN-BEGIN:_addRelatedDtos_UserRole_1_be
if (user.getUserName() != null) {
Criteria criteria = new Criteria();
criteria.setTable(UserRoleMeta.getName());
criteria.addCriteria(UserRoleMeta.USER_NAME, user.getUserName());
criteria.addOrderBy("UserName", Criteria.ORDER_BY_ASC);
criteria.addOrderBy("RoleName", Criteria.ORDER_BY_ASC);
// .//GEN-END:_addRelatedDtos_UserRole_1_be
// Add custom code to set the criteria before the query //GEN-FIRST:_addRelatedDtos_UserRole_1
// .//GEN-LAST:_addRelatedDtos_UserRole_1
// .//GEN-BEGIN:_addRelatedDtos_UserRole_2_be
Iterator itr = uow.query(criteria).iterator();
while (itr.hasNext()) {
UserRole userRole = (UserRole) itr.next();
UserRoleDto dto = new UserRoleDto();
// .//GEN-END:_addRelatedDtos_UserRole_2_be
// Add custom code before all the setters //GEN-FIRST:_addRelatedDtos_UserRole_2
// .//GEN-LAST:_addRelatedDtos_UserRole_2
// .//GEN-BEGIN:_addRelatedDtos_UserRole_UserName_1_be
dto.setUserName(userRole.getUserName());
// .//GEN-END:_addRelatedDtos_UserRole_UserName_1_be
// .//GEN-BEGIN:_addRelatedDtos_UserRole_RoleName_1_be
dto.setRoleName(userRole.getRoleName());
// .//GEN-END:_addRelatedDtos_UserRole_RoleName_1_be
// Add custom code to pass values to the dto //GEN-FIRST:_addRelatedDtos_UserRole_3
// .//GEN-LAST:_addRelatedDtos_UserRole_3
// .//GEN-BEGIN:_addRelatedDtos_UserRole_3_be
output.addUserRole(dto);
}
}
// .//GEN-END:_addRelatedDtos_UserRole_3_be
// .//GEN-BEGIN:_addRelatedDtos_2_be
}
use of org.jaffa.applications.jaffa.modules.admin.domain.UserRole in project jaffa-framework by jaffa-projects.
the class UserContextWrapper method readUserRoles.
/**
* Read the roles for the user from the database
*
* @param userId the user id.
* @return the roles for the user.
* @throws FrameworkException if any internal error occurs.
*/
protected String[] readUserRoles(String userId) throws FrameworkException {
UOW uow = null;
List<String> roleList = new ArrayList<String>();
try {
uow = new UOW();
Criteria c = new Criteria();
c.setTable(UserRoleMeta.getName());
c.addCriteria(UserRoleMeta.USER_NAME, userId);
Collection roles = uow.query(c);
for (Iterator it = roles.iterator(); it.hasNext(); ) {
UserRole role = (UserRole) it.next();
roleList.add(role.getRoleName());
}
} catch (UOWException e) {
// Log the error
log.error("Can't Get The Roles for User - " + userId, e);
} finally {
// Attempt to rollback any open transaction
try {
if (uow != null) {
uow.rollback();
}
} catch (UOWException e) {
log.error("Rollback", e);
}
}
return (String[]) roleList.toArray(new String[0]);
}
use of org.jaffa.applications.jaffa.modules.admin.domain.UserRole in project jaffa-framework by jaffa-projects.
the class UserMaintenanceTx method updateDomain.
// .//GEN-END:_loadUpdate_3_be
// .//GEN-BEGIN:_updateDomain_1_be
/**
* Update the domain object and add it to the UOW.
*/
private void updateDomain(UOW uow, UserMaintenanceUpdateInDto input, User domain, boolean fromPrevalidate) throws FrameworkException, ApplicationExceptions {
ApplicationExceptions appExps = null;
// .//GEN-BEGIN:_updateDomain_2_be
try {
domain.updateFirstName(input.getFirstName());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateLastName(input.getLastName());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateStatus(input.getStatus());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateEMailAddress(input.getEMailAddress());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateSecurityQuestion(input.getSecurityQuestion());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
domain.updateSecurityAnswer(input.getSecurityAnswer());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
if (!fromPrevalidate)
domain.updateLastUpdatedOn(new DateTime());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
try {
if (!fromPrevalidate && input.getHeaderDto() != null && input.getHeaderDto().getUserId() != null)
domain.updateLastUpdatedBy(input.getHeaderDto().getUserId());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
// Add custom code //GEN-FIRST:_updateDomain_2
try {
if (input.getPassword1() != null)
domain.updatePassword(input.getPassword1());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
String[] userRole = null;
if (appExps == null || appExps.size() == 0) {
// Build an array of roles
userRole = new String[input.getUserRoleCount()];
UserRoleDto[] userRoleDtos = input.getUserRole();
for (int i = 0; i < userRoleDtos.length; i++) userRole[i] = userRoleDtos[i].getRoleName();
Arrays.sort(userRole);
performUserRoleValidations(userRole, domain);
}
if (!fromPrevalidate) {
// These keep track of whats added and removed
Collection rolesAdded = new ArrayList();
Collection rolesRemoved = new ArrayList();
Collection processed = new ArrayList();
if (appExps == null || appExps.size() == 0) {
// Roles can be updated only if the user has access to the maintenance function
if (hasMaintenanceAccess()) {
// Get the current roles
Criteria crit = new Criteria();
crit.setTable(UserRoleMeta.getName());
crit.addCriteria(UserRoleMeta.USER_NAME, input.getUserName());
Collection currRoles = uow.query(crit);
// if in database, add to the processed list
for (Iterator it = currRoles.iterator(); it.hasNext(); ) {
UserRole ur = (UserRole) it.next();
if (Arrays.binarySearch(userRole, ur.getRoleName()) >= 0) {
processed.add(ur.getRoleName());
if (log.isDebugEnabled())
log.debug("Keeping Role - " + ur.getRoleName());
} else {
rolesRemoved.add(ur.getRoleName());
uow.delete(ur);
if (log.isDebugEnabled())
log.debug("Deleting Role - " + ur.getRoleName());
}
}
// Now add the new ones
for (int i = 0; i < userRole.length; i++) {
String rolename = userRole[i];
if (!processed.contains(rolename)) {
try {
UserRole ur = new UserRole();
ur.updateRoleName(rolename);
ur.updateUserName(input.getUserName());
rolesAdded.add(ur.getRoleName());
uow.add(ur);
if (log.isDebugEnabled())
log.debug("Adding Role - " + ur.getRoleName());
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
}
}
}
}
}
if (input.getNotifyUser().booleanValue()) {
try {
EmailerBean email = new EmailerBean();
String[] to = new String[] { domain.getEMailAddress() };
StringBuffer body = new StringBuffer();
if ((oldPassword != null && !oldPassword.equals(domain.getPassword())) || (oldStatus != null && !oldStatus.equals(domain.getStatus()))) {
body.append("Your UserName is " + domain.getUserName());
if (oldPassword != null && !oldPassword.equals(domain.getPassword()))
body.append(" and your password is " + domain.getPassword() + ".");
if (oldStatus != null && !oldStatus.equals(domain.getStatus()))
body.append("Your account is currently " + domain.getStatus() + ".");
email.sendMail(to, "Account Information", body.toString());
}
} catch (javax.mail.MessagingException e) {
e.printStackTrace();
}
}
/* try {
UserRequest userRequest = UserRequest.findByPK(uow , new Long(input.getRequestId()));
userRequest.setStatus("S");
uow.update(userRequest);
} catch (ValidationException e) {
if (appExps == null)
appExps = new ApplicationExceptions();
appExps.add(e);
}
*/
if (appExps != null && appExps.size() > 0)
throw appExps;
// .//GEN-BEGIN:_updateDomain_3_be
if (appExps != null && appExps.size() > 0)
throw appExps;
}
use of org.jaffa.applications.jaffa.modules.admin.domain.UserRole in project jaffa-framework by jaffa-projects.
the class UserMaintenanceTx method addRelatedDtosToRetrieveOut.
// .//GEN-END:_createPrevalidateOutDto_2_be
// .//GEN-BEGIN:_addRelatedDtosToRetrieveOut_1_be
/**
* Add related objects to UserMaintenanceRetrieveOutDto
*/
private void addRelatedDtosToRetrieveOut(UOW uow, User user, UserMaintenanceRetrieveOutDto output) throws FrameworkException, ApplicationExceptions {
// .//GEN-BEGIN:_addRelatedDtosToRetrieveOut_UserRole_1_be
if (user.getUserName() != null) {
Criteria criteria = new Criteria();
criteria.setTable(UserRoleMeta.getName());
criteria.addCriteria(UserRoleMeta.USER_NAME, user.getUserName());
// .//GEN-END:_addRelatedDtosToRetrieveOut_UserRole_1_be
// Add custom code to set the criteria before the query //GEN-FIRST:_addRelatedDtosToRetrieveOut_UserRole_1
// .//GEN-LAST:_addRelatedDtosToRetrieveOut_UserRole_1
// .//GEN-BEGIN:_addRelatedDtosToRetrieveOut_UserRole_2_be
Iterator itrMany = uow.query(criteria).iterator();
while (itrMany.hasNext()) {
UserRole userRole = (UserRole) itrMany.next();
UserRoleDto dto = new UserRoleDto();
// .//GEN-END:_addRelatedDtosToRetrieveOut_UserRole_2_be
// Add custom code before all the setters //GEN-FIRST:_addRelatedDtosToRetrieveOut_UserRole_2
// .//GEN-LAST:_addRelatedDtosToRetrieveOut_UserRole_2
// .//GEN-BEGIN:_addRelatedDtosToRetrieveOut_UserRole_RoleName_1_be
dto.setRoleName(userRole.getRoleName());
// .//GEN-END:_addRelatedDtosToRetrieveOut_UserRole_RoleName_1_be
// Add custom code to pass values to the dto //GEN-FIRST:_addRelatedDtosToRetrieveOut_UserRole_3
// .//GEN-LAST:_addRelatedDtosToRetrieveOut_UserRole_3
// .//GEN-BEGIN:_addRelatedDtosToRetrieveOut_UserRole_3_be
output.addUserRole(dto);
}
// .//GEN-END:_addRelatedDtosToRetrieveOut_UserRole_3_be
// .//GEN-BEGIN:_addRelatedDtosToRetrieveOut_UserRole_6_be
}
// .//GEN-END:_addRelatedDtosToRetrieveOut_UserRole_6_be
// .//GEN-BEGIN:_addRelatedDtosToRetrieveOut_2_be
}
Aggregations