Merge branch 'sprint148'
diff --git a/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/ConnectionEvent.java b/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/ConnectionEvent.java
index f9f2f17..3258456 100644
--- a/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/ConnectionEvent.java
+++ b/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/ConnectionEvent.java
@@ -28,15 +28,22 @@
    private final UUID sessionKey;
    private final OteServiceProperties props;
    private final IHostTestEnvironment hostTestEnvironment;
+   private final boolean isUnauthorizedUser;
 
-   public ConnectionEvent(IHostTestEnvironment hostTestEnvironment, IServiceConnector connector, ITestEnvironment environment, UUID sessionKey) {
-      if (connector == null) {
-         throw new NullPointerException("connector cannot be null");
+   public ConnectionEvent(IHostTestEnvironment hostTestEnvironment, IServiceConnector connector, ITestEnvironment environment, 
+         UUID sessionKey, boolean isUnauthorizedUser) {
+      
+      if (!isUnauthorizedUser) {
+         if (connector == null) {
+            throw new NullPointerException("connector cannot be null");
+         }
       }
+      
       this.environment = environment;
       this.connector = connector;
       this.sessionKey = sessionKey;
       this.hostTestEnvironment = hostTestEnvironment;
+      this.isUnauthorizedUser = isUnauthorizedUser;
       props = new OteServiceProperties(connector);
    }
 
@@ -75,4 +82,8 @@
       return hostTestEnvironment;
    }
 
+   public boolean isUnauthorizedUser() {
+      return isUnauthorizedUser;
+   }
+
 }
diff --git a/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/core/ClientSession.java b/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/core/ClientSession.java
index c850a25..1196269 100644
--- a/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/core/ClientSession.java
+++ b/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/core/ClientSession.java
@@ -56,7 +56,7 @@
    }
 
    @Override
-   public String getAddress() throws RemoteException {
+   public String getAddress() {
       return address.getHostAddress();
    }
 
@@ -101,7 +101,7 @@
    }
 
    @Override
-   public void initiateInformationalPrompt(String message) throws RemoteException {
+   public void initiateInformationalPrompt(String message) {
       assert sessionDelegate != null : "delegate is null";
       try {
          sessionDelegate.handleInformationPrompt(message);
@@ -162,12 +162,12 @@
     * closes this session
     */
    void close() {
-
+      // INTENTIONALLY EMPTY BLOCK
    }
 
    TestHostConnection connect(IServiceConnector connector, IHostTestEnvironment testHost, TestEnvironmentConfig config) throws Exception {
       // intentionally package-private
-      if (lock.tryLock(TIMEOUT, TimeUnit.MINUTES)) {
+       if (lock.tryLock(TIMEOUT, TimeUnit.MINUTES)) {
          try {
             IRemoteUserSession exportedSession = (IRemoteUserSession) connector.export(this);
             UUID id = UUID.randomUUID();
@@ -175,10 +175,12 @@
             ConnectionRequestResult result = testHost.requestEnvironment(exportedSession, id, config);
             if (result != null && result.getStatus().getStatus()) {
                connector.setConnected(true);
-               return new TestHostConnection(connector, testHost, result.getEnvironment(), result.getSessionKey());
+               return new TestHostConnection(connector, testHost, result.getEnvironment(), result.getSessionKey(), false);
+            } else if (result != null && result.getStatus().isUnauthorizedUser()) {
+               return new TestHostConnection(null, testHost, null, null, true);
             } else {
                OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, "Error Connecting to the OTE Test Server.",
-                  new Exception(result.getStatus().getMessage()));
+                     new Exception(result.getStatus().getMessage()));
             }
             return null;
          } finally {
diff --git a/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/core/TestClientServiceImpl.java b/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/core/TestClientServiceImpl.java
index 176d3d3..24db862 100644
--- a/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/core/TestClientServiceImpl.java
+++ b/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/core/TestClientServiceImpl.java
@@ -89,7 +89,7 @@
 	}
 
 	@Override
-	public  ConnectionEvent connect(IHostTestEnvironment testHost, IEnvironmentConfigurer configurer, TestEnvironmentConfig config, IProgressMonitor monitor) throws IllegalArgumentException, TestSessionException {
+	public  ConnectionEvent connect(IHostTestEnvironment testHost, IEnvironmentConfigurer configurer, TestEnvironmentConfig config, IProgressMonitor monitor) throws IllegalArgumentException {
 		checkState();
 		final IServiceConnector connector;
 		final ClientSession localSession;
@@ -113,14 +113,20 @@
 			if(configurer.configure(testHost, new SubProgressMonitor(monitor, 95)) && !monitor.isCanceled()){
 			   testConnection = localSession.connect(connector, testHost, config);
 			   if (testConnection != null) {
-			      // success
-			      ConnectionEvent event = new ConnectionEvent(testHost, connector, testConnection.getConnectEnvironment(), testConnection.getSessionKey());
-			      listenerNotifier.notifyPostConnection(event);
-			      return event;
+			      if (testConnection.isUnauthorizedUser()) {
+			         ConnectionEvent event = new ConnectionEvent(null, null, null, null, true);
+			         testConnection = null; //Not really connected after this.
+                  return event;
+			      } else {
+			         // success
+			         ConnectionEvent event = new ConnectionEvent(testHost, connector, testConnection.getConnectEnvironment(), testConnection.getSessionKey(), false);
+			         listenerNotifier.notifyPostConnection(event);
+			         return event;
+			      }
 			   }
 			}
 		} catch (Exception e) {
-			Activator.log(Level.SEVERE, "failed to establish connection", e);
+		   Activator.log(Level.SEVERE, "failed to establish connection", e);
 			testConnection = null;
 		}
 		return null;
@@ -165,7 +171,7 @@
 			} else {
 				ConnectionEvent event =
 						new ConnectionEvent(this.getConnectedHost(), testConnection.getConnectedTestHost(), envirnonment,
-								testConnection.getSessionKey());
+								testConnection.getSessionKey(), false);
 				listenerNotifier.notifyDisconnect(event);
 				try {
 					session.disconnect(testConnection);
@@ -215,7 +221,7 @@
 					if (testConnection  != null) {
 						event = new ConnectionEvent(this.getConnectedHost(),
 								testConnection.getServiceConnector(), testConnection.getConnectEnvironment(),
-								testConnection.getSessionKey());
+								testConnection.getSessionKey(), false);
 					} else {
 						event = null;
 					}
@@ -347,6 +353,7 @@
 
 	@Override
 	public void onConnectionServiceStopped() {
+	   // INTENTIONALLY EMPTY BLOCK
 	}
 
 	@Override
diff --git a/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/core/TestHostConnection.java b/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/core/TestHostConnection.java
index 6680b6b..d1ba198 100644
--- a/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/core/TestHostConnection.java
+++ b/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/core/TestHostConnection.java
@@ -30,18 +30,24 @@
    private final UUID sessionKey;
    private final IHostTestEnvironment host;
    private String serverId;
+   private final boolean isUnauthorizedUser;
 
-   TestHostConnection(IServiceConnector connector, IHostTestEnvironment host, ITestEnvironment connectEnvironment, UUID uuid) {
+   TestHostConnection(IServiceConnector connector, IHostTestEnvironment host, ITestEnvironment connectEnvironment, 
+         UUID uuid, boolean isUnauthorizedUser) {
       // intentionally package-private
-      if (connector == null) {
-         throw new NullPointerException("service connector cannot be null");
+
+      if (!isUnauthorizedUser) {
+         if (connector == null) {
+            throw new NullPointerException("service connector cannot be null");
+         }
+         if (connectEnvironment == null) {
+            throw new NullPointerException("test environment cannot be null");
+         }
+         if (uuid == null) {
+            throw new NullPointerException("session key cannot be null");
+         }
       }
-      if (connectEnvironment == null) {
-         throw new NullPointerException("test environment cannot be null");
-      }
-      if (uuid == null) {
-         throw new NullPointerException("session key cannot be null");
-      }
+      
       this.serviceConnector = connector;
       this.host = host;
       this.connectEnvironment = connectEnvironment;
@@ -51,6 +57,7 @@
       } catch (RemoteException e) {
     	  this.serverId = "";
       }
+      this.isUnauthorizedUser = isUnauthorizedUser;
    }
 
    /**
@@ -90,4 +97,8 @@
 
       host.disconnect(sessionKey);
    }
+
+   public boolean isUnauthorizedUser() {
+      return isUnauthorizedUser;
+   }
 }
diff --git a/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/ReturnStatus.java b/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/ReturnStatus.java
index 164db85..53188f4 100644
--- a/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/ReturnStatus.java
+++ b/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/ReturnStatus.java
@@ -20,11 +20,13 @@
    private static final long serialVersionUID = -7774073812320127561L;
 
    private final boolean status;
+   private final boolean unauthorizedUser;
    private final String message;
 
-   public ReturnStatus(String message, boolean status) {
+   public ReturnStatus(String message, boolean status, boolean unauthorizedUser) {
       this.status = status;
       this.message = message;
+      this.unauthorizedUser = unauthorizedUser;
    }
 
    public boolean getStatus() {
@@ -34,4 +36,8 @@
    public String getMessage() {
       return message;
    }
+   
+   public boolean isUnauthorizedUser() {
+      return unauthorizedUser;
+   }
 }
diff --git a/org.eclipse.osee.ote.properties/src/org/eclipse/osee/ote/properties/OtePropertiesCore.java b/org.eclipse.osee.ote.properties/src/org/eclipse/osee/ote/properties/OtePropertiesCore.java
index 45c2cfd..5f76501 100644
--- a/org.eclipse.osee.ote.properties/src/org/eclipse/osee/ote/properties/OtePropertiesCore.java
+++ b/org.eclipse.osee.ote.properties/src/org/eclipse/osee/ote/properties/OtePropertiesCore.java
@@ -2,6 +2,7 @@
 
 public enum OtePropertiesCore implements OteProperties {
 
+   authorizedUser("ote.authorized.user"),
    batchFolderDays("ote.batchfolder.days"),
    brokerUriPort("ote.server.broker.uri.port"),
    endpointPort("ote.endpoint.port"),
diff --git a/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OTEServerCreationComponent.java b/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OTEServerCreationComponent.java
index 1a797f7..7e34c3b 100644
--- a/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OTEServerCreationComponent.java
+++ b/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OTEServerCreationComponent.java
@@ -45,7 +45,14 @@
             if (outfileLocation == null) {
                outfileLocation = OtePropertiesCore.javaIoTmpdir.getValue();
             }
-            String title = OtePropertiesCore.serverTitle.getValue();
+            
+            String title;
+            if (OtePropertiesCore.authorizedUser.getValue() != null) {
+               title = OtePropertiesCore.serverTitle.getValue() + "[AUTHORIZED USER:" + OtePropertiesCore.authorizedUser.getValue() + "]";
+            } else {
+               title = OtePropertiesCore.serverTitle.getValue();
+            }
+            
             String name = OtePropertiesCore.userName.getValue();
             String keepEnvAliveWithNoUsersStr = OtePropertiesCore.serverKeepalive.getValue();
             boolean keepEnvAliveWithNoUsers = true;
diff --git a/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OteService.java b/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OteService.java
index a5c3ce3..2c10365 100644
--- a/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OteService.java
+++ b/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OteService.java
@@ -77,7 +77,7 @@
       enhancedProperties.setProperty(HostServerProperties.owner.name(), OtePropertiesCore.userName.getValue());
       enhancedProperties.setProperty(HostServerProperties.id.name(), serviceID.toString());
       enhancedProperties.setProperty(HostServerProperties.isSim.name(), Boolean.toString(environmentCreation.isSimulated()));
-//      enhancedProperties.setProperty(HostServerProperties.activeMq.name(), environmentCreation.getBroker().getUri().toString());
+      //      enhancedProperties.setProperty(HostServerProperties.activeMq.name(), environmentCreation.getBroker().getUri().toString());
       try {
          String format = String.format("tcp://%s:%d", receiver.getLocalEndpoint().getAddress().getHostAddress(), receiver.getLocalEndpoint().getPort());
          if(OtePropertiesCore.httpPort.getValue() == null){
@@ -115,7 +115,7 @@
 //   }
 
    @Override
-   public EnhancedProperties getProperties() throws RemoteException {
+   public EnhancedProperties getProperties() {
       return enhancedProperties;
    }
 
@@ -123,14 +123,20 @@
    public ConnectionRequestResult requestEnvironment(IRemoteUserSession session, UUID sessionId, TestEnvironmentConfig config) throws RemoteException {
       try {
          OseeLog.log(OteService.class, Level.INFO,
-            "received request for test environment from user " + session.getUser().getName());
-         if (!isEnvironmentAvailable()) {
-            createEnvironment();
+               "received request for test environment from user " + session.getUser().getName());
+
+         if (isAuthorizedUser(session)) {
+            if (!isEnvironmentAvailable()) {
+               createEnvironment();
+            }
+            
+            oteSessions.add(sessionId, session);
+            updateDynamicInfo();
+            return new ConnectionRequestResult(remoteEnvironment, sessionId, new ReturnStatus("Success", true, false));
+         } 
+         else {
+            return new ConnectionRequestResult(null, null, new ReturnStatus("Failure", false, true));
          }
-         
-         oteSessions.add(sessionId, session);
-         updateDynamicInfo();
-         return new ConnectionRequestResult(remoteEnvironment, sessionId, new ReturnStatus("Success", true));
       } catch (Throwable ex) {
          OseeLog.log(OteService.class, Level.SEVERE,
             "Exception while requesting environment for user " + session.getUser().getName(), ex);
@@ -138,6 +144,21 @@
       }
    }
 
+   private boolean isAuthorizedUser(IRemoteUserSession session) throws RemoteException {
+
+      if (OtePropertiesCore.authorizedUser.getValue() == null) {
+         return true;
+      } else {
+         String [] authorizedUsers = OtePropertiesCore.authorizedUser.getValue().split(",");
+         for (int i = 0; i < authorizedUsers.length; i++) {
+            if (authorizedUsers[i].equals(session.getUser().getName())) {
+               return true;
+            }
+         }
+         return false;
+      }
+   }
+
    private void createEnvironment() throws Throwable {
       currentEnvironment = environmentCreation.createEnvironment();
       remoteEnvironment = environmentCreation.createRemoteTestEnvironment(currentEnvironment);
@@ -148,7 +169,7 @@
       return remoteEnvironment != null;
    }
 
-   public void updateDynamicInfo() throws RemoteException {
+   public void updateDynamicInfo() {
       Collection<OSEEPerson1_4> userList = new LinkedList<>();
       StringBuilder sb = new StringBuilder();
       if (isEnvironmentAvailable()) {
@@ -176,11 +197,11 @@
 //      }
    }
 
-   public ServiceID getServiceID() throws RemoteException {
+   public ServiceID getServiceID() {
       return serviceID;
    }
 
-   public void kill() throws RemoteException {
+   public void kill() {
       if(currentEnvironment != null){
          currentEnvironment.shutdown();
       }
@@ -191,7 +212,7 @@
 //   }
 
    @Override
-   public void disconnect(UUID sessionId) throws RemoteException {
+   public void disconnect(UUID sessionId) {
       if (currentEnvironment != null) {
          oteSessions.remove(sessionId);
          updateDynamicInfo();
@@ -199,7 +220,7 @@
    }
 
    @Override
-   public String getHttpURL() throws RemoteException {
+   public String getHttpURL() {
       return (String)enhancedProperties.getProperty("appServerURI");
    }