Package ca.carleton.gcrc.auth.common

Examples of ca.carleton.gcrc.auth.common.User


   
    logger.info("Login authorization: "+auth+" name:"+name+" adjustCookies: "+adjustCookies);
   
    if( null == auth ) {
      // No authentication provided. Assume default user.
      User user = userRepository.getDefaultUser();

      // If adjusting cookies, do not complain and return OK
      if( adjustCookies ) {
        acceptRequest(response, false, user);
       
      } else {
        // Inform client that authentication is required.
        rejectRequest(response);
      }
      return;
    }
   
    String[] userNameAndPassword = null;
    try {
      userNameAndPassword = AuthenticationUtils.getUserNameAndPassword(auth);
    } catch (Exception e) {
      throw new Exception("Unable to acquire user",e);
    }
   
    // An auth has been provided. Check that the auth corresponds to
    // the 'name' provided by the script. This is to avoid a situation
    // where the browser has changed its tokens, already learned from
    // the fact that this path is protected and supplies already known
    // credentials, ignoring the username and password provided in the
    // XmlHttpRequest
   
    if( false == adjustCookies ) {
      if( null == name ) {
        // We're not adjusting cookies, therefore we must know the
        // intended user
        throw new Exception("name parameter not provided");
      }
      if( false == name.equals( userNameAndPassword[0] ) ) {
        // The funny (interesting) situation has occurred.
        // Send back a 401 to get intended name and password
        rejectRequest(response);
        return;
      }
    }
   
    // From this point on, an auth has been provided for an intended
    // user. We do not want to return an error or else a pop-up box
    // from the browser (not javascript) will be displayed. Even if
    // login fails, return an OK status. The outcome of the login is
    // returned as a JSON object. Also, the cookie installed on the
    // client reflects a default user if the authentication fails.

    User user;
    boolean loggedIn = false;
    try {
      user = userRepository.authenticate(userNameAndPassword[0],userNameAndPassword[1]);
      loggedIn = true;
    } catch (Exception e) {
View Full Code Here


    // to return an error or else a pop-up box from the browser (not
    // javascript) will be displayed. At this point, we are logging out
    // so we are expecting bogus credentials and we should not check
    // them. Accept request as default user.
   
    User user = userRepository.getDefaultUser();
    acceptRequest(response, false, user);
  }
View Full Code Here

      logger.info("Unable to decode user name and password",e);
      return result;
    }

    // Fetch user from repository
    User user;
    try {
      user = userRepository.authenticate(userNameAndPassword[0],userNameAndPassword[1]);

      logger.info("user: "+user);
     
      result.user = user;
     
      if( allowAnonymous && user.isAnonymous() ) {
        result.allowed = true;
       
      } else if( allowAdmin && user.isAdmin() ) {
        result.allowed = true;
       
      } else if( allowUser && !user.isAdmin() && !user.isAnonymous() ) {
        result.allowed = true;
      }

    } catch (Exception e) {
     
View Full Code Here

   
    logger.info("Login authorization: "+auth+" name:"+name+" adjustCookies: "+adjustCookies);
   
    if( null == auth ) {
      // No authentication provided. Assume default user.
      User user = userRepository.getDefaultUser();

      // If adjusting cookies, do not complain and return OK
      if( adjustCookies ) {
        acceptRequest(response, false, user);
       
      } else {
        // Inform client that authentication is required.
        rejectRequest(response);
      }
      return;
    }
   
    String[] userNameAndPassword = null;
    try {
      userNameAndPassword = AuthenticationUtils.getUserNameAndPassword(auth);
    } catch (Exception e) {
      throw new Exception("Unable to acquire user",e);
    }
   
    // An auth has been provided. Check that the auth corresponds to
    // the 'name' provided by the script. This is to avoid a situation
    // where the browser has changed its tokens, already learned from
    // the fact that this path is protected and supplies already known
    // credentials, ignoring the username and password provided in the
    // XmlHttpRequest
   
    if( false == adjustCookies ) {
      if( null == name ) {
        // We're not adjusting cookies, therefore we must know the
        // intended user
        throw new Exception("name parameter not provided");
      }
      if( false == name.equals( userNameAndPassword[0] ) ) {
        // The funny (interesting) situation has occurred.
        // Send back a 401 to get intended name and password
        rejectRequest(response);
        return;
      }
    }
   
    // From this point on, an auth has been provided for an intended
    // user. We do not want to return an error or else a pop-up box
    // from the browser (not javascript) will be displayed. Even if
    // login fails, return an OK status. The outcome of the login is
    // returned as a JSON object. Also, the cookie installed on the
    // client reflects a default user if the authentication fails.

    User user;
    boolean loggedIn = false;
    try {
      user = userRepository.authenticate(userNameAndPassword[0],userNameAndPassword[1]);
      loggedIn = true;
    } catch (Exception e) {
View Full Code Here

    // to return an error or else a pop-up box from the browser (not
    // javascript) will be displayed. At this point, we are logging out
    // so we are expecting bogus credentials and we should not check
    // them. Accept request as default user.
   
    User user = userRepository.getDefaultUser();
    acceptRequest(response, false, user);
  }
View Full Code Here

    HttpServletRequest request = (HttpServletRequest)servletRequest;
    HttpServletResponse response = (HttpServletResponse)servletResponse;
   
    if( request instanceof AuthHttpServletRequest ) {
      try {
        User user = AuthenticationUtils.getUserFromRequest(request);
        checkAndDispatch(user, request, response, chain);
      } catch (Exception e) {
        throw new ServletException("Error while filtering AuthHttpServletRequest",e);
      }
     
    } else {
      try {
        // Validate cookie and obtain user from it
        User user = null;
        {
          Cookie cookie = getCookieFromRequest(request);
          if( null != cookie ) {
            user = CookieAuthentication.verifyCookieString(userRepository, cookie.getValue());
          }
View Full Code Here

   
    if( null == name || null == password ) {
      throw new Exception("name or password missing");
    }
   
    User user;
    try {
      user = userRepository.authenticate(name,password);
    } catch (Exception e) {
      throw new Exception("Invalid credentials");
    }
View Full Code Here

    acceptRequest(response, true, user);
  }

  private void performLogout(HttpServletRequest request, HttpServletResponse response) throws Exception {

    User user = userRepository.getDefaultUser();
    acceptRequest(response, false, user);
  }
View Full Code Here

   * @throws IOException
   */
  private void performAdjustCookies(HttpServletRequest request, HttpServletResponse response) throws Exception {

    boolean loggedIn = false;
    User user = null;
    try {
      Cookie cookie = getCookieFromRequest(request);
      if( null != cookie ) {
        user = CookieAuthentication.verifyCookieString(userRepository, cookie.getValue());
        loggedIn = true;
View Full Code Here

    if( 0 != version ) {
      throw new Exception("Unknown version of auth cookie string");
    }
   
    // Get user
    User user = null;
    {
      user = userRepository.userFromId(userId);
      if( null == user ) {
        throw new Exception("Can not find user from auth cookie string");
      }
View Full Code Here

TOP

Related Classes of ca.carleton.gcrc.auth.common.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.