Examples of UserRepository


Examples of org.fao.geonet.repository.UserRepository

        }
    }

    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

Examples of org.fao.geonet.repository.UserRepository

            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

Examples of org.fao.geonet.repository.UserRepository

        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

Examples of org.fao.geonet.repository.UserRepository

        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

Examples of org.fao.geonet.repository.UserRepository

    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

Examples of org.fao.geonet.repository.UserRepository

    String      userId  = session.getUserId();

    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

Examples of org.fao.geonet.repository.UserRepository

        UserSession usrSess = context.getUserSession();
        Profile myProfile = usrSess.getProfile();
        String      myUserId  = usrSess.getUserId();

        final UserGroupRepository groupRepository = context.getBean(UserGroupRepository.class);
        final UserRepository userRepository = context.getBean(UserRepository.class);
        @SuppressWarnings("unchecked")
        java.util.List<Element> userGroups = params.getChildren(Params.GROUPS);

        if (profile == Profile.Administrator) {
            userGroups = new ArrayList<Element>();
        }

        if (myProfile == Profile.Administrator ||
        myProfile == Profile.UserAdmin ||
        myUserId.equals(id)) {
            checkAccessRights(operation, id, username, myProfile, myUserId, userGroups, groupRepository);


            User user = getUser(userRepository, operation, id, username);
            if (username != null) {
                user.setUsername(username);
            }

            if (name != null) {
                user.setName(name);
            }
            if (surname != null) {
                user.setSurname(surname);
            }

            if (profile != null) {
                if (!myProfile.getAll().contains(profile)) {
                    throw new IllegalArgumentException("Trying to set profile to "+profile+" max profile permitted is: "+myProfile);
                }
                user.setProfile(profile);
            }
            if (kind != null) {
                user.setKind(kind);
            }
            if (organ != null) {
                user.setOrganisation(organ);
            }

            Address addressEntity;
            boolean hasNoAddress = user.getAddresses().isEmpty();
            if (hasNoAddress) {
                addressEntity = new Address();
            } else {
                addressEntity = user.getAddresses().iterator().next();

            }
            if (address != null) {
                addressEntity.setAddress(address);
            }
            if (city != null) {
                addressEntity.setCity(city);
            }
            if (state != null) {
                addressEntity.setState(state);
            }
            if (zip != null) {
                addressEntity.setZip(zip);
            }
            if (country != null) {
                addressEntity.setCountry(country);
            }

            if (hasNoAddress) {
                user.getAddresses().add(addressEntity);
            }

            if (email != null) {
                user.getEmailAddresses().add(email);
            }


            if (password != null) {
                user.getSecurity().setPassword(PasswordUtil.encode(context, password));
            } else if (operation.equals(Params.Operation.RESETPW)) {
                throw new IllegalArgumentException("password is a required parameter for operation: " + Params.Operation.RESETPW);
            }

            // -- For adding new user
            if (operation.equals(Params.Operation.NEWUSER)) {
                user = userRepository.save(user);

        setUserGroups(user, params, context);
      } else if (operation.equals(Params.Operation.FULLUPDATE) || operation.equals(Params.Operation.EDITINFO)) {
                user = userRepository.save(user);

                //--- add groups
                groupRepository.deleteAllByIdAttribute(UserGroupId_.userId, Arrays.asList(user.getId()));

                setUserGroups(user, params, context);
      } else if (operation.equals(Params.Operation.RESETPW)) {
             user = userRepository.save(user);
      } else {
                throw new IllegalArgumentException("unknown user update operation " + operation);
            }
    } else {
      throw new IllegalArgumentException("You don't have rights to do this");
View Full Code Here

Examples of org.fao.geonet.repository.UserRepository

    UserSession usrSess = context.getUserSession();
    Profile myProfile = usrSess.getProfile();
    String      myUserId  = usrSess.getUserId();

        final UserRepository userRepository = context.getBean(UserRepository.class);
        final GroupRepository groupRepository = context.getBean(GroupRepository.class);
        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();
View Full Code Here

Examples of org.superbiz.deltaspike.repository.UserRepository

    {
        final String userName = "gp";
        final String firstName = "Gerhard";
        final String lastName = "Petracek";

        UserRepository mockedUserRepository = mock(JpaUserRepository.class); //don't use the interface here to avoid issues with mockito and cdi proxies
        when(mockedUserRepository.loadUser(userName)).thenReturn(new User(userName, firstName, lastName.toUpperCase() /*just to illustrate that the mock-instance is used*/));
        mockManager.addMock(mockedUserRepository);


        this.windowContext.activateWindow("testWindow");

View Full Code Here

Examples of org.superbiz.deltaspike.repository.UserRepository

        final String firstName = "Gerhard";
        final String lastName = "Petracek";

        // mockito doesn't support interfaces...seriously? but you can mock CDI impl
        // here we don't have one so implementing for the test the interface
        UserRepository mockedUserRepository = (UserRepository) Proxy.newProxyInstance(
                Thread.currentThread().getContextClassLoader(),
                new Class<?>[]{ UserRepository.class},
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.