Package org.fao.geonet.domain

Examples of org.fao.geonet.domain.User


        // Add new user to database

        Group group = getGroup(context);
        String passwordHash = PasswordUtil.encode(context, password);
        User user = new User()
                .setKind(kind)
                .setName(name)
                .setOrganisation(organ)
                .setProfile(Profile.findProfileIgnoreCase(profile))
                .setSurname(surname)
                .setUsername(username);
        user.getSecurity().setPassword(passwordHash);
        user.getEmailAddresses().add(email);
        user.getAddresses().add(new Address().setAddress(address).setCountry(country).setCity(city).setState(state).setZip(zip));

        userRepository.save(user);

        // The user is created as registereduser on the GUEST group, and not mapped on the specific optional
        // profile. Then the catalogue administrator could manage the created user.
View Full Code Here


    String changeKey = Util.getParam(params, CHANGE_KEY);
    String template = Util.getParam(params, Params.TEMPLATE, PWD_CHANGED_XSLT);
   
    // check valid user
        final UserRepository userRepository = context.getBean(UserRepository.class);
        User elUser = userRepository.findOneByUsername(username);
    if (elUser == null) {
      throw new UserNotFoundEx(username);
        }

    // only let registered users change their password this way 
    if ( elUser.getProfile() != Profile.RegisteredUser) {
      throw new OperationNotAllowedEx("Only users with profile RegisteredUser can change their password using this option");
        }
   
    // construct expected change key - only valid today
    String scrambledPassword = elUser.getPassword();
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
    String todaysDate = sdf.format(cal.getTime());
    boolean passwordMatches = PasswordUtil.encoder(context.getServlet().getServletContext()).matches(scrambledPassword+todaysDate, changeKey);

    //check change key
    if (!passwordMatches)
      throw new BadParameterEx("Change key invalid or expired", changeKey);
   
    // get mail details
    SettingManager sm = context.getBean(SettingManager.class);

    String adminEmail = sm.getValue("system/feedback/email");
    String thisSite = sm.getSiteName();

    // get site URL
    SettingInfo si = context.getBean(SettingInfo.class);
    String siteURL = si.getSiteUrl() + context.getBaseUrl();

        elUser.getSecurity().setPassword(PasswordUtil.encode(context, password));
        userRepository.save(elUser);

    // generate email details using customisable stylesheet
    //TODO: allow internationalised emails
    Element root = new Element("root");
    root.addContent(elUser.asXml());
    root.addContent(new Element("site").setText(thisSite));
    root.addContent(new Element("siteURL").setText(siteURL));
    root.addContent(new Element("adminEmail").setText(adminEmail));
    root.addContent(new Element("password").setText(password));
   
View Full Code Here

        thesaurusDir = _applicationContext.getBean(ThesaurusManager.class).getThesauriDirectory();

        if (context.getUserSession() == null) {
            UserSession session = new UserSession();
            context.setUserSession(session);
            session.loginAs(new User().setUsername("admin").setId(-1).setProfile(Profile.Administrator));
        }
        // get lastchangedate of all metadata in index
        Map<String,String> docs = searchMan.getDocsChangeDate();

        // set up results HashMap for post processing of records to be indexed
View Full Code Here

            moreFields.add(SearchManager.makeField("_rating",      rating,      true, true));
            moreFields.add(SearchManager.makeField("_displayOrder",displayOrder, true, false));
            moreFields.add(SearchManager.makeField("_extra",       extra,       true, false));

            if (owner != null) {
                User user = _applicationContext.getBean(UserRepository.class).findOne(fullMd.getSourceInfo().getOwner());
                if (user != null) {
                    moreFields.add(SearchManager.makeField("_userinfo", user.getUsername() + "|" + user.getSurname() + "|" + user
                            .getName() + "|" + user.getProfile(), true, false));
                }
            }
            if (groupOwner != null) {
                moreFields.add(SearchManager.makeField("_groupOwner", groupOwner, true, true));
            }
View Full Code Here

        Map<String, Element> map = Maps.newHashMap();
        map.put(id, info);
        buildPrivilegesMetadataInfo(context, map);

        // add owner name
        User user = _applicationContext.getBean(UserRepository.class).findOne(owner);
        if (user != null) {
            String ownerName = user.getName();
            addElement(info, Edit.Info.Elem.OWNERNAME, ownerName);
        }


        for (MetadataCategory category : metadata.getCategories()) {
View Full Code Here

     * @throws Exception
     */
  public Set<Integer> getVisibleGroups(final int userId) throws Exception {
    Set<Integer> hs = new HashSet<Integer>();

        User user = _userRepository.findOne(userId);

    if (user == null) {
      return hs;
        }

    Profile profile = user.getProfile();

    List<Integer> groupIds;
    if (profile == Profile.Administrator) {
      groupIds = _groupRepository.findIds();
    } else {
      groupIds = _userGroupRepository.findGroupIds(UserGroupSpecs.hasUserId(user.getId()));
    }

        hs.addAll(groupIds);

    return hs;
View Full Code Here

        List<Pair<Integer, User>> results = _userRepository.findAllByGroupOwnerNameAndProfile(metadataIds,
                Profile.Reviewer, SortUtils.createSort(User_.name));

        Element resultEl = new Element("results");
        for (Pair<Integer, User> integerUserPair : results) {
            User user = integerUserPair.two();
            resultEl.addContent(new Element("record").
                    addContent(new Element("userid").setText(user.getId() + "")).
                    addContent(new Element("name").setText(user.getName())).
                    addContent(new Element("surname").setText(user.getSurname())).
                    addContent(new Element("email").setText(user.getEmail()))
            );
        }
        return resultEl;
    }
View Full Code Here

    UserList exec() throws Exception {
        final SecurityContext context = SecurityContextHolder.getContext();
        if (context == null || context.getAuthentication() == null) {
            throw new AuthenticationCredentialsNotFoundException("User needs to log in");
        }
        User me = userRepository.findOneByUsername(context.getAuthentication().getName());

        if (me == null) {
            throw new AccessDeniedException(SecurityContextHolder.class.getSimpleName() + " has a user that is not in the database: " +
                                            context.getAuthentication());
        }

        Set<Integer> hsMyGroups = getGroups(me.getId(), me.getProfile());

        Collection<? extends GrantedAuthority> roles = me.getAuthorities();

        Set<String> profileSet = Sets.newHashSet();

        for (GrantedAuthority rol : roles) {
            profileSet.add(rol.getAuthority());
View Full Code Here

        final UserGroupRepository userGroupRepository = context.getBean(UserGroupRepository.class);

        if (myProfile == Profile.Administrator || myProfile == Profile.UserAdmin || myUserId.equals(id)) {

      // -- get the profile of the user id supplied
            User user = userRepository.findOne(Integer.valueOf(id));
      if (user == null) {
        throw new IllegalArgumentException("user "+id+" doesn't exist");
            }

      String  theProfile = user.getProfile().name();

      //--- retrieve user groups of the user id supplied
      Element elGroups = new Element(Geonet.Elem.GROUPS);
      List<Group> theGroups;
            List<UserGroup> userGroups;
View Full Code Here

    if (userId == null)
      throw new UserNotFoundEx(null);

        final UserRepository userRepository = context.getBean(UserRepository.class);
        final User user = userRepository.findOne(userId);

        user.setName(name)
                .setKind(kind)
                .setOrganisation(organ)
                .setSurname(surname);
        user.getPrimaryAddress()
                .setAddress(address)
                .setCity(city)
                .setCountry(country)
                .setState(state)
                .setZip(zip);
        user.getEmailAddresses().clear();
        user.getEmailAddresses().add(email);

        userRepository.save(user);

    return new Element(Jeeves.Elem.RESPONSE);
  }
View Full Code Here

TOP

Related Classes of org.fao.geonet.domain.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.