Class LocalClientSession
java.lang.Object
org.jivesoftware.openfire.session.LocalSession
org.jivesoftware.openfire.session.LocalClientSession
- All Implemented Interfaces:
ChannelHandler<org.xmpp.packet.Packet>,RoutableChannelHandler,ClientSession,Session
- Direct Known Subclasses:
HttpSession
Represents a session between the server and a client.
- Author:
- Gaston Dombiak
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jivesoftware.openfire.session.Session
Session.Status -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AuthTokenThe authentication token for this session.protected final CsiManagerXEP-0352 Client State Indication ManagerFields inherited from class org.jivesoftware.openfire.session.LocalSession
address, conn, serverName, sessionManager, startDate, status, streamID, streamManagerFields inherited from interface org.jivesoftware.openfire.session.Session
MAJOR_VERSION, MINOR_VERSION -
Constructor Summary
ConstructorsConstructorDescriptionLocalClientSession(String serverName, Connection connection, StreamID streamID, Locale language) Creates a session with an underlying connection and permission protection. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanDeliver(org.xmpp.packet.Packet stanza) Returns true if the specified packet must not be blocked based on the active or default privacy list rules.booleanReturns true if the offline messages of the user should be sent to the user when the user becomes online.static LocalClientSessioncreateSession(String serverName, org.xmlpull.v1.XmlPullParser xpp, Connection connection) Returns a newly created session between the server and a client.voiddeliver(org.xmpp.packet.Packet queueOrPushStanza) Returns the Privacy list that overrides the default privacy list.Returns the authentication token associated with this session.List<org.dom4j.Element>Returns a text with the available stream features.Returns the list of IP address that are disallowed to connect to the server.Returns the Client State Indication manager for this session.Returns the default Privacy list used for the session's user.org.xmpp.packet.PresenceObtain the presence of this session.Returns the username associated with this session.Returns the list of IP address that are allowed to connect to the server for anonymous users.Returns the list of IP address that are allowed to connect to the server.booleanIndicates whether this session has requested a blocklist, as specified in XEP-0191.intIncrements the conflict by one.static booleanisAddressInRange(byte[] address, Set<String> ranges) Deprecated, for removal: This API element is subject to removal in a future version.static booleanisAllowed(Connection connection) static booleanisAllowedAnonymous(Connection connection) booleanReturns true if the authenticated user is an anonymous user or if the use has not authenticated yet.booleanFlag indicating if this session has been initialized once coming online.booleanIndicates, whether message carbons are enabled.booleanReturns true if the user requested to not receive offline messages when sending an available presence.voidreattach(LocalSession connectionProvider, long h) Reattach the (existing) session to the connection provided by a new session (a session that will be replaced by the older, pre-existing session).voidsetActiveList(PrivacyList activeList) Sets the Privacy list that overrides the default privacy list.voidsetAddress(org.xmpp.packet.JID address) Sets the new address of this session.voidInitialize the session as an anonymous login.voidsetAuthToken(AuthToken auth) Sets the new Authorization Token for this session.voidsetAuthToken(AuthToken auth, String resource) Initialize the session with a valid authentication token and resource name.static voidsetBlacklistedIPs(Set<String> blocked) Sets the list of IP address that are not allowed to connect to the server.voidsetDefaultList(PrivacyList defaultList) Sets the default Privacy list used for the session's user.voidsetHasRequestedBlocklist(boolean hasRequestedBlocklist) Defines if this session has requested a blocklist, as specified in XEP-0191.voidsetInitialized(boolean isInit) Sets the initialization state of the session.voidsetMessageCarbonsEnabled(boolean enabled) Enables or disables XEP-0280: Message Carbons for this session.voidsetOfflineFloodStopped(boolean offlineFloodStopped) Sets if the user requested to not receive offline messages when sending an available presence.voidsetPresence(org.xmpp.packet.Presence presence) Set the presence of this sessionstatic voidsetWhitelistedAnonymousIPs(Set<String> allowed) Sets the list of IP address that are allowed to connect to the server for anonymous users.static voidsetWhitelistedIPs(Set<String> allowed) Sets the list of IP address that are allowed to connect to the server.toString()booleanReturns true if the session was available ever.Methods inherited from class org.jivesoftware.openfire.session.LocalSession
close, deliverRawText, getAddress, getCipherSuiteName, getConnection, getCreationDate, getHostAddress, getHostName, getLanguage, getLastActiveDate, getNumClientPackets, getNumServerPackets, getPeerCertificates, getServerName, getSessionData, getSoftwareVersion, getStatus, getStreamID, getStreamManager, getTLSProtocolName, incrementClientPacketCount, incrementServerPacketCount, isClosed, isDetached, isEncrypted, isUsingSelfSignedCertificate, process, removeSessionData, setDetached, setSessionData, setSoftwareVersionData, setStatus, validateMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jivesoftware.openfire.session.Session
close, deliverRawText, getAddress, getCipherSuiteName, getCreationDate, getHostAddress, getHostName, getLanguage, getLastActiveDate, getNumClientPackets, getNumServerPackets, getPeerCertificates, getServerName, getSoftwareVersion, getStatus, getStreamID, getTLSProtocolName, isAuthenticated, isClosed, isDetached, isEncrypted, process, validate
-
Field Details
-
authToken
The authentication token for this session. -
csiManager
XEP-0352 Client State Indication Manager
-
-
Constructor Details
-
LocalClientSession
public LocalClientSession(String serverName, Connection connection, StreamID streamID, Locale language) Creates a session with an underlying connection and permission protection.- Parameters:
serverName- name of the server.connection- The connection we are proxying.streamID- unique identifier of this session.language- the language
-
-
Method Details
-
getWhitelistedIPs
Returns the list of IP address that are allowed to connect to the server. If the list is empty then anyone is allowed to connect to the server except for anonymous users that are subject togetWhitelistedAnonymousIPs(). This list is used for both anonymous and non-anonymous users. Note that the blacklist ingetBlacklistedIPs()should take precedence!- Returns:
- the collection of IP address that are allowed to connect to the server. Never null, possibly empty.
-
getWhitelistedAnonymousIPs
Returns the list of IP address that are allowed to connect to the server for anonymous users. If the list is empty then anonymous will be only restricted bygetWhitelistedIPs(). Note that the blacklist ingetBlacklistedIPs()should take precedence!- Returns:
- the collection of IP address that are allowed to connect to the server. Never null, possibly empty.
-
getBlacklistedIPs
Returns the list of IP address that are disallowed to connect to the server. If the list is empty then anyone is allowed to connect to the server, subject to whitelisting. This list is used for both anonymous and non-anonymous users.- Returns:
- the collection of IP address that are not allowed to connect to the server. Never null, possibly empty.
-
createSession
public static LocalClientSession createSession(String serverName, org.xmlpull.v1.XmlPullParser xpp, Connection connection) throws org.xmlpull.v1.XmlPullParserException Returns a newly created session between the server and a client. The session will be created and returned only if correct name/prefix ('stream') and namespace were provided by the client.- Parameters:
serverName- the name of the server where the session is connecting to.xpp- the parser that is reading the provided XML through the connection.connection- the connection with the client.- Returns:
- a newly created session between the server and a client.
- Throws:
org.xmlpull.v1.XmlPullParserException- if an error occurs while parsing incoming data.
-
isAllowed
-
isAllowedAnonymous
-
isAddressInRange
@Deprecated(forRemoval=true, since="5.0.0") public static boolean isAddressInRange(byte[] address, Set<String> ranges) Deprecated, for removal: This API element is subject to removal in a future version. -
setWhitelistedIPs
Sets the list of IP address that are allowed to connect to the server. If the list is empty then anyone not ongetBlacklistedIPs()is allowed to connect to the server except for anonymous users that are subject togetWhitelistedAnonymousIPs(). This list is used for both anonymous and non-anonymous users. Note that blacklisting takes precedence over whitelisting: if an address is matched by both, access is denied.- Parameters:
allowed- the list of IP address that are allowed to connect to the server. Can be empty, but not null.
-
setWhitelistedAnonymousIPs
Sets the list of IP address that are allowed to connect to the server for anonymous users. If the list is empty then anonymous will be only restricted bygetBlacklistedIPs()andgetWhitelistedIPs().- Parameters:
allowed- the list of IP address that are allowed to connect to the server. Can be empty, but not null.
-
setBlacklistedIPs
Sets the list of IP address that are not allowed to connect to the server. This list is used for both anonymous and non-anonymous users, and always takes precedence over a whitelist.- Parameters:
blocked- the list of IP address that are not allowed to connect to the server. Can be empty, but not null.
-
getActiveList
Returns the Privacy list that overrides the default privacy list. This list affects only this session and only for the duration of the session.- Specified by:
getActiveListin interfaceClientSession- Returns:
- the Privacy list that overrides the default privacy list.
-
setActiveList
Sets the Privacy list that overrides the default privacy list. This list affects only this session and only for the duration of the session.- Specified by:
setActiveListin interfaceClientSession- Parameters:
activeList- the Privacy list that overrides the default privacy list.
-
getDefaultList
Returns the default Privacy list used for the session's user. This list is processed if there is no active list set for the session.- Specified by:
getDefaultListin interfaceClientSession- Returns:
- the default Privacy list used for the session's user.
-
setDefaultList
Sets the default Privacy list used for the session's user. This list is processed if there is no active list set for the session.- Specified by:
setDefaultListin interfaceClientSession- Parameters:
defaultList- the default Privacy list used for the session's user.
-
getUsername
Returns the username associated with this session. Use this information with the user manager to obtain the user based on username.- Specified by:
getUsernamein interfaceClientSession- Returns:
- the username associated with this session
- Throws:
UserNotFoundException- if a user is not associated with a session (the session has not authenticated yet)
-
setAuthToken
Sets the new Authorization Token for this session. The session is not yet considered fully authenticated (i.e. active) since a resource has not been bound at this point. This message will be sent after SASL authentication was successful but yet resource binding is required.- Parameters:
auth- the authentication token obtained from SASL authentication.
-
setAuthToken
Initialize the session with a valid authentication token and resource name. This automatically upgrades the session's status to authenticated and enables many features that are not available until authenticated (obtaining managers for example).- Parameters:
auth- the authentication token obtained from the AuthFactory.resource- the resource this session authenticated under.
-
setAddress
public void setAddress(@Nonnull org.xmpp.packet.JID address) Description copied from class:LocalSessionSets the new address of this session. The address is used by services like the core server packet router to determine if a packet should be sent to the handler. Handlers that are working on behalf of the server should use the generic server hostname address (e.g. server.com).- Overrides:
setAddressin classLocalSession- Parameters:
address- the new address of this session.
-
setAnonymousAuth
public void setAnonymousAuth()Initialize the session as an anonymous login. This automatically upgrades the session's status to authenticated and enables many features that are not available until authenticated (obtaining managers for example). -
getAuthToken
Returns the authentication token associated with this session.- Returns:
- the authentication token associated with this session (can be null).
-
isAnonymousUser
public boolean isAnonymousUser()Description copied from interface:ClientSessionReturns true if the authenticated user is an anonymous user or if the use has not authenticated yet.- Specified by:
isAnonymousUserin interfaceClientSession- Returns:
- true if the authenticated user is an anonymous user or if the use has not authenticated yet.
-
isInitialized
public boolean isInitialized()Flag indicating if this session has been initialized once coming online. Session initialization occurs after the session receives the first "available" presence update from the client. Initialization actions include pushing offline messages, presence subscription requests, and presence statuses to the client. Initialization occurs only once following the first available presence transition.- Specified by:
isInitializedin interfaceClientSession- Returns:
- True if the session has already been initialized
-
setInitialized
public void setInitialized(boolean isInit) Sets the initialization state of the session.- Specified by:
setInitializedin interfaceClientSession- Parameters:
isInit- True if the session has been initialized- See Also:
-
wasAvailable
public boolean wasAvailable()Returns true if the session was available ever.- Returns:
- true if the session was available ever.
-
canFloodOfflineMessages
public boolean canFloodOfflineMessages()Returns true if the offline messages of the user should be sent to the user when the user becomes online. If the user sent a disco request with node "http://jabber.org/protocol/offline" before the available presence then do not flood the user with the offline messages. If the user is connected from many resources then if one of the sessions stopped the flooding then no session should flood the user.- Specified by:
canFloodOfflineMessagesin interfaceClientSession- Returns:
- true if the offline messages of the user should be sent to the user when the user becomes online.
- See Also:
-
isOfflineFloodStopped
public boolean isOfflineFloodStopped()Returns true if the user requested to not receive offline messages when sending an available presence. The user may send a disco request with node "http://jabber.org/protocol/offline" so that no offline messages are sent to the user when he becomes online. If the user is connected from many resources then if one of the sessions stopped the flooding then no session should flood the user.- Specified by:
isOfflineFloodStoppedin interfaceClientSession- Returns:
- true if the user requested to not receive offline messages when sending an available presence.
-
setOfflineFloodStopped
public void setOfflineFloodStopped(boolean offlineFloodStopped) Sets if the user requested to not receive offline messages when sending an available presence. The user may send a disco request with node "http://jabber.org/protocol/offline" so that no offline messages are sent to the user when he becomes online. If the user is connected from many resources then if one of the sessions stopped the flooding then no session should flood the user.- Parameters:
offlineFloodStopped- if the user requested to not receive offline messages when sending an available presence.
-
reattach
Description copied from class:LocalSessionReattach the (existing) session to the connection provided by a new session (a session that will be replaced by the older, pre-existing session). The connection must already be initialized as a running XML Stream, normally by having run through XEP-0198 resumption.- Overrides:
reattachin classLocalSession- Parameters:
connectionProvider- Session from which to obtain the connection from.h- the sequence number of the last handled stanza sent over the former stream
-
getCsiManager
Returns the Client State Indication manager for this session.- Returns:
- A Client State Indication manager
-
getPresence
public org.xmpp.packet.Presence getPresence()Obtain the presence of this session.- Specified by:
getPresencein interfaceClientSession- Returns:
- The presence of this session or null if not authenticated
-
setPresence
public void setPresence(org.xmpp.packet.Presence presence) Set the presence of this session- Specified by:
setPresencein interfaceClientSession- Parameters:
presence- The presence for the session
-
getAvailableStreamFeatures
Description copied from class:LocalSessionReturns a text with the available stream features. Each subclass may return different values depending whether the session has been authenticated or not.- Specified by:
getAvailableStreamFeaturesin classLocalSession- Returns:
- a text with the available stream features or
nullto add nothing.
-
incrementConflictCount
public int incrementConflictCount()Increments the conflict by one.- Specified by:
incrementConflictCountin interfaceClientSession- Returns:
- the new number of conflicts detected on this session.
-
isMessageCarbonsEnabled
public boolean isMessageCarbonsEnabled()Description copied from interface:ClientSessionIndicates, whether message carbons are enabled.- Specified by:
isMessageCarbonsEnabledin interfaceClientSession- Returns:
- True, if message carbons are enabled.
-
setMessageCarbonsEnabled
public void setMessageCarbonsEnabled(boolean enabled) Description copied from interface:ClientSessionEnables or disables XEP-0280: Message Carbons for this session.- Specified by:
setMessageCarbonsEnabledin interfaceClientSession- Parameters:
enabled- True, if message carbons are enabled.- See Also:
-
hasRequestedBlocklist
public boolean hasRequestedBlocklist()Description copied from interface:ClientSessionIndicates whether this session has requested a blocklist, as specified in XEP-0191.- Specified by:
hasRequestedBlocklistin interfaceClientSession- Returns:
- true when a blocklist was requested, otherwise false;
-
setHasRequestedBlocklist
public void setHasRequestedBlocklist(boolean hasRequestedBlocklist) Description copied from interface:ClientSessionDefines if this session has requested a blocklist, as specified in XEP-0191.- Specified by:
setHasRequestedBlocklistin interfaceClientSession- Parameters:
hasRequestedBlocklist- True when a blocklist has been requested by this session, otherwise false.
-
canDeliver
public boolean canDeliver(@Nonnull org.xmpp.packet.Packet stanza) Returns true if the specified packet must not be blocked based on the active or default privacy list rules. The active list will be tried first. If none was found then the default list is going to be used. If no default list was defined for this user then allow the packet to flow.- Parameters:
stanza- the packet to analyze if it must be blocked.- Returns:
- true if the specified packet must *not* be blocked.
-
deliver
- Throws:
UnauthorizedException
-
toString
- Overrides:
toStringin classLocalSession
-