Package org.ngrinder.model

Examples of org.ngrinder.model.User


   * org.springframework.web.bind.support.WebDataBinderFactory)
   */
  @Override
  public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
      NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
    User currentUser = getUserContext().getCurrentUser();

    String userParam = webRequest.getParameter("ownerId");
    if (StringUtils.isNotBlank(userParam) && currentUser.getRole().hasPermission(Permission.SWITCH_TO_ANYONE)) {
      return getUserService().getOne(userParam);
    }

    // User want to do something through other User status and this
    // switchUser is other user Id
    String switchUser = null;
    Cookie[] cookies = getCookies(webRequest);
    if (cookies != null) {
      for (Cookie cookie : cookies) {
        if ("switchUser".equals(cookie.getName()) && cookie.getMaxAge() != 0) {
          switchUser = cookie.getValue();
        }
      }
    }
    // Let this can be done with parameter as well.
    switchUser = StringUtils.defaultIfBlank(webRequest.getParameter("switchUser"), switchUser);
   
    if (currentUser.getUserId().equals(switchUser)) {
      currentUser.setOwnerUser(null);
    } else if (StringUtils.isNotEmpty(switchUser)) {
      User ownerUser = getUserService().getOne(switchUser);
      // CurrentUser should remember whose status he used
      if (currentUser.getRole().hasPermission(Permission.SWITCH_TO_ANYONE)
          || (ownerUser.getFollowers() != null && ownerUser.getFollowers().contains(currentUser))) {
        currentUser.setOwnerUser(ownerUser);
        return ownerUser;
      }
    } else if (StringUtils.isEmpty(switchUser)) {
      currentUser.setOwnerUser(null);
View Full Code Here


   * @param securedUser
   *            user
   */
  @Transactional
  public void addNewUserIntoLocal(SecuredUser securedUser) {
    User user = securedUser.getUser();
    user.setAuthProviderClass(securedUser.getUserInfoProviderClass());
    user.setCreatedDate(new Date());
    User newUser = userService.getOne(user.getUserId());
    if (newUser != null) {
      user = newUser.merge(user);
    }
    if (user.getRole() == null) {
      user.setRole(Role.USER);
    }
    User savedUser = userService.save(user);
    securedUser.setUser(savedUser);
  }
View Full Code Here

      return getCurrentUser();
    } catch (AuthenticationCredentialsNotFoundException e) {
      // Fall through
      noOp();
    }
    return new User();
  }
View Full Code Here

  }

  private void resetAdminPasswordIfNecessary() {
    if (config.getControllerProperties().getPropertyBoolean(ControllerConstants
        .PROP_CONTROLLER_ADMIN_PASSWORD_RESET)) {
      final User admin = userRepository.findOneByUserId("admin");
      if (admin == null) {
        createUser("admin", "admin", Role.ADMIN, "admin", "admin@nhn.com");
      } else {
        SecuredUser securedUser = new SecuredUser(admin, null);
        Object salt = saltSource.getSalt(securedUser);
        admin.setRole(Role.ADMIN);
        admin.setPassword(passwordEncoder.encodePassword("admin", salt));
        userRepository.saveAndFlush(admin);
      }
    }
  }
View Full Code Here

   * @param userName user name
   * @param email    email
   */
  private void createUser(String userId, String password, Role role, String userName, String email) {
    if (userRepository.findOneByUserId(userId) == null) {
      User user = new User();
      user.setUserId(userId);
      SecuredUser securedUser = new SecuredUser(user, null);
      Object salt = saltSource.getSalt(securedUser);
      user.setPassword(passwordEncoder.encodePassword(password, salt));
      user.setRole(role);
      user.setUserName(userName);
      user.setEmail(email);
      user.setCreatedDate(new Date());
      user = userRepository.save(user);
      fileEntryService.prepare(user);
    }

  }
View Full Code Here

   * @param securedUser
   *            user
   */
  @Transactional
  public void addNewUserIntoLocal(SecuredUser securedUser) {
    User user = securedUser.getUser();
    user.setAuthProviderClass(securedUser.getUserInfoProviderClass());
    user.setCreatedDate(new Date());
    User findOneByUserId = userService.getOne(user.getUserId());
    if (findOneByUserId != null) {
      user = findOneByUserId.merge(user);
    }
    if (user.getRole() == null) {
      user.setRole(Role.USER);
    }
    User savedUser = userService.save(user);
    securedUser.setUser(savedUser);
  }
View Full Code Here

    }
    if (!(authentication.getPrincipal() instanceof SecuredUser)) {
      return ACCESS_DENIED;
    }
    SecuredUser secureUser = cast(authentication.getPrincipal());
    User user = secureUser.getUser();
    if (user.getRole() == Role.ADMIN) {
      return ACCESS_GRANTED;
    }

    String realm = StringUtils.split(filter.getHttpRequest().getPathInfo(), '/')[0];
    if (secureUser.getUsername().equals(realm)) {
      return ACCESS_GRANTED;
    } else {
      List<User> owners = user.getOwners();
      for (User each : owners) {
        if (realm.equals(each.getUserId())) {
          return ACCESS_GRANTED;
        }
      }
View Full Code Here

  private DefaultLoginPlugin defaultPlugin;

  @Override
  public UserDetails loadUserByUsername(String userId) {
    for (OnLoginRunnable each : getPluginManager().getEnabledModulesByClass(OnLoginRunnable.class, defaultPlugin)) {
      User user = each.loadUser(userId);
      if (user != null) {
        checkNotEmpty(user.getUserId(), "User info's userId provided by " + each.getClass().getName()
            + " should not be empty");
        checkNotEmpty(user.getUserName(), "User info's userName provided by " + each.getClass().getName()
            + " should not be empty");
        return new SecuredUser(user, user.getAuthProviderClass());
      }
    }
    throw new UsernameNotFoundException(userId + " is not found.");
  }
View Full Code Here

TOP

Related Classes of org.ngrinder.model.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.