Changeset 5043
- Timestamp:
- Aug 11, 2009, 1:02:08 PM (14 years ago)
- 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 25 25 package net.sf.basedb.core; 26 26 27 import net.sf.basedb.core.data.ClientData;28 27 import net.sf.basedb.core.data.SchemaVersionData; 29 28 import net.sf.basedb.core.hibernate.JdbcWork; … … 937 936 } 938 937 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); 970 939 sessionCache.put(sessionControlId, sc); 971 940 return sc; -
trunk/src/core/net/sf/basedb/core/Install.java
r5041 r5043 595 595 createClient(rootUser, "net.sf.basedb.clients.migration", "Migration tool", "This client is used to migrate BASE 1.2.x data to BASE 2", null); 596 596 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); 597 600 598 601 // Plugins -
trunk/src/core/net/sf/basedb/core/InternalJobQueue.java
r4889 r5043 277 277 runnersGroup.setDaemon(false); 278 278 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()); 280 280 sc.login(new JobQueueKeyring()); 281 281 } -
trunk/src/core/net/sf/basedb/core/InternalStorageController.java
r4995 r5043 122 122 throw new BaseException("Path not found: " + settings); 123 123 } 124 sc = new SessionControl(null, 0, null, null);124 sc = new SessionControl(null, "net.sf.basedb.clients.internal", false, Application.getHostName()); 125 125 sc.login(new StorageKeyring()); 126 126 log.info("InternalStorageController has been initialised"); -
trunk/src/core/net/sf/basedb/core/SessionControl.java
r5038 r5043 166 166 Creates a new <code>SessionControl</code> object. 167 167 @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 169 171 @param remoteId For example, the IP-address 170 172 */ 171 SessionControl(String id, int clientId, String externalClientId, String remoteId)173 SessionControl(String id, String externalClientId, boolean failIfNoClient, String remoteId) 172 174 throws BaseException 173 175 { 174 176 this.id = id; 175 this.clientId = clientId;176 177 this.externalClientId = externalClientId; 177 178 this.remoteId = remoteId; 178 179 this.dbControlCache = Collections.synchronizedMap(new WeakHashMap<DbControl,String>()); 179 180 this.currentContexts = Collections.synchronizedMap(new HashMap<ContextKey, ItemContext>()); 180 i f (clientId != 0)181 {182 // load default settings for client application181 int tempClientId = 0; 182 if (externalClientId != null) 183 { 183 184 org.hibernate.Session session = null; 184 185 org.hibernate.Transaction tx = null; … … 187 188 session = HibernateUtil.newSession(); 188 189 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 } 190 210 } 191 211 finally … … 195 215 } 196 216 } 217 this.clientId = tempClientId; 197 218 updateLastAccess(); 198 219 } … … 620 641 // If a client has been specified - check for USE permission 621 642 ClientData clientData = null; 622 if (getClientId() != 0 && !impersonated)643 if (getClientId() != 0) 623 644 { 624 645 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 } 631 655 } 632 656 }
Note: See TracChangeset
for help on using the changeset viewer.