Package ca.carleton.gcrc.auth.common

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


 

  public JSONObject userInfoFromId(int id) throws Exception {
    JSONObject result = new JSONObject();
   
    User user = userFromId(id);
    result.put("display", user.getDisplayName());
    result.put("anonymous", user.isAnonymous());
    result.put("admin", user.isAdmin());
   
    return result;
  }
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

    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

  private void checkAuthentication(
      HttpServletRequest request,
      HttpServletResponse response,
      FilterChain chain) throws Exception {
    String[] userNameAndPassword = null;
    User user = null;
    if (request instanceof AuthHttpServletRequest) {
     
      user = AuthenticationUtils.getUserFromRequest(request);
      checkAndDispatch(user, request, response, chain);
     
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

  private void checkAuthentication(
      HttpServletRequest request,
      HttpServletResponse response,
      FilterChain chain) throws Exception {
    String[] userNameAndPassword = null;
    User user = null;
    if (request instanceof AuthHttpServletRequest) {
     
      user = AuthenticationUtils.getUserFromRequest(request);
      checkAndDispatch(user, request, response, chain);
     
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.