Package weave.config

Examples of weave.config.ConnectionConfig$DatabaseConfigInfo


    return getConnectionInfo(user, password).is_superuser;
  }
 
  private ConnectionInfo getConnectionInfo(String user, String password) throws RemoteException
  {
    ConnectionConfig connConfig = getConnectionConfig();
    ConnectionInfo info = connConfig.getConnectionInfo(user);
    if (info == null || password == null || !password.equals(info.pass))
    {
      System.out.println(String.format("authenticate failed, name=\"%s\" pass=\"%s\"", user, password));
      throw new RemoteException("Incorrect username or password.");
    }
View Full Code Here


  public String[] getConnectionNames(String user, String password)
    throws RemoteException
  {
    try
    {
      ConnectionConfig config = getConnectionConfig();
      // only check password and superuser privileges if dbInfo is valid
      if (config.getDatabaseConfigInfo() != null)
      {
        // non-superusers can't get connection info for other users
        if (!getConnectionInfo(user, password).is_superuser)
          return new String[] { user };
      }
      // otherwise, return all connection names
      String[] connectionNames = config.getConnectionInfoNames().toArray(new String[0]);
      Arrays.sort(connectionNames, String.CASE_INSENSITIVE_ORDER);
      return connectionNames;
    }
    catch (RemoteException se)
    {
View Full Code Here

    newConnectionInfo.is_superuser = true;
    newConnectionInfo.connectString = connectString;

    // if there are existing connections and DatabaseConfigInfo exists,
    // check the password. otherwise, allow anything.
    ConnectionConfig config = getConnectionConfig();
   
    if (config.getConnectionInfoNames().size() > 0 && config.getDatabaseConfigInfo() != null)
    {
      authenticate(currentUser, currentPass);

      // non-superusers can't save connection info
      if (!config.getConnectionInfo(currentUser).is_superuser)
        throw new RemoteException(String.format(
            "User \"%s\" does not have permission to modify connections.", currentUser));
      // is_superuser for the new connection will only be false if there
      // is an existing superuser connection and grantSuperuser is false.
      newConnectionInfo.is_superuser = grantSuperuser;
    }

    // test connection only - to validate parameters
    Connection conn = null;
    try
    {
      conn = newConnectionInfo.getConnection();
      SQLUtils.testConnection(conn);
    }
    catch (Exception e)
    {
      throw new RemoteException(
          String.format("The connection named \"%s\" was not created because the server could not"
              + " connect to the specified database with the given parameters.", newConnectionInfo.name),
          e);
    }
    finally
    {
      // close the connection, as we will not use it later
      SQLUtils.cleanup(conn);
    }

    // if the connection already exists AND overwrite == false throw error
    if (!configOverwrite && config.getConnectionInfoNames().contains(newConnectionInfo.name))
    {
      throw new RemoteException(String.format(
          "The connection named \"%s\" already exists.  Action cancelled.", newConnectionInfo.name));
    }

    // generate config connection entry
    try
    {
      // do not delete if this is the last user (which must be a
      // superuser)
      Collection<String> connectionNames = config.getConnectionInfoNames();

      // check for number of superusers
      int numSuperUsers = 0;
      for (String name : connectionNames)
      {
        if (config.getConnectionInfo(name).is_superuser)
          ++numSuperUsers;
        if (numSuperUsers >= 2)
          break;
      }
      // sanity check
      if (Strings.equal(currentUser, newUser) && numSuperUsers == 1 && !newConnectionInfo.is_superuser)
        throw new RemoteException("Cannot remove superuser privileges from last remaining superuser.");

      config.saveConnectionInfo(newConnectionInfo);
    }
    catch (Exception e)
    {
      e.printStackTrace();
      throw new RemoteException(String.format(
View Full Code Here

    if (!getConnectionInfo(loginUser, loginPassword).is_superuser)
      throw new RemoteException("Only superusers can remove connections.");

    try
    {
      ConnectionConfig config = getConnectionConfig();
     
      if (!config.getConnectionInfoNames().contains(userToRemove))
        throw new RemoteException("Connection \"" + userToRemove + "\" does not exist.");
     
      // disallow removing databaseConfig connection
      DatabaseConfigInfo dbInfo = config.getDatabaseConfigInfo();
      if (dbInfo != null && dbInfo.connection.equals(userToRemove))
        throw new RemoteException(String.format("Cannot remove connection \"%s\" which is used to store configuration information.", userToRemove));

      // check for number of superusers
      Collection<String> connectionNames = config.getConnectionInfoNames();
      int numSuperUsers = 0;
      for (String name : connectionNames)
        if (config.getConnectionInfo(name).is_superuser)
          ++numSuperUsers;
      // do not allow removal of last superuser
      if (numSuperUsers == 1 && loginUser.equals(userToRemove))
        throw new RemoteException("Cannot remove the only superuser.");

      config.removeConnectionInfo(userToRemove);
      return "Connection \"" + userToRemove + "\" was deleted.";
    }
    catch (Exception e)
    {
      e.printStackTrace();
View Full Code Here

TOP

Related Classes of weave.config.ConnectionConfig$DatabaseConfigInfo

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.