📄 connectqos.java
字号:
/*------------------------------------------------------------------------------Name: ConnectQos.javaProject: xmlBlaster.orgCopyright: xmlBlaster.org, see xmlBlaster-LICENSE file------------------------------------------------------------------------------*/package org.xmlBlaster.client.qos;import org.xmlBlaster.util.Global;import org.xmlBlaster.util.XmlBlasterException;import org.xmlBlaster.util.SessionName;import org.xmlBlaster.util.def.Constants;import org.xmlBlaster.util.qos.ConnectQosData;import org.xmlBlaster.util.qos.SessionQos;import org.xmlBlaster.util.qos.ClientProperty;import org.xmlBlaster.authentication.plugins.I_SecurityQos;import org.xmlBlaster.util.qos.address.Address;import org.xmlBlaster.util.qos.address.AddressBase;import org.xmlBlaster.util.qos.address.CallbackAddress;import org.xmlBlaster.util.qos.storage.ClientQueueProperty;import org.xmlBlaster.util.qos.storage.CbQueueProperty;import org.xmlBlaster.authentication.plugins.I_ClientPlugin;/** * This class encapsulates the qos of a connect() invocation. * <p /> * @see org.xmlBlaster.util.qos.ConnectQosSaxFactory * @see <a href="http://www.xmlblaster.org/xmlBlaster/doc/requirements/interface.connect.html">connect interface</a> */public final class ConnectQos{ private final Global glob; private final ConnectQosData connectQosData; private boolean doSendConnect=true; /** Access to encrypt/decrypt framework, used by protocol plugins */ //private I_MsgSecurityInterceptor securityInterceptor; /** * Default constructor. * <p> * Initializes login credentials from environment e.g. <i>-session.name guest</i> and <i>-passwd secret</i> with * the default security plugin as given by <i>-Security.Client.DefaultPlugin htpasswd,1.0</i> * </p> * <p> * To use another security authentication plugin use setSecurity() * @exception XmlBlasterException on problems loading the client security plugin */ public ConnectQos(Global glob) throws XmlBlasterException { this.glob = (glob==null) ? Global.instance() : glob; this.connectQosData = new ConnectQosData(this.glob); init(); } /** * Login with the default security plugin as given by <i>-Security.Client.DefaultPlugin htpasswd,1.0</i> * @param userId e.g. "joe" or "joe/7" if you want to connect to joe's seventh session * @param passwd The password if you use a password based authentication * @exception XmlBlasterException if the default security plugin couldn't be loaded */ public ConnectQos(Global glob, String userId, String passwd) throws XmlBlasterException { this.glob = (glob==null) ? Global.instance() : glob; this.connectQosData = new ConnectQosData(this.glob, this.glob.getConnectQosFactory(), null, null); this.connectQosData.loadClientPlugin(null, null, userId, passwd); init(); } /** * Constructor for special use in cluster environment only. */ public ConnectQos(Global glob, ConnectQosData connectQosData) { this.glob = (glob==null) ? Global.instance() : glob; this.connectQosData = connectQosData; init(); } private void init() { this.doSendConnect = this.glob.getProperty().get("dispatch/connection/doSendConnect", true); } public ConnectQosData getData() { return this.connectQosData; } /** * @return The session QoS which contains all session specific configuration, never null */ public SessionQos getSessionQos() { return this.connectQosData.getSessionQos(); } /** * Set the login session name. * <p> * This will NOT set the security loginName (see setUserId()). * </p> * @param sessionName e.g. "joe" which is the loginName (subjectId) only<br /> * e.g. "joe/2" which forces a connect on the public session ID 2 of user joe */ public void setSessionName(SessionName sessionName) { getSessionQos().setSessionName(sessionName); } public SessionName getSessionName() { return getSessionQos().getSessionName(); } /** * Timeout until session expires if no communication happens * @param timeout The login session will be destroyed after given milliseconds.<br /> * Session lasts forever if set to 0L */ public void setSessionTimeout(long timeout) { getSessionQos().setSessionTimeout(timeout); } /** * Set the secret sessionId. * Usually never used, the secret sessionId is generated by the server */ public void setSecretSessionId(String id) { this.connectQosData.getSessionQos().setSecretSessionId(id); } /** * Set the secret cbSessionId. * This is bounced back in the <code>update(cbSessionId, ...)</code> */ public void setSecretCbSessionId(String id) { this.connectQosData.getCurrentCallbackAddress().setSecretCbSessionId(id); } /** * If maxSession == 1, only a single login is possible * @param max How often the same client may login */ public void setMaxSessions(int max) { this.connectQosData.getSessionQos().setMaxSessions(max); } /** * If clearSessions is true, all old sessions of this user are discarded. * @param clear Defaults to false */ public void clearSessions(boolean clear) { this.connectQosData.getSessionQos().clearSessions(clear); } /** * If clearSessions is true, all old sessions of this user are discarded. */ public final boolean clearSessions() { return this.connectQosData.getSessionQos().clearSessions(); } /** * @return refreshSession is true if the client automatically notifies xmlBlaster that it is alive * and the login session is extended */ public final boolean getRefreshSession() { return this.connectQosData.getRefreshSession(); } /** * @param refreshSession true: The client automatically notifies xmlBlaster that it is alive * and the login session is extended */ public final void setRefreshSession(boolean refreshSession) { this.connectQosData.setRefreshSession(refreshSession); } /** * Allows to set or overwrite the login name for I_SecurityQos. * <p> * This will call setSessionName() as well if sessionName is not set yet. * </p> * This is a convenience method to set the securityQos userId * * @param loginName The unique user id */ public void setUserId(String loginName) throws XmlBlasterException { this.connectQosData.setUserId(loginName); } /** * @return The user ID or "NoLoginName" if not known */ public String getUserId() { return this.connectQosData.getUserId(); } /** * Allows to set or overwrite the client side security plugin. * * @param type The client side security plugin to use * @param credential For 'htpasswd' the password, if null the environment -passwd is checked (default plugin) * @see ConnectQosData#loadClientPlugin(String, String, String, String) */ public I_ClientPlugin loadClientPlugin(String type, String version, String userId, String credential) throws XmlBlasterException { //public void setSecurityPluginData(String mechanism, String version, String loginName, String passwd) throws XmlBlasterException { return this.connectQosData.loadClientPlugin(type, version, userId, credential); } /** * Access the default plugin or the previously added by load loadClientPlugin() */ public I_ClientPlugin getClientPlugin() { return this.getClientPlugin(); } /* * Allows to specify how you want to identify yourself. * <p /> * Usage to login to xmlBlaster with a password approach: * <pre> * import org.xmlBlaster.authentication.plugins.simple.SecurityQos; * ... * ConnectQosData qos = new ConnectQosData(null); * qos.setSecurityQos(new SecurityQos("joe", "secret")); * xmlBlasterConnection.connect(qos); * </pre> * NOTE: Usually loadClientPlugin() is easier to use. * @deprecated This is specific to the loaded I_ClientPlugin, please use getClientPlugin().setSecurityQos() */ //public void setSecurityQos(I_SecurityQos securityQos) { // this.connectQosData.setSecurityQos(securityQos); //} /** * This is a convenience method for <code>getClientPlugin().getSecurityQos()</code>. * @return Access the login credentials or null if not set */ public I_SecurityQos getSecurityQos() { return this.connectQosData.getSecurityQos(); } /** * Return the type of the referenced SecurityPlugin. * <p/> * This is a convenience access similiar to * <code>getClientPlugin().getPluginType()</code> * * @return The type or null if not known */ //public String getSecurityPluginType() { // return this.connectQosData.getSecurityPluginType(); //} /** * Return the version of the referenced SecurityPlugin. * <p/> * This is a convenience access similiar to * <code>getClientPlugin().getPluginVersion()</code> *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -