Package org.xmlBlaster.engine.qos

Examples of org.xmlBlaster.engine.qos.ConnectReturnQosServer


                     // DispatchConnection.initialize() -> CbDispatchConnection.connectLowlevel()
                     // will later call callback.initialize(loginName, callbackAddress)
                  }
               }

               ConnectReturnQosServer retQos = authenticate.connect(conQos);
               this.secretSessionId = retQos.getSecretSessionId();
               receiver.setSecretSessionId(retQos.getSecretSessionId()); // executeResponse needs it
               executeResponse(receiver, retQos.toXml(), SocketUrl.SOCKET_TCP);
               driver.addClient(this.secretSessionId, this);
             }
            else if (MethodName.DISCONNECT == receiver.getMethodName()) {
               this.disconnectIsCalled = true;
               executeResponse(receiver, Constants.RET_OK, SocketUrl.SOCKET_TCP);   // ACK the disconnect to the client and then proceed to the server core
View Full Code Here


      connectQos.addCallbackAddress(cbAddress);
      connectQos.loadClientPlugin("htpasswd", "1.0", loginName, passwd);
      connectQos.getSessionQos().setSessionTimeout(0L);
      ConnectQosServer connectQosServer = new ConnectQosServer(glob, connectQos.getData());
      connectQosServer.setAddressServer(this.addressServer);
      ConnectReturnQosServer returnQos = this.authenticate.connect(connectQosServer);
      sessionId = returnQos.getSecretSessionId();

      log.info("Started successfully JDBC driver with loginName=" + loginName);
   }
View Full Code Here

            SessionInfo info = getSessionInfo(secretSessionId);
            if (info != null) {  // authentication succeeded

               updateConnectQos(info, connectQos);

               ConnectReturnQosServer returnQos = new ConnectReturnQosServer(glob, info.getConnectQos().getData());
               returnQos.getSessionQos().setSecretSessionId(secretSessionId);
               returnQos.getSessionQos().setSessionName(info.getSessionName());
               returnQos.setReconnected(true);
               returnQos.getData().addClientProperty(Constants.CLIENTPROPERTY_RCVTIMESTAMPSTR, IsoDateParser.getCurrentUTCTimestampNanos());
               log.info("Reconnected with given secretSessionId.");
               return returnQos;
            }
         }
      }
      catch (Throwable e) {
         log.severe("Internal error when trying to reconnect to session " + connectQos.getSessionName() + " with secret session ID: " + e.toString());
         e.printStackTrace();
         throw XmlBlasterException.convert(glob, ME, ErrorCode.INTERNAL_CONNECTIONFAILURE.toString(), e);
      }

      // [2] Try reconnecting with publicSessionId
      if (connectQos.hasPublicSessionId()) {
         SessionInfo info = getSessionInfo(connectQos.getSessionName());
         if (info != null && !info.isShutdown() && !info.getConnectQos().bypassCredentialCheck()) {
            if (connectQos.getSessionQos().reconnectSameClientOnly()) {
               String text = "Only the creator of session " + connectQos.getSessionName().toString() + " may reconnect, access denied.";
               log.warning(text);
               throw new XmlBlasterException(glob, ErrorCode.USER_CONFIGURATION_IDENTICALCLIENT,
                         ME+".connect()", text);
            }
            try {
               // Check password as we can't trust the public session ID
               connectQos = info.getSecuritySession().init(connectQos, null);
               boolean ok = info.getSecuritySession().verify(connectQos.getSecurityQos());
               if (!ok)
                   throw new XmlBlasterException(glob, ErrorCode.USER_SECURITY_AUTHENTICATION_ACCESSDENIED,
                       ME, "Access denied for " + connectQos.getSecurityQos().getUserId() + " " + connectQos.getClientPluginType());

               String oldSecretSessionId = info.getSecretSessionId();

               if (secretSessionId == null || secretSessionId.length() < 2) {
                  // Keep the old secretSessionId
                  connectQos.getSessionQos().setSecretSessionId(oldSecretSessionId);
               }
               else {
                  // The CORBA driver insists in a new secretSessionId
                  changeSecretSessionId(oldSecretSessionId, secretSessionId);
                  connectQos.getSessionQos().setSecretSessionId(secretSessionId);
               }

               updateConnectQos(info, connectQos); // fires event

               ConnectReturnQosServer returnQos = new ConnectReturnQosServer(glob, info.getConnectQos().getData());
               returnQos.getSessionQos().setSessionName(info.getSessionName());
               returnQos.setReconnected(true);
               returnQos.getData().addClientProperty(Constants.CLIENTPROPERTY_RCVTIMESTAMPSTR, IsoDateParser.getCurrentUTCTimestampNanos());
               log.info("Reconnected with given publicSessionId to '" + info.getSessionName() + "'.");
               return returnQos;
            }
            catch (XmlBlasterException e) {
               log.warning("Access is denied when trying to reconnect to session " + info.getSessionName() + ": " + e.getMessage());
               throw e; // Thrown if authentication failed
            }
            catch (Throwable e) {
               log.severe("Internal error when trying to reconnect to session " + info.getSessionName() + " with public session ID: " + e.toString());
               e.printStackTrace();
               throw XmlBlasterException.convert(glob, ME, ErrorCode.INTERNAL_CONNECTIONFAILURE.toString(), e);
            }
         }
      }

      // [3] Generate a secret session ID
      if (secretSessionId == null || secretSessionId.length() < 2) {
         secretSessionId = createSessionId("null" /*subjectCtx.getName()*/);
         connectQos.getSessionQos().setSecretSessionId(secretSessionId); // assure consistency
         if (log.isLoggable(Level.FINE)) log.fine("Empty secretSessionId - generated secretSessionId=" + secretSessionId);
      }

      I_Session sessionCtx = null;
      I_Manager securityMgr = null;
      SessionInfo sessionInfo = null;

      // [4] Authenticate new client with password
      try {
         // Get suitable SecurityManager and context ...
         securityMgr = plgnLdr.getManager(connectQos.getClientPluginType(), connectQos.getClientPluginVersion());
         if (securityMgr == null) {
            log.warning("Access is denied, there is no security manager configured for this connect QoS: " + connectQos.toXml());
            throw new XmlBlasterException(glob, ErrorCode.USER_SECURITY_AUTHENTICATION_ACCESSDENIED, ME, "There is no security manager configured with the given connect QoS");
         }
         sessionCtx = securityMgr.reserveSession(secretSessionId)// always creates a new I_Session instance
         connectQos = sessionCtx.init(connectQos, null);
         if (connectQos.bypassCredentialCheck()) {
            // This happens when a session is auto created by a PtP message
            // Only ConnectQosServer (which is under control of the core) can set this flag
            if (log.isLoggable(Level.FINE)) log.fine("SECURITY SWITCH OFF: Granted access to xmlBlaster without password, bypassCredentialCheck=true");
         }
         else {
            String securityInfo = sessionCtx.init(connectQos.getSecurityQos()); // throws XmlBlasterExceptions if authentication fails
            if (securityInfo != null && securityInfo.length() > 1) log.warning("Ignoring security info: " + securityInfo);
         }
         // Now the client is authenticated
      }
      catch (XmlBlasterException e) {
         // If access is denied: cleanup resources
         log.warning("Access is denied: " + e.getMessage() + ": " + connectQos.toString());
         if (securityMgr != null) securityMgr.releaseSession(secretSessionId, null)// allways creates a new I_Session instance
         throw e;
      }
      catch (Throwable e) {
         log.severe("PANIC: Access is denied: " + e.getMessage() + "\n" + ServerScope.getStackTraceAsString(e));
         e.printStackTrace();
         // On error: cleanup resources
         securityMgr.releaseSession(secretSessionId, null)// allways creates a new I_Session instance
         throw XmlBlasterException.convert(glob, ME, ErrorCode.INTERNAL_CONNECTIONFAILURE.toString(), e);
      }

      if (log.isLoggable(Level.FINE)) log.fine("Checking if user is known ...");
      SubjectInfo subjectInfo = null;
      try {
      /*
         // Check if user is known, otherwise create an entry ...
         I_Subject subjectCtx = sessionCtx.getSubject();
         SessionName subjectName = new SessionName(glob, connectQos.getSessionName(), 0L); // Force to be of type subject (no public session ID)

         boolean subjectIsAlive = false;
         synchronized(this.loginNameSubjectInfoMap) { // Protect against two simultaneous logins
            subjectInfo = (SubjectInfo)this.loginNameSubjectInfoMap.get(subjectName.getLoginName());
            //log.error(ME, "DEBUG ONLY, subjectName=" + subjectName.toString() + " loginName=" + subjectName.getLoginName() + " state=" + toXml());
            if (subjectInfo == null) {
               subjectInfo = new SubjectInfo(getGlobal(), this, subjectName);
               this.loginNameSubjectInfoMap.put(subjectInfo.getLoginName(), subjectInfo); // Protect against two simultaneous logins
            }

            subjectIsAlive = subjectInfo.isAlive();
         } // synchronized(this.loginNameSubjectInfoMap)

         if (!subjectInfo.isAlive()) {
            try {
               subjectInfo.toAlive(subjectCtx, connectQos.getSubjectQueueProperty());
            }
            catch(Throwable e) {
               synchronized(this.loginNameSubjectInfoMap) {
                  this.loginNameSubjectInfoMap.remove(subjectInfo.getLoginName());
               }
               throw e;
            }
         }
         */

         // [5] New client is authenticated, create the SessioInfo
         boolean returnLocked = true;
         subjectInfo = getOrCreateSubjectInfoByName(connectQos.getSessionName(),
                                   returnLocked, sessionCtx.getSubject(), connectQos.getSubjectQueueProperty());
         try { // subjectInfo.getLock().release())
            if (subjectInfo.isAlive()) {
               if (connectQos.getData().hasSubjectQueueProperty())
                  subjectInfo.setSubjectQueueProperty(connectQos.getSubjectQueueProperty()); // overwrites only if not null
            }
            // Check if client does a relogin and wants to destroy old sessions
            if (connectQos.clearSessions() == true) {
               SessionInfo[] sessions = subjectInfo.getSessionsToClear(connectQos);
               if (sessions.length > 0) {
                 for (int i=0; i<sessions.length; i++ ) {
                    SessionInfo si = sessions[i];
                    log.warning("Destroying session '" + si.getSecretSessionId() + "' of user '" + subjectInfo.getSubjectName() + "' as requested by client");
                    disconnect(si.getSecretSessionId(), (String)null);
                 }
                 // will create a new SubjectInfo instance (which should be OK)
                 return connect(connectQos, secretSessionId);
               }
            }

            if (log.isLoggable(Level.FINE)) log.fine("Creating sessionInfo for " + subjectInfo.getId());

            // A PtP with forceQueuing=true and a simultaneous connect of the same
            // client: This code is thread safe with new SessionInfo() below
            // to avoid duplicate SessionInfo
            sessionInfo = getOrCreateSessionInfo(connectQos.getSessionName(), connectQos);
            if (sessionInfo.isInitialized() &&
                !sessionInfo.isShutdown() && sessionInfo.getConnectQos().bypassCredentialCheck()) {
               if (log.isLoggable(Level.FINE)) log.fine("connect: Reused session with had bypassCredentialCheck=true");
               String oldSecretSessionId = sessionInfo.getSecretSessionId();
               sessionInfo.setSecuritySession(sessionCtx);
               if (secretSessionId == null || secretSessionId.length() < 2) {
                  // Keep the old secretSessionId
                  connectQos.getSessionQos().setSecretSessionId(oldSecretSessionId);
               }
               else {
                  // The CORBA driver insists in a new secretSessionId
                  changeSecretSessionId(oldSecretSessionId, secretSessionId);
                  connectQos.getSessionQos().setSecretSessionId(secretSessionId);
               }
               updateConnectQos(sessionInfo, connectQos);
            }
            else {
               // Create the new sessionInfo instance
               if (log.isLoggable(Level.FINE)) log.fine("connect: sessionId='" + secretSessionId + "' connectQos='"  + connectQos.toXml() + "'");
               sessionInfo.init(subjectInfo, sessionCtx, connectQos);
               synchronized(this.sessionInfoMap) {
                  this.sessionInfoMap.put(secretSessionId, sessionInfo);
               }
            }

            connectQos.getSessionQos().setSecretSessionId(secretSessionId);
            connectQos.getSessionQos().setSessionName(sessionInfo.getSessionName());
            subjectInfo.notifyAboutLogin(sessionInfo);
            fireClientEvent(sessionInfo, true);
         }
         finally {
            if (subjectInfo != null) subjectInfo.getLock().release();
         }

         // --- compose an answer -----------------------------------------------
         ConnectReturnQosServer returnQos = new ConnectReturnQosServer(glob, connectQos.getData());
         returnQos.getSessionQos().setSecretSessionId(secretSessionId); // securityInfo is not coded yet !
         returnQos.getSessionQos().setSessionName(sessionInfo.getSessionName());
         returnQos.getData().addClientProperty(Constants.CLIENTPROPERTY_RCVTIMESTAMPSTR, IsoDateParser.getCurrentUTCTimestampNanos());


         // Now some nice logging ...
         StringBuffer sb = new StringBuffer(256);
         if (connectQos.bypassCredentialCheck())
            sb.append("Created tempory session for client ");
         else
            sb.append("Successful login for client ");
         sb.append(sessionInfo.getSessionName().getAbsoluteName());
         sb.append(", session");
         sb.append(((connectQos.getSessionTimeout() > 0L) ?
                         " expires after"+Timestamp.millisToNice(connectQos.getSessionTimeout()) :
                         " lasts forever"));
         sb.append(", ").append(subjectInfo.getNumSessions()).append(" of ");
         sb.append(connectQos.getMaxSessions()).append(" sessions are in use.");
         log.info(sb.toString());
         if (log.isLoggable(Level.FINEST)) log.finest(toXml());
         if (log.isLoggable(Level.FINEST)) log.finest("Returned QoS:\n" + returnQos.toXml());
         if (log.isLoggable(Level.FINER)) log.finer("Leaving connect()");

         return returnQos;
      }
      catch (XmlBlasterException e) {
View Full Code Here

   {
      String returnValue = null;
      ConnectQosServer connectQos = new ConnectQosServer(glob, qos_literal);
      if (log.isLoggable(Level.FINER)) log.finer("Entering connect(qos=" + qos_literal + ")");
      connectQos.setAddressServer(this.addressServer);
      ConnectReturnQosServer returnQos = authenticate.connect(connectQos);
      returnValue = returnQos.toXml();

      return returnValue;
   }
View Full Code Here

         // super.receiveReply() processes all invocations, only connect()/disconnect() we do locally ...
         if (super.receiveReply(receiver, udp) == false) {
            if (MethodName.CONNECT == receiver.getMethodName()) {
               ConnectQosServer conQos = new ConnectQosServer(this.glob, receiver.getQos());
               conQos.setAddressServer(getAddressServer());
               ConnectReturnQosServer retQos = this.authenticate.connect(conQos);
               //As we are a singleton there is no need to remember the secretSessionId of this client
               receiver.setSecretSessionId(retQos.getSecretSessionId()); // executeResponse needs it
               executeResponse(receiver, retQos.toXml(), SocketUrl.SOCKET_TCP);
             }
            else if (MethodName.DISCONNECT == receiver.getMethodName()) {
               executeResponse(receiver, Constants.RET_OK, SocketUrl.SOCKET_TCP);   // ACK the disconnect to the client and then proceed to the server core
               // Note: the disconnect will call over the CbInfo our shutdown as well
               // setting sessionId = null prevents that our shutdown calls disconnect() again.
View Full Code Here

         // Extend qos to contain security credentials ...
         ConnectQosServer loginQos = new ConnectQosServer(glob, qos_literal);
         loginQos.loadClientPlugin(null, null, loginName, passwd);

         // No login using the connect() method ...
         ConnectReturnQosServer returnQos = connectIntern(loginQos.toXml());

         // Build return handle ...
         ServerRef ref = returnQos.getServerRef();
         if (ref == null) {
            throw OrbInstanceFactory.convert(new org.xmlBlaster.util.XmlBlasterException(glob,
                     ErrorCode.INTERNAL_CONNECTIONFAILURE,
                     ME,
                     "Can't determine server reference."));
View Full Code Here

      }
   }

   private ConnectReturnQosServer connectIntern(String qos_literal) throws org.xmlBlaster.util.XmlBlasterException
   {
      ConnectReturnQosServer returnQos = null;
      String sessionId = null;

      org.omg.CORBA.Object certificatedServerRef = null;
      try {
         // set up a association between the new created object reference (oid is sufficient)
         // and the callback object reference
         certificatedServerRef = xmlBlasterPOA.create_reference(ServerHelper.id());
         sessionId = getSessionId(certificatedServerRef);
         // The bytes at IOR position 234 and 378 are increased (there must be the object_id)
         if (log.isLoggable(Level.FINE)) log.fine("Created sessionId="+sessionId);
      } catch (Exception e) {
         e.printStackTrace();
         log.severe(e.toString());
         throw new org.xmlBlaster.util.XmlBlasterException(glob, ErrorCode.INTERNAL_CONNECTIONFAILURE,
                                ME, "connect failed: " + e.toString());
      }

      String returnQosStr = authenticate.connect(this.addressServer, qos_literal, sessionId);
      returnQos = new ConnectReturnQosServer(glob, returnQosStr);
      if (returnQos.isReconnected()) {
         // How to detect outdated server IORs??
         // Here we assume max one connection of type=CORBA which is probably wrong?
         if (log.isLoggable(Level.FINE)) log.fine("Destroying old server addresses because of reconnect");
         returnQos.removeServerRef("IOR");
      }

      org.xmlBlaster.protocol.corba.serverIdl.Server xmlBlaster = org.xmlBlaster.protocol.corba.serverIdl.ServerHelper.narrow(certificatedServerRef);
      String serverIOR = orb.object_to_string(xmlBlaster);
      returnQos.addServerRef(new ServerRef("IOR", serverIOR));

      if (log.isLoggable(Level.FINEST)) log.finest("Returning from login-connect()" + returnQos.toXml());

      return returnQos;
   }
View Full Code Here

         securityQos.setCredential(passwd);
         if (log.isLoggable(Level.FINE)) log.fine("login() method uses supplied loginName=" + loginName + " and password");
      }
        

      ConnectReturnQosServer returnQos = authenticate.connect(connectQos);
      return returnQos.getSecretSessionId();
   }
View Full Code Here

              String sessionId = data.getSessionQos().getSecretSessionId();
              sessionIds.put(sessionName.getAbsoluteName(), sessionId);
              if (log.isLoggable(Level.FINE))
                 log.fine("recoverSessions: store in map session='" + sessionName.getAbsoluteName() + "' has secret sessionId='" + sessionId + "' and persistenceUniqueId=" + entry.getUniqueId());
              // if (log.isLoggable(Level.FINE)) log.trace(ME, "recoverSessions: session: '" + data.getSessionName() + "' secretSessionId='" + qos.getSessionQos().getSecretSessionId() + "' qos='" + qos.toXml() + "'");
              ConnectReturnQosServer ret = this.global.getAuthenticate().connect(qos);
              if (log.isLoggable(Level.FINEST))
                 log.finest("recoverSessions: return of connect: returnConnectQos='" + ret.toXml() + "'");
           }
           else {
              throw new XmlBlasterException(this.global, ErrorCode.INTERNAL_ILLEGALARGUMENT, ME + ".recoverSessions: the entry in the storage should be of type 'SessionEntry' but is of type'" + entries[i].getClass().getName() + "'");
           }
        }
View Full Code Here

                  conQos.getSecurityQos().setClientIp (socket.getInetAddress().getHostAddress());
                  conQos.setAddressServer(getAddressServer());
                  Object callbackSocketDriver = new CallbackSocketDriver(conQos.getSessionName().getLoginName(), this);
                  conQos.getAddressServer().setCallbackDriver(callbackSocketDriver);
                  conQos.getData().getCurrentCallbackAddress().setCallbackDriver(callbackSocketDriver);
                  ConnectReturnQosServer retQos = getAuthenticateCore().connect(conQos);
                  this.secretSessionId = retQos.getSecretSessionId();
                  receiver.setSecretSessionId(retQos.getSecretSessionId()); // executeResponse needs it
                  executeResponse(receiver, retQos.toXml(), SocketUrl.SOCKET_TCP);
               }
               else if (MethodName.DISCONNECT == receiver.getMethodName()) {
                  executeResponse(receiver, Constants.RET_OK, SocketUrl.SOCKET_TCP);   // ACK the disconnect to the client and then proceed to the server core
                  // Note: the disconnect will call over the CbInfo our shutdown as well
                  // setting sessionId = null prevents that our shutdown calls disconnect() again.
View Full Code Here

TOP

Related Classes of org.xmlBlaster.engine.qos.ConnectReturnQosServer

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.