Package com.agiletec.aps.system.services.user

Examples of com.agiletec.aps.system.services.user.UserDetails


  }

  private static boolean isVotedContentByCookie(String contentId, HttpServletRequest request) {
    Cookie[] cookies = request.getCookies();
    if (null == cookies) return false;
    UserDetails currentUser = (UserDetails) request.getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
    String expectedCookieName = getCookieName(currentUser.getUsername(),contentId);
    String expectedCookieValue = getCookieValue(currentUser.getUsername(), contentId);
    for (int i=0; i<cookies.length; i++) {
      Cookie cookie = cookies[i];
      if (cookie.getName().equals(expectedCookieName) && cookie.getValue().equals(expectedCookieValue)) {
        return true;
      }
View Full Code Here


  }

  private static boolean isVotedCommentByCookie(int commentId, HttpServletRequest request) {
    Cookie[] cookies = request.getCookies();
    if (null == cookies) return false;
    UserDetails currentUser = (UserDetails) request.getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
    String expectedCookieName = getCookieName(currentUser.getUsername(), commentId);
    String expectedCookieValue = getCookieValue(currentUser.getUsername(), commentId);
    for (int i=0; i<cookies.length; i++) {
      Cookie cookie = cookies[i];
      if (cookie.getName().equals(expectedCookieName) && cookie.getValue().equals(expectedCookieValue)) {
        return true;
      }
View Full Code Here

  protected boolean isValidVote() {
    return (null != this.getVote() && this.getVotes().values().contains(this.getVote()));
  }

  protected void addCookieRating(String contentId) {
    UserDetails currentUser = this.getCurrentUser();
    String cookieName = CheckVotingUtil.getCookieName(currentUser.getUsername(), contentId);
    String cookieValue = CheckVotingUtil.getCookieValue(currentUser.getUsername(), contentId);
    Cookie cookie = new Cookie(cookieName, cookieValue);
    cookie.setMaxAge(365*24*60*60);//one year
    this.getResponse().addCookie(cookie);
  }
View Full Code Here

    cookie.setMaxAge(365*24*60*60);//one year
    this.getResponse().addCookie(cookie);
  }

  protected void addCookieRating(int commentId) {
    UserDetails currentUser = this.getCurrentUser();
    String cookieName = CheckVotingUtil.getCookieName(currentUser.getUsername(), commentId);
    String cookieValue = CheckVotingUtil.getCookieValue(currentUser.getUsername(), commentId);
    Cookie cookie = new Cookie(cookieName, cookieValue);
    cookie.setMaxAge(365*24*60*60);//one year
    this.getResponse().addCookie(cookie);
  }
View Full Code Here

    String username = null;
    try {
      if (key instanceof String) {
        username = key.toString();
      } else if (key instanceof UserDetails) {
        UserDetails userDetails = (UserDetails) key;
        username = userDetails.getUsername();
      }
      username = username.toLowerCase();
      File fileToDelete = this.getAvatarResource(username);
      if (null != fileToDelete) {
        FileUtils.forceDelete(fileToDelete);
View Full Code Here

      } else {
        HttpServletRequest req = reqCtx.getRequest();
        HttpSession session = req.getSession();
        IPage currentPage =
          (IPage) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_PAGE);
        UserDetails currentUser =
          (UserDetails) session.getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
        boolean authorized = this.getAuthManager().isAuth(currentUser, currentPage);
        if (authorized) {
          retStatus = ControllerManager.CONTINUE;
        } else if (SystemConstants.GUEST_USER_NAME.equals(currentUser.getUsername())) {
          _log.info("CAS - user not authorized and guest");
          CasClientUtils casClientUtils = new CasClientUtils();
          String loginBaseUrl = this.getCasClientConfig().getCasLoginURL();
          StringBuilder loginUrl = new StringBuilder(loginBaseUrl);
          loginUrl.append("?service=");
View Full Code Here

          username = getAuthCommon().getUsernameFromPrincipal(name);
        }
        this._log.trace("Request From User with Username: " + username + " - info: AuthType " + req.getAuthType() + " " + req.getProtocol() + " " + req.getRemoteAddr() + " " + req.getRemoteHost());
        if (username != null) {
          this._log.trace("jpcasclient: user is " + username);
          UserDetails userOnSession = (UserDetails) session.getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
          if (userOnSession == null || (userOnSession != null && !username.equals(userOnSession.getUsername()))) {
            UserDetails user = this.getAuthenticationProvider().getUser(username);
            if (user != null) {
              if (!user.isAccountNotExpired()) {
                req.setAttribute("accountExpired", new Boolean(true));
              } else {
                if (userOnSession != null && !userOnSession.getUsername().equals(SystemConstants.GUEST_USER_NAME)) {
                  ((AbstractUser) user).setPassword(userOnSession.getPassword());
                }
                session.setAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER, user);
                this._log.trace("jpcasclient: new user: " + user.getUsername());
              }
            } else {
//                      req.setAttribute("wrongAccountCredential", new Boolean(true));
              /* create user on the fly */
              user = new User();
              ((User) user).setUsername(username);
              ((User) user).setPassword(CasClientPluginSystemCostants.JPCAS_RUNTIME_USER);
              ((User) user).setLastAccess(new Date());
              /* put in the session */
              session.setAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER, user);
              this._log.trace("jpcasclient: new user created on the fly: " + user.getUsername());
            }
          }
        }
      }

      //Punto 2
      String userName = req.getParameter("username");
      String password = req.getParameter("password");
      if (userName != null && password != null) {
        _log.trace("user " + userName + " - password ******** ");
        UserDetails user = this.getAuthenticationProvider().getUser(userName, password);
        if (user != null) {
          if (!user.isAccountNotExpired()) {
            req.setAttribute("accountExpired", new Boolean(true));
          } else {
            session.setAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER, user);
            _log.trace("Nuovo User: " + user.getUsername());
          }
        } else {
          req.setAttribute("wrongAccountCredential", new Boolean(true));
        }
      }

      //Punto 3
      if (session.getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER) == null) {
        UserDetails guestUser = this.getUserManager().getGuestUser();
        session.setAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER, guestUser);
      }
      retStatus = ControllerManager.CONTINUE;
    } catch (Throwable t) {
      ApsSystemUtils.logThrowable(t, this, "service", "Error in processing the request");
View Full Code Here

  public void test_no_auth() {
    RequestContext reqCtx = this.getRequestContext();
    int status = _authenticator.service(reqCtx, ControllerManager.CONTINUE);
    assertEquals(status, ControllerManager.CONTINUE);
    UserDetails currentUser = (UserDetails) reqCtx.getRequest().getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
    assertEquals(SystemConstants.GUEST_USER_NAME, currentUser.getUsername());
  }
View Full Code Here

    MockHttpServletRequest request = (MockHttpServletRequest) reqCtx.getRequest();
    request.setParameter("username", "admin");
    request.setParameter("password", "admin");
    int status = _authenticator.service(reqCtx, ControllerManager.CONTINUE);
    assertEquals(status, ControllerManager.CONTINUE);
    UserDetails currentUser = (UserDetails) request.getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
    assertEquals("admin", currentUser.getUsername());
  }
View Full Code Here

    MockHttpServletRequest request = (MockHttpServletRequest) reqCtx.getRequest();
    request.setParameter("user", "notauthorized");
    request.setParameter("password", "notauthorized");
    int status = _authenticator.service(reqCtx, ControllerManager.CONTINUE);
    assertEquals(status, ControllerManager.CONTINUE);
    UserDetails currentUser = (UserDetails) request.getSession().getAttribute(SystemConstants.SESSIONPARAM_CURRENT_USER);
    assertEquals(SystemConstants.GUEST_USER_NAME, currentUser.getUsername());
  }
View Full Code Here

TOP

Related Classes of com.agiletec.aps.system.services.user.UserDetails

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.