/** * Secures {@link User} object. * @param source * @return {@link User} object */ protected User prepareMinimalUser(User source) { if (source==null) { return null; } // creating new object to make sure only specified data will be sent to unauthorized client User result = new User(); result.setId(source.getId()); result.setDomain(source.getDomain()); result.setIdentifiers(source.getIdentifiers()); result.setAttributes(prepareMinimalAttributes(source.getAttributes())); return result; }
/** * Transform hibernate user to user. * * @param hibernateUser the hibernate user * @return the user */ public static User transformHibernateUserToUser(HibernateUser hibernateUser) { if (hibernateUser == null) { return null; } User user = new User(); user.setId(hibernateUser.getId()); user.setDomain(hibernateUser.getDomain()); user.setAttributes(new HashMap<String, String>(hibernateUser.getAttributes())); user.setRoles(new HashSet<String>(hibernateUser.getRoles())); user.setFlags(new HashSet<String>(hibernateUser.getFlags())); user.setIdentifiers(new HashSet<String>(hibernateUser.getIdentifiers())); return user; }
@Override public String addUser(User user) throws UserExistsException, DomainNotSupportedException { if (user.getDomain() == null) { user.setDomain(UserCatalogConstants.DEFAULT_DOMAIN_NAME); } else { checkIfDomainSupported(user.getDomain()); } return userDao.save(UserCatalogModelHibernateModelTransformer.transformUserToHibernateUser(user)); }
public void addAllAttr(Map<String, String> attr){ Map<String, String> oldAttr = userData.getUser().getAttributes(); if(oldAttr==null) oldAttr = Collections.emptyMap(); Map<String, String> newAttr = Maps.newHashMap(); newAttr.putAll(oldAttr); newAttr.putAll(attr); userData.getUser().setAttributes(newAttr); }
if (source!=null) { UserData result = new UserData(); result.setUser(new User()); if (source.getName()!=null && source.getName().trim().length()>0) { if (setNameAsExtId) { result.getUser().setIdentifiers(new HashSet<String>()); result.getUser().getIdentifiers().add(source.getName()); } else { result.getUser().setId(source.getName()); result.getUser().setDomain(source.getDomain()); result.getUser().setRoles(convertCSVToSet(source.getRolesCSV())); result.getUser().setFlags(convertCSVToSet(source.getFlagsCSV())); if (result.getUser().getFlags()==null) { result.getUser().setFlags(new HashSet<String>()); result.getUser().getFlags().add(UserFlagsConstants.ACTIVE); } else if (!result.getUser().getFlags().contains(UserFlagsConstants.INACTIVE)) { result.getUser().getFlags().add(UserFlagsConstants.ACTIVE); result.getUser().setAttributes(convertAttributes(source.getAttrsCSV())); if (result.getUser().getAttributes()==null) { result.getUser().setAttributes(new HashMap<String, String>()); result.getUser().getAttributes().put( UserAttributesConstants.EMAIL, source.getEmail());
if (userData.getUser().getAttributes()==null) { userData.getUser().setAttributes(new HashMap<String, String>()); userData.getUser().getAttributes().put( ATTR_KEY_CREATED_BY, generateCreatedByAttrValue(cli, context)); userDataList.add(userData); System.out.println(new Formatter().format("%1$-3s %2$-15s %3$-15s %4$-25s %5$-60s %6$s", ++idx, user.getUser().getDomain(), user.getUser().getIdentifiers().iterator().next(), user.getUser().getAttributes().get(UserAttributesConstants.EMAIL), user.getUser().getRoles(), prepareAttributes(user.getUser().getAttributes(), UserAttributesConstants.EMAIL))); if (ACTION_ADD_ROLE_TO_ALL.equals(cli.getOptionValue(CLI_SHORT_PARAM_ACTION))) { for (UserData result : results.getResults()) { if (result.getUser().getRoles()==null) { result.getUser().setRoles(new HashSet<String>()); result.getUser().getRoles().add(cli.getOptionValue(CLI_SHORT_PARAM_ROLE)); userCatalogFacade.updateUser(result.getUser()); } else { if (!result.getUser().getRoles().contains( cli.getOptionValue(CLI_SHORT_PARAM_ROLE))) { result.getUser().getRoles().add(cli.getOptionValue(CLI_SHORT_PARAM_ROLE)); userCatalogFacade.updateUser(result.getUser()); if (result.getUser().getRoles()!=null &&
Element xUser = new Element("user", ns); Element xId = new Element("id", ns); xId.setText(user.getId()); xUser.addContent(xId); Element xDomain = new Element("domain", ns); xDomain.setText(user.getDomain()); xUser.addContent(xDomain); if (!CollectionUtils.isEmpty(user.getRoles())) { Element xRoles = new Element("roles", ns); for (String role : user.getRoles()) { Element xRole = new Element("role", ns); xRole.setText(role); if (!CollectionUtils.isEmpty(user.getFlags())) { Element xFlags = new Element("flags", ns); for (String flag : user.getFlags()) { Element xFlag = new Element("flag", ns); xFlag.setText(flag); if (!CollectionUtils.isEmpty(user.getIdentifiers())) { Element xIdentifiers = new Element("identifiers", ns); for (String identifier : user.getIdentifiers()) { Element xIdentifier = new Element("identifier", ns); xIdentifier.setText(identifier); if (user.getAttributes() != null && user.getAttributes().size() > 0) { Element xAttributes = new Element("attributes", ns); for (Entry<String, String> entry : user.getAttributes().entrySet()) {
throws NamingException { User user = new User(); if (attrs.get("uid") != null) { user.setId((String) attrs.get("uid").get()); if (user.getAttributes()==null) { user.setAttributes(new HashMap<String, String>()); user.getAttributes().put( UserAttributesConstants.EMAIL, (String) attrs.get(JoomlaLDAPConstants.MAIL_ATTR_NAME).get()); if (user.getAttributes()==null) { user.setAttributes(new HashMap<String, String>()); user.getAttributes().put( UserAttributesConstants.FULL_NAME, (String) attrs.get(JoomlaLDAPConstants.DISP_NAME_ATTR_NAME).get());
private Map<String, String> getAllAttr(){ Map<String, String> attrs = userData.getUser().getAttributes(); if(attrs == null) attrs = Collections.emptyMap(); return attrs; }
@Override public void updateUser(User user) throws UserNotFoundException { if (user.getId()==null) { throw new InvalidParameterException("got null user id: " + "user identifier has to be set externally!"); } Name userDN = builUserDn(user.getId()); try { if (ldapTemplate.lookup(userDN)==null) { throw new UserNotFoundException( user.getId(), user.getDomain()); } } catch(NameNotFoundException e) { throw new UserNotFoundException( user.getId(), user.getDomain()); } // updating only selected attributes ModificationItem[] modItems = prepareModifications(user); if (modItems!=null && modItems.length>0) { ldapTemplate.modifyAttributes(userDN, modItems); } else { log.warn("No modifications will be made: " + "no modification items found!"); } }
if (CollectionUtils.isNotEmpty(getEffectiveRoles())) { getEffectiveRoles().removeAll(getRoles()); if (CollectionUtils.isNotEmpty(user.getRoles())) { getEffectiveRoles().addAll(user.getRoles()); if (CollectionUtils.isNotEmpty(user.getRoles())) { setEffectiveRoles(new HashSet<String>(user.getRoles())); if (MapUtils.isNotEmpty(user.getAttributes())) { setAttributes(new HashMap<String, String>(user.getAttributes())); } else { setAttributes(new HashMap<String, String>()); if (CollectionUtils.isNotEmpty(user.getRoles())) { setRoles(new HashSet<String>(user.getRoles())); } else { setRoles(new HashSet<String>(0)); if (CollectionUtils.isNotEmpty(user.getFlags())) { setFlags(new HashSet<String>(user.getFlags())); } else { setFlags(new HashSet<String>(0)); if (CollectionUtils.isNotEmpty(user.getIdentifiers())) { setIdentifiers(new HashSet<String>(user.getIdentifiers())); } else { setIdentifiers(new HashSet<String>(0));
ocattr.add(JoomlaLDAPConstants.USER_OBJECTCLASS_NAME); attrs.put(ocattr); attrs.put("cn", user.getId()); attrs.put("sn", user.getId()); throw new RuntimeException("invalid state: bad encoding!", e); if (user.getAttributes()!=null) { if (user.getAttributes().containsKey(UserAttributesConstants.EMAIL)) { attrs.put(JoomlaLDAPConstants.MAIL_ATTR_NAME, user.getAttributes().get(UserAttributesConstants.EMAIL)); if (user.getAttributes().containsKey(UserAttributesConstants.FULL_NAME)) { attrs.put(JoomlaLDAPConstants.DISP_NAME_ATTR_NAME, user.getAttributes().get(UserAttributesConstants.FULL_NAME));
@Override public void changeUserData(String newName, String newEmail, String newPassword, Map<String, String> attributes) { try { UserData userData = userCatalog.loadUser(currentUser.getLogin(), domain, UserDataParts.SAFE_SENSITIVE_DATA); pl.edu.icm.yadda.service2.user.model.User user = userData.getUser(); String newId = newEmail; user.getIdentifiers().remove(currentUser.getEmail()); user.getIdentifiers().add(newId); user.setAttributes(attributes); userCatalog.updateUser(user); currentUser = loadUserData(newId); notificationService.publishLocalizedNotification( NotificationLevel.INFO, MessageConstants.PAGE_CHANGE_USER_DATA_SUCCESS); } catch (UserNotFoundException e) { throw new SystemException(Modules.PREFERENCES, e.getMessage()); } }
/** * Builds user login. * @param userData * @return user login */ public static String buildUserLogin(UserData userData) { // in some scenarios there are no additional ids, main id only which is user's login return (userData.getUser().getIdentifiers()!=null && !userData.getUser().getIdentifiers().isEmpty())? userData.getUser().getIdentifiers().iterator().next(): userData.getUser().getId(); }
UserData getUserDataForId(String id, List<UserData> candidates) { for (UserData current : candidates) { if (id.equals(current.getUser().getId())) { return current; } } return null; }
@Override public GenericResponse updateUser(ModifyUserRequest request) { Map<String, Serializable> auxParams = new HashMap<String, Serializable>(); if (request.getUser()!=null && request.getUser().getDomain()!=null) { auxParams.put(XACMLConstants.SUBJECT_AUX_PARAM_DOMAIN_ROOT_SUFFIX, extractDomainRoot(request.getUser().getDomain())); auxParams.put(XACMLConstants.SUBJECT_AUX_PARAM_DOMAIN_SUFFIX, request.getUser().getDomain());
if (userData.getUser().getFlags()!=null && userData.getUser().getFlags().contains(UserFlagsConstants.INACTIVE)) { notificationService.publishLocalizedNotification( NotificationLevel.ERROR, DefaultUserHelper.buildUserLogin(userData), "", DefaultUserHelper.buildUserName(userData), userData.getUser().getAttributes().get(UserAttributes.ATTRIBUTE_EMAIL), userData.getUser().getAttributes());
/** * Prepares results to conform with contract defined for listing users and * sorting users in the same order as the one specified for identifiers. For * each not found user null should be stored in returned list. * * @param candidates the candidates * @param genericIds not null list of ids * @return prepared results */ public static List<UserData> prepareListUsersResults(List<UserData> candidates, List<String> genericIds) { List<UserData> results = new ArrayList<UserData>(genericIds.size()); if (candidates == null || candidates.size() == 0) { for (int i = 0; i < genericIds.size(); i++) { results.add(i, null); } return results; } for (String id : genericIds) { UserData udToSet = null; for (UserData ud : candidates) { if (ud.getId().equals(id) || ud.getUser().getIdentifiers().contains(id)) { udToSet = ud; break; } } results.add(genericIds.indexOf(id), udToSet); } return results; } }
/** * Builds user name. * @param userData * @return user name */ public static String buildUserName(UserData userData) { if (userData.getUser().getAttributes().containsKey(UserAttributes.ATTRIBUTE_NAME)) { return userData.getUser().getAttributes().get(UserAttributes.ATTRIBUTE_NAME); } else if (userData.getUser().getAttributes().containsKey(UserAttributes.ATTRIBUTE_FIRST_NAME)) { String userName = userData.getUser().getAttributes().get(UserAttributes.ATTRIBUTE_FIRST_NAME); if (userData.getUser().getAttributes().containsKey(UserAttributes.ATTRIBUTE_LAST_NAME)) { userName += ' '; userName += userData.getUser().getAttributes().get(UserAttributes.ATTRIBUTE_LAST_NAME); } return userName; } else { // fallback: user name will be based on login return buildUserLogin(userData); } } }