Skip to main content
summaryrefslogtreecommitdiffstats
blob: aefd91ede7c977649555b651db3bbcbb4c17a7f6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.framework.core.server.internal.session;

import java.util.Date;
import java.util.Properties;
import org.eclipse.osee.framework.core.data.IUserToken;
import org.eclipse.osee.framework.core.data.OseeSessionGrant;
import org.eclipse.osee.framework.core.model.cache.IOseeTypeFactory;
import org.eclipse.osee.framework.core.server.OseeServerProperties;
import org.eclipse.osee.framework.core.sql.OseeSql;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.Conditions;
import org.eclipse.osee.jdbc.JdbcClientConfig;
import org.eclipse.osee.jdbc.JdbcService;
import org.eclipse.osee.logger.Log;

/**
 * @author Roberto E. Escobar
 */
public final class SessionFactory implements IOseeTypeFactory {
   private final Log logger;
   private final JdbcService jdbcService;

   public SessionFactory(Log logger, JdbcService jdbcService) {
      this.logger = logger;
      this.jdbcService = jdbcService;
   }

   public Session createLoadedSession(String guid, String userId, Date creationDate, String clientVersion, String clientMachineName, String clientAddress, int clientPort) {
      Session toReturn =
         createNewSession(guid, userId, creationDate, clientVersion, clientMachineName, clientAddress, clientPort);
      return toReturn;
   }

   public Session createNewSession(String guid, String userId, Date creationDate, String clientVersion, String clientMachineName, String clientAddress, int clientPort) {
      Session toReturn =
         new Session(guid, userId, creationDate, clientVersion, clientMachineName, clientAddress, clientPort);
      return toReturn;
   }

   public OseeSessionGrant createSessionGrant(Session session, IUserToken userToken, String authenticationType) throws OseeCoreException {
      Conditions.checkNotNull(session, "Session");
      Conditions.checkNotNull(userToken, "IUserToken");

      final JdbcClientConfig config = jdbcService.getClient().getConfig();

      OseeSessionGrant sessionGrant = new OseeSessionGrant(session.getGuid());
      sessionGrant.setAuthenticationProtocol(authenticationType);
      sessionGrant.setCreationRequired(userToken.isCreationRequired());
      sessionGrant.setOseeUserName(userToken.getName());
      sessionGrant.setOseeUserEmail(userToken.getEmail());
      sessionGrant.setOseeUserActive(userToken.isActive());
      sessionGrant.setOseeUserId(userToken.getUserId());
      sessionGrant.setDbIsProduction(config.isProduction());
      sessionGrant.setDbLogin(config.getDbUsername());
      sessionGrant.setDbId(jdbcService.getId());
      sessionGrant.setDbDriver(config.getDbDriver());
      sessionGrant.setDbLogin(config.getDbUsername());
      sessionGrant.setDbUrl(config.getDbUri());
      sessionGrant.setDbConnectionProperties(config.getDbProps());
      sessionGrant.setDbDatabaseName(jdbcService.hasServer() ? jdbcService.getServerConfig().getDbName() : "");
      sessionGrant.setDbDatabasePath(jdbcService.hasServer() ? jdbcService.getServerConfig().getDbPath() : "");

      Properties properties = OseeSql.getSqlProperties(jdbcService.getClient().getDbType().areHintsSupported());
      sessionGrant.setSqlProperties(properties);

      sessionGrant.setDataStorePath(OseeServerProperties.getOseeApplicationServerData(logger));
      return sessionGrant;
   }

}

Back to the top