Changeset 5043


Ignore:
Timestamp:
Aug 11, 2009, 1:02:08 PM (13 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #1355: Add "client application" for internal use

Location:
trunk/src/core/net/sf/basedb/core
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/Application.java

    r5039 r5043  
    2525package net.sf.basedb.core;
    2626
    27 import net.sf.basedb.core.data.ClientData;
    2827import net.sf.basedb.core.data.SchemaVersionData;
    2928import net.sf.basedb.core.hibernate.JdbcWork;
     
    937936    }
    938937
    939     int clientId = 0;
    940     if (externalClientId != null)
    941     {
    942       org.hibernate.Session session = null;
    943       org.hibernate.Transaction tx = null;
    944       try
    945       {
    946         session = HibernateUtil.newSession();
    947         tx = HibernateUtil.newTransaction(session);
    948         org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session, "GET_CLIENT_FOR_EXTERNAL_ID");
    949         /*
    950           SELECT cli
    951           FROM ClientData cli
    952           WHERE cli.externalId = :externalId
    953         */
    954         query.setString("externalId", externalClientId);
    955         ClientData clientData = HibernateUtil.loadData(ClientData.class, query);
    956         if (clientData == null)
    957         {
    958           throw new ItemNotFoundException("Client[externalId="+externalClientId+"]");
    959         }
    960         clientId = clientData.getId();
    961       }
    962       finally
    963       {
    964         if (tx != null) HibernateUtil.commit(tx);
    965         if (session != null) HibernateUtil.close(session);
    966       }
    967     }
    968 
    969     SessionControl sc = new SessionControl(sessionControlId, clientId, externalClientId, remoteId);
     938    SessionControl sc = new SessionControl(sessionControlId, externalClientId, true, remoteId);
    970939    sessionCache.put(sessionControlId, sc);
    971940    return sc;
  • trunk/src/core/net/sf/basedb/core/Install.java

    r5041 r5043  
    595595      createClient(rootUser, "net.sf.basedb.clients.migration", "Migration tool", "This client is used to migrate BASE 1.2.x data to BASE 2", null);
    596596      createClient(rootUser, "net.sf.basedb.clients.jobagent", "Job agent client", "This client is used by all job agents", keyJobAgentUse);
     597      createClient(rootUser, "net.sf.basedb.clients.internal", "Internal",
     598        "This client is used by the internal processes such as the job queue and secondary " +
     599        "storage controller. Do not remove!", keyEveryoneRead);
    597600 
    598601      // Plugins
  • trunk/src/core/net/sf/basedb/core/InternalJobQueue.java

    r4889 r5043  
    277277    runnersGroup.setDaemon(false);
    278278    runnersGroup.setMaxPriority(Config.getInt("jobqueue.internal.maxthreadpriority", Thread.NORM_PRIORITY - 1));
    279     sc = new SessionControl(null, 0, null, null);
     279    sc = new SessionControl(null, "net.sf.basedb.clients.internal", false, Application.getHostName());
    280280    sc.login(new JobQueueKeyring());
    281281  }
  • trunk/src/core/net/sf/basedb/core/InternalStorageController.java

    r4995 r5043  
    122122      throw new BaseException("Path not found: " + settings);
    123123    }
    124     sc = new SessionControl(null, 0, null, null);
     124    sc = new SessionControl(null, "net.sf.basedb.clients.internal", false, Application.getHostName());
    125125    sc.login(new StorageKeyring());
    126126    log.info("InternalStorageController has been initialised");
  • trunk/src/core/net/sf/basedb/core/SessionControl.java

    r5038 r5043  
    166166    Creates a new <code>SessionControl</code> object.
    167167    @param id The id used in {@link Application#newSessionControl(String,String,String)}
    168     @param clientId The id of the client application
     168    @param externalClientId Optional external ID of the client application in use
     169    @param failIfNoClient If TRUE, an exception is thrown if an external client id
     170      has been specified, but not found
    169171    @param remoteId For example, the IP-address
    170172  */
    171   SessionControl(String id, int clientId, String externalClientId, String remoteId)
     173  SessionControl(String id, String externalClientId, boolean failIfNoClient, String remoteId)
    172174    throws BaseException
    173175  {
    174176    this.id = id;
    175     this.clientId = clientId;
    176177    this.externalClientId = externalClientId;
    177178    this.remoteId = remoteId;
    178179    this.dbControlCache = Collections.synchronizedMap(new WeakHashMap<DbControl,String>());
    179180    this.currentContexts = Collections.synchronizedMap(new HashMap<ContextKey, ItemContext>());
    180     if (clientId != 0)
    181     {
    182       // load default settings for client application
     181    int tempClientId = 0;
     182    if (externalClientId != null)
     183    {
    183184      org.hibernate.Session session = null;
    184185      org.hibernate.Transaction tx = null;
     
    187188        session = HibernateUtil.newSession();
    188189        tx = HibernateUtil.newTransaction(session);
    189         clientDefaultSettings = loadClientDefaultSettings(session, clientId);
     190       
     191        // Find the internal client id for the given external id
     192        org.hibernate.Query query = HibernateUtil.getPredefinedQuery(session, "GET_CLIENT_FOR_EXTERNAL_ID");
     193        /*
     194          SELECT cli
     195          FROM ClientData cli
     196          WHERE cli.externalId = :externalId
     197        */
     198        query.setString("externalId", externalClientId);
     199        ClientData clientData = HibernateUtil.loadData(ClientData.class, query);
     200        if (clientData != null)
     201        {
     202          tempClientId = clientData.getId();
     203          // load default settings for client application
     204          clientDefaultSettings = loadClientDefaultSettings(session, tempClientId);
     205        }
     206        else if (failIfNoClient)
     207        {
     208          throw new ItemNotFoundException("Client[externalId="+externalClientId+"]");
     209        }
    190210      }
    191211      finally
     
    195215      }
    196216    }
     217    this.clientId = tempClientId;
    197218    updateLastAccess();
    198219  }
     
    620641    // If a client has been specified - check for USE permission
    621642    ClientData clientData = null;
    622     if (getClientId() != 0 && !impersonated)
     643    if (getClientId() != 0)
    623644    {
    624645      clientData = HibernateUtil.loadData(session, ClientData.class, getClientId());
    625       int permissions = li.keyring.getAllPermissions(
    626         Item.CLIENT, clientData.getOwner(), clientData.getItemKey(), clientData.getProjectKey()
    627         );
    628       if (!Permission.hasPermission(permissions, Permission.USE))
    629       {
    630         throw new PermissionDeniedException(Permission.USE, "Client[externalId="+clientData.getExternalId()+"]");
     646      if (!impersonated)
     647      {
     648        int permissions = li.keyring.getAllPermissions(
     649          Item.CLIENT, clientData.getOwner(), clientData.getItemKey(), clientData.getProjectKey()
     650          );
     651        if (!Permission.hasPermission(permissions, Permission.USE))
     652        {
     653          throw new PermissionDeniedException(Permission.USE, "Client[externalId="+clientData.getExternalId()+"]");
     654        }
    631655      }
    632656    }
Note: See TracChangeset for help on using the changeset viewer.