Package org.fao.geonet.repository

Examples of org.fao.geonet.repository.UserRepository


    if (!us.isAuthenticated())
      return new ArrayList<Element>();

    int userId = Integer.parseInt(us.getUserId());

        final UserRepository userRepository = context.getBean(UserRepository.class);
        if (us.getProfile() == Profile.Administrator) {
      @SuppressWarnings("unchecked")
            List<Element> allUsers = userRepository.findAllAsXml().getChildren();
            return allUsers;
    }

    if (us.getProfile() != Profile.UserAdmin) {
            @SuppressWarnings("unchecked")
            List<Element> identifiedUsers = userRepository.findAllAsXml(UserSpecs.hasUserId(userId)).getChildren();;
            return identifiedUsers;
        }

    //--- we have a user admin

    Set<Integer> hsMyGroups = getUserGroups(context, userId);

        Set<String> profileSet = us.getProfile().getAllNames();

    //--- retrieve all users

    Element elUsers = userRepository.findAllAsXml(null, SortUtils.createSort(User_.name));

    //--- now filter them

    ArrayList<Element> alToRemove = new ArrayList<Element>();
View Full Code Here


     * @param changeMessage Message supplied by the user that set the status
     */
    protected void informContentReviewers(Set<Integer> metadata, String changeDate, String changeMessage) throws Exception {

        // --- get content reviewers (sorted on content reviewer userid)
        UserRepository userRepository = context.getBean(UserRepository.class);
        List<Pair<Integer, User>> results = userRepository.findAllByGroupOwnerNameAndProfile(metadata,
                Profile.Reviewer, SortUtils.createSort(User_.name));

        List<User> users = Lists.transform(results, new Function<Pair<Integer, User>, User>() {
            @Nullable
            @Override
View Full Code Here

                translatedStatusName, replyToDescr, replyTo, changeDate);
        String mdChanged = buildMetadataChangedMessage(metadataIds);
       
        Iterable<Metadata> metadata = this.context.getBean(MetadataRepository.class).findAll(metadataIds);
        List<User> owners = new ArrayList<User>();
        UserRepository userRepo = this.context.getBean(UserRepository.class);

        for (Metadata md : metadata) {
            int ownerId = md.getSourceInfo().getOwner();
            owners.add(userRepo.findOne(ownerId));
        }

        processList(owners, subject, status, changeDate, changeMessage, mdChanged);

    }
View Full Code Here

   * @throws SQLException if an error occurred during a database access
   * @throws UserNotFoundEx  if the id does not reference a user
   */
  public static User updatePasswordWithNew(boolean matchOldPassword, String oldPassword,
      String newPassword, Integer iUserId, ApplicationContext appContext) throws SQLException, UserNotFoundEx {
      UserRepository repo = appContext.getBean(UserRepository.class);
        User user = repo.findOne(iUserId);
        if (user == null) {
            throw new UserNotFoundEx(""+iUserId);
        }

        PasswordEncoder encoder = encoder(appContext);
View Full Code Here

    // TODO: I am not sure this is the expected behaviour: allowing people to create
    // even temporary account as administrator, just noticing the admin catalogue
    // might be a dangerous behaviour.

    final UserRepository userRepository = svcCtx.getBean(UserRepository.class);
    User newUsr = userRepository.findOneByEmail("root@localhost");
       
    assertTrue (newUsr.getProfile() == Profile.Administrator);
   
  }
View Full Code Here

        }
    }

    private void saveUser(LDAPUser userDetails) {
        try {
            UserRepository userRepo = applicationContext.getBean(UserRepository.class);
            GroupRepository groupRepo = applicationContext.getBean(GroupRepository.class);
            UserGroupRepository userGroupRepo = applicationContext.getBean(UserGroupRepository.class);
            LDAPUtils.saveUser(userDetails, userRepo, groupRepo, userGroupRepo, importPrivilegesFromLdap, createNonExistingLdapGroup);
        } catch (Exception e) {
            throw new AuthenticationServiceException(
View Full Code Here

            usernames.add(username);
        }

        // Remove LDAP user available in db and not in LDAP if not linked to
        // metadata
        final UserRepository userRepository = applicationContext.getBean(UserRepository.class);
        final UserGroupRepository userGroupRepository = applicationContext.getBean(UserGroupRepository.class);
        final Specifications<User> spec = Specifications.where(
                UserSpecs.hasAuthType(LDAPConstants.LDAP_FLAG)
        ).and(
                Specifications.not(UserSpecs.userIsNameNotOneOf(usernames))
        );

        final List<User> usersFound = userRepository.findAll(spec);
        Collection<Integer> userIds = Collections2.transform(usersFound, new Function<User, Integer>() {
            @Nullable
            @Override
            public Integer apply(@Nonnull User input) {
                return input.getId();
            }
        });
        userGroupRepository.deleteAllByIdAttribute(UserGroupId_.userId, userIds);
        userRepository.deleteInBatch(usersFound);
    }
View Full Code Here

        if (group.equals("")) {
            group = defGroup;
        }

        UserRepository userRepository = context.getBean(UserRepository.class);

        // Create or update the user
        if (username != null && username.length() > 0) {
            User user = updateUser(context, userRepository, username, surname, firstname, profile, group);
View Full Code Here

        Element element = new Element(Jeeves.Elem.RESPONSE);
        element.setAttribute(Params.SURNAME, surname);
        element.setAttribute(Params.NAME, name);
        element.setAttribute(Params.EMAIL, email);

        final UserRepository userRepository = context.getBean(UserRepository.class);
        if (userRepository.findOneByEmail(email) != null) {
            return element.addContent(new Element("result").setText("errorEmailAddressAlreadyRegistered"));
        }

        // 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.
        UserGroup userGroup = new UserGroup().setUser(user).setGroup(group).setProfile(Profile.RegisteredUser);
        context.getBean(UserGroupRepository.class).save(userGroup);
View Full Code Here

    String password = Util.getParam(params, Params.PASSWORD);
    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());
View Full Code Here

TOP

Related Classes of org.fao.geonet.repository.UserRepository

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.