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

  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

 

  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

      sendErrorResponse(response, e);
    }
  }
 
  private void performGetSchema(HttpServletRequest request, HttpServletResponse response) throws Exception {
    User user = AuthenticationUtils.getUserFromRequest(request);
    String tableName = getTableNameFromRequest(request);
   
    DbTableAccess tableAccess = DbTableAccess.getAccess(dbSecurity, tableName, new DbUserAdaptor(user));
    JSONObject schema = tableAccess.getSchema();
   
View Full Code Here

   
    sendJsonResponse(response, schema);
  }
 
  private void performGetCapabilities(HttpServletRequest request, HttpServletResponse response) throws Exception {
    User user = AuthenticationUtils.getUserFromRequest(request);

    List<TableSchema> tableSchemas = dbSecurity.getAvailableTablesFromGroups( new DbUserAdaptor(user) );

    JSONArray array = new JSONArray();
    for(TableSchema schema : tableSchemas) {
View Full Code Here

   * @param request http request containing the query parameters.
   * @param response http response to be sent.
   * @throws Exception (for a variety of reasons detected while parsing and validating the http parms).
   */
  private void performQuery(HttpServletRequest request, HttpServletResponse response) throws Exception {
    User user = AuthenticationUtils.getUserFromRequest(request);
    String tableName = getTableNameFromRequest(request);
   
    DbTableAccess tableAccess = DbTableAccess.getAccess(dbSecurity, tableName, new DbUserAdaptor(user));
   
    List<RecordSelector> whereMap = getRecordSelectorsFromRequest(request);
View Full Code Here

   * @param request http request containing the query parameters.
   * @param response http response to be sent.
   * @throws Exception (for a variety of reasons detected while parsing and validating the http parms).
   */
  private void performMultiQuery(HttpServletRequest request, HttpServletResponse response) throws Exception {
    User user = AuthenticationUtils.getUserFromRequest(request);

    String[] queriesStrings = request.getParameterValues("queries");
    if( 1 != queriesStrings.length ) {
      throw new Exception("Parameter 'queries' must be specified exactly oncce");
    }
View Full Code Here

    return query;
  }

  private void performInsert(HttpServletRequest request, HttpServletResponse response) throws Exception {
    User user = AuthenticationUtils.getUserFromRequest(request);
    String tableName = getTableNameFromRequest(request);
   
    DbTableAccess tableAccess = DbTableAccess.getAccess(dbSecurity, tableName, new DbUserAdaptor(user));

    Map<String,String> setterMap = getSetParametersMap(request);
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.