Package org.fao.geonet.domain

Examples of org.fao.geonet.domain.User


    }

    @Test
    public void testExecAsWithGroups() throws Exception {
        final Group group = _groupRepo.save(GroupRepositoryTest.newGroup(inc));
        User user1 = UserRepositoryTest.newUser(inc);
        user1.setProfile(Profile.Editor);
        user1 = _userRepo.save(user1);

        User user2 = UserRepositoryTest.newUser(inc);
        user2.setProfile(Profile.RegisteredUser);
        user2 = _userRepo.save(user2);

        _userGroupRepo.save(new UserGroup().setGroup(group).setUser(user1).setProfile(Profile.Editor));
        _userGroupRepo.save(new UserGroup().setGroup(group).setUser(user2).setProfile(Profile.RegisteredUser));
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

  @Override
  protected void additionalAuthenticationChecks(UserDetails userDetails,
      UsernamePasswordAuthenticationToken authentication)
      throws AuthenticationException {
    User gnDetails = (User) userDetails;
       
    if (authentication.getCredentials() == null) {
      Log.warning(Log.JEEVES, "Authentication failed: no credentials provided");
      throw new BadCredentialsException("Authentication failed: no credentials provided");
    }

    if (!encoder.matches(authentication.getCredentials().toString(), gnDetails.getPassword())) {
      Log.warning(Log.JEEVES, "Authentication failed: wrong password provided");
      throw new BadCredentialsException("Authentication failed: wrong password provided");
    }
  }
View Full Code Here

  protected UserDetails retrieveUser(String username,
      UsernamePasswordAuthenticationToken authentication)
      throws AuthenticationException {
      try {
      // Only check user with local db user (ie. authtype is '')
          User user = _userRepository.findOneByUsernameAndSecurityAuthTypeIsNullOrEmpty(username);
            if (user == null && checkUserNameOrEmail) {
                user = _userRepository.findOneByEmailAndSecurityAuthTypeIsNullOrEmpty(username);
            }
      if (user != null) {
        if (authentication != null && authentication.getCredentials() != null) {
          if(PasswordUtil.hasOldHash(user)) {
            String oldPassword = user.getPassword();
            String newPassword = authentication.getCredentials().toString();
                        user = PasswordUtil.updatePasswordWithNew(true, oldPassword, newPassword, user, encoder, _userRepository);
          }
        }

                if (authentication != null && authentication.getDetails() instanceof JeevesAuthenticationDetails) {
                    user.getSecurity().setNodeId(((JeevesAuthenticationDetails) authentication.getDetails()).getNodeId());
                }

        return user;
      }
    } catch (Exception e) {
View Full Code Here

        Map<String, ArrayList<String>> userInfo = LDAPUtils
                .convertAttributes(userCtx.getAttributes().getAll());

        LDAPUser userDetails = new LDAPUser(username);
        User user = userDetails.getUser();
        user.setName(getUserInfo(userInfo, "name"))
                .setSurname(getUserInfo(userInfo, "surname"))
                .setOrganisation(getUserInfo(userInfo, "organisation"));
        user.getEmailAddresses().clear();
        user.getEmailAddresses().add(getUserInfo(userInfo, "mail"));
        user.getPrimaryAddress()
                .setAddress(getUserInfo(userInfo, "address"))
                .setState(getUserInfo(userInfo, "state"))
                .setZip(getUserInfo(userInfo, "zip"))
                .setCity(getUserInfo(userInfo, "city"))
                .setCountry(getUserInfo(userInfo, "country"));

        // Set privileges for the user. If not, privileges are handled
        // in local database
        if (importPrivilegesFromLdap) {
            setProfilesAndPrivileges(defaultProfile, defaultGroup, userInfo, userDetails);
        }

        // Assign default profile if not set by LDAP info or local database
        if (user.getProfile() == null) {
            user.setProfile(defaultProfile);
        }

        saveUser(userDetails);

        return userDetails;
View Full Code Here

                try {
                    UserDetails userDetails = (UserDetails) e
                            .getAuthentication().getPrincipal();

                    User user = _userRepository.findOneByUsername(userDetails.getUsername());
                    user.setLastLoginDate(new ISODate().toString());
                    _userRepository.save(user);

                } catch (Exception ex) {
                    // TODO: Log exception
                    ex.printStackTrace();
View Full Code Here

        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);

            UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(user.getUsername(), null,
                    user.getAuthorities());
            authentication.setDetails(user);

            if (SecurityContextHolder.getContext() == null) {
                SecurityContextHolder.createEmptyContext();
            }
            SecurityContextHolder.getContext().setAuthentication(authentication);

            context.info("User '" + username + "' logged in as '" + user.getProfile() + "'");

            return new Element("ok");
        } else {
            throw new UserLoginEx(username);
        }
View Full Code Here

        // --- update user information into the database
        if (username.length() > 256) // only accept the first 256 chars
        {
            username = username.substring(0, 256);
        }
        User user = userRepository.findOneByUsername(username);

        if (user == null) {
            user = new User().setUsername(username);
        }

        user.setName(firstname).setSurname(surname).setProfile(profile).getSecurity().setPassword(VIA_SHIBBOLETH.toCharArray())
                .setAuthType(SHIBBOLETH_FLAG);

        userRepository.save(user);

        if (groupProvided) {
View Full Code Here

        session.setProperty(Geonet.Session.FILE_DISCLAIMER, resourceData);

        //--- now get the users name, organisation and email address to
        //--- prepopulate the feedback form (if they are logged in)
        if (session.getUserId() != null) {
            User user = context.getBean(UserRepository.class).findOne(session.getUserIdAsInt());
            if (user != null) {
                Element elRec = user.asXml();
                elBrief.setName("record");
                response.addContent(elRec.cloneContent());
            }
        }
View Full Code Here

      throws Exception {

    String username = Util.getParam(params, Params.USERNAME);
    String template = Util.getParam(params, Params.TEMPLATE, CHANGE_EMAIL_XSLT);

        final User user = context.getBean(UserRepository.class).findOneByUsername(username);
    if (user == null) {
      throw new UserNotFoundEx(username);
        }

    // only let registered users change their password 
    if (user.getProfile() != Profile.RegisteredUser) {
      // Don't throw OperationNotAllowedEx because it is not related to not having enough priviledges
      throw new IllegalArgumentException("Only users with profile RegisteredUser can change their password using this option");
        }

    // get mail settings   
    GeonetContext  gc = (GeonetContext) context.getHandlerContext(Geonet.CONTEXT_NAME);
    SettingManager sm = gc.getBean(SettingManager.class);

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

    SettingInfo si = context.getBean(SettingInfo.class);
    String siteURL = si.getSiteUrl() + context.getBaseUrl();

    // construct change key - only valid today
    String scrambledPassword = user.getPassword();
    Calendar cal = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
    String todaysDate = sdf.format(cal.getTime());
    String changeKey = PasswordUtil.encode(context, scrambledPassword+todaysDate);

    // generate email details using customisable stylesheet
    // TODO: allow internationalised emails
    Element root = new Element("root");
    root.addContent(new Element("username").setText(username));
        for (String email : user.getEmailAddresses()) {
            root.addContent(new Element("email").setText(email));
        }
    root.addContent(new Element("site").setText(thisSite));
    root.addContent(new Element("siteURL").setText(siteURL));
    root.addContent(new Element("changeKey").setText(changeKey));
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.