Package tigase.xmpp
Class XMPPResourceConnection
- java.lang.Object
-
- tigase.xmpp.RepositoryAccess
-
- tigase.xmpp.XMPPResourceConnection
-
- Direct Known Subclasses:
JabberIqPrivacy.OfflineResourceConnection,SMResourceConnection
public class XMPPResourceConnection extends RepositoryAccess
Describe class XMPPResourceConnection here.
Created: Wed Feb 8 22:30:37 2006- Version:
- $Rev$
- Author:
- Artur Hefczyc
-
-
Field Summary
Fields Modifier and Type Field Description static StringALL_RESOURCES_CAPS_KEYstatic StringALL_RESOURCES_KEYstatic StringALL_RESOURCES_PRIORITY_KEYstatic StringAUTHENTICATION_TIMEOUT_KEYstatic StringCLOSING_KEYstatic StringERROR_KEYstatic StringPRESENCE_KEYConstantPRESENCE_KEYis a key in temporary session data where the last presence sent by the user to server is stored, either initial presence or off-line presence before disconnecting.-
Fields inherited from class tigase.xmpp.RepositoryAccess
authRepo, authState, domain, is_anonymous, NO_ACCESS_TO_REP_MSG, NOT_AUTHORIZED_MSG
-
-
Constructor Summary
Constructors Constructor Description XMPPResourceConnection(JID connectionId, UserRepository rep, AuthRepository authRepo, SessionManagerHandler loginHandler)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidauthorizeJID(BareJID jid, boolean anonymous)ObjectcomputeCommonSessionDataIfAbsent(String key, Function<String,Object> valueFactory)Method checks if inparentSessionin session data there is value for passedkeyand returns it if exists.ObjectcomputeSessionDataIfAbsent(String key, Function<String,Object> valueFactory)Method checks if in session data is value for passedkeyand returns it if exists.List<XMPPResourceConnection>getActiveSessions()Method returns list of active connection for the sameXMPPSession.JID[]getAllResourcesJIDs()Method returns list of jids of all connections for the sameXMPPSession(same user).AuthRepositorygetAuthRepository()longgetAuthTime()BareJIDgetBareJID()Returns user JID but without resource part.ObjectgetCommonSessionData(String key)JIDgetConnectionId()Gets the value of connectionIdJIDgetConnectionId(boolean updateLastAccessed)JIDgetConnectionId(JID jid)longgetCreationTime()StringgetDefLang()JIDgetjid()Returns full user JID for this session without throwing theNotAuthorizedExceptionexception if session is not authorized yet and therefore user name and resource is not known yet.JIDgetJID()Returns full user JID for this session or throwsNotAuthorizedExceptionif session is not authorized yet and therefore user name and resource is not known yet.longgetLastAccessed()Gets the value of lastAccessedlonggetPacketsCounter()XMPPSessiongetParentSession()ElementgetPresence()Returns last presence packet with the user presence status ornullif the user has not yet sent an initial presence.intgetPriority()StringgetResource()Gets the value of resourceObjectgetSessionData(String key)Retrieves session data.StringgetSessionId()Gets the value of sessionIdJIDgetSMComponentId()BareJIDgetUserId()Deprecated.StringgetUserName()voidincPacketsCounter()booleanisAuthorized()This method allows you test this session if it already has been authorized.booleanisEncrypted()booleanisLocalDomain(String outDomain, boolean includeComponents)booleanisResourceSet()booleanisServerSession()Returns information whether this is a server (SessionManager) session or normal user session.booleanisTlsRequired()booleanisTmpSession()booleanisUserId(BareJID bareJID)protected voidlogin()AuthorizationloginDigest(String user, String digest, String id, String alg)Deprecated.AuthorizationloginOther(Map<String,Object> props)Deprecated.AuthorizationloginPlain(String user, String password)Deprecated.voidlogout()StringnextStanzaId()voidputCommonSessionData(String key, Object value)Method sets passed value under passed key in common sessionData kept in parentSessionObjectputCommonSessionDataIfAbsent(String key, Object value)Method sets passed value under passedkeyin commonsessionDatakept inparentSessionbut only if there is no value for thiskeyalreadyvoidputSessionData(String key, Object value)Saves given session data.ObjectputSessionDataIfAbsent(String key, Object value)Method sets passed value under passedkeyinsessionDatabut only if there is no value for thiskeyalreadyvoidqueryAuth(Map<String,Object> authProps)ObjectremoveCommonSessionData(String key)voidremoveParentSession(XMPPSession parent)voidremoveSessionData(String key)voidsetConnectionId(JID connectionId)Sets the value of connectionIdvoidsetDefLang(String lang)voidsetLastAccessed(long argLastAccessed)Sets the value of lastAccessedvoidsetParentSession(XMPPSession parent)voidsetPresence(Element packet)voidsetPriority(int priority)voidsetResource(String argResource)Sets the connection resourcevoidsetSessionId(String argSessionId)Sets the value of sessionIdvoidsetTmpSession(boolean tmp)voidstreamClosed()StringtoString()Authorizationunregister(String name_param)Deprecated.-
Methods inherited from class tigase.xmpp.RepositoryAccess
addDataList, addOfflineDataList, addPublicDataList, changeRegistration, getAuthenticationToken, getAuthState, getData, getDataGroups, getDataKeys, getDataList, getDomain, getDomainAsJID, getOfflineData, getOfflineDataList, getPublicData, getPublicDataList, isAnonymous, loginDigest, loginPlain, loginToken, register, register, removeData, removeDataGroup, removeOfflineData, removeOfflineDataGroup, removePublicData, removePublicDataGroup, setData, setDataList, setDomain, setOfflineData, setOfflineDataList, setPublicData, setPublicDataList, setRegistration
-
-
-
-
Field Detail
-
ALL_RESOURCES_CAPS_KEY
public static final String ALL_RESOURCES_CAPS_KEY
- See Also:
- Constant Field Values
-
ALL_RESOURCES_KEY
public static final String ALL_RESOURCES_KEY
- See Also:
- Constant Field Values
-
ALL_RESOURCES_PRIORITY_KEY
public static final String ALL_RESOURCES_PRIORITY_KEY
- See Also:
- Constant Field Values
-
AUTHENTICATION_TIMEOUT_KEY
public static final String AUTHENTICATION_TIMEOUT_KEY
- See Also:
- Constant Field Values
-
CLOSING_KEY
public static final String CLOSING_KEY
- See Also:
- Constant Field Values
-
ERROR_KEY
public static final String ERROR_KEY
- See Also:
- Constant Field Values
-
PRESENCE_KEY
public static final String PRESENCE_KEY
ConstantPRESENCE_KEYis a key in temporary session data where the last presence sent by the user to server is stored, either initial presence or off-line presence before disconnecting.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
XMPPResourceConnection
public XMPPResourceConnection(JID connectionId, UserRepository rep, AuthRepository authRepo, SessionManagerHandler loginHandler)
-
-
Method Detail
-
authorizeJID
public void authorizeJID(BareJID jid, boolean anonymous) throws TigaseStringprepException
- Throws:
TigaseStringprepException
-
computeCommonSessionDataIfAbsent
public Object computeCommonSessionDataIfAbsent(String key, Function<String,Object> valueFactory)
Method checks if inparentSessionin session data there is value for passedkeyand returns it if exists. If not then it uses passedvalueFactoryto generate value and sets it inparentSessionin session data under passedkeyand returns newly set value- Parameters:
key-valueFactory-- Returns:
-
computeSessionDataIfAbsent
public Object computeSessionDataIfAbsent(String key, Function<String,Object> valueFactory)
Method checks if in session data is value for passedkeyand returns it if exists. If not then it uses passedvalueFactoryto generate value and sets it in session data under passedkeyand returns newly set value- Parameters:
key-valueFactory-- Returns:
-
getjid
public final JID getjid()
Returns full user JID for this session without throwing theNotAuthorizedExceptionexception if session is not authorized yet and therefore user name and resource is not known yet. Please note this method is for logging using only to avoid excessive use of try/catch for debugging code. It may return null.- Returns:
- a
Stringvalue of calculated user full JID for this session including resource name.
-
incPacketsCounter
public void incPacketsCounter()
-
loginDigest
@Deprecated public final Authorization loginDigest(String user, String digest, String id, String alg) throws NotAuthorizedException, AuthorizationException, TigaseDBException, TigaseStringprepException
Deprecated.
-
loginOther
@Deprecated public final Authorization loginOther(Map<String,Object> props) throws NotAuthorizedException, AuthorizationException, TigaseDBException
Deprecated.- Overrides:
loginOtherin classRepositoryAccess- Throws:
NotAuthorizedExceptionAuthorizationExceptionTigaseDBException
-
loginPlain
@Deprecated public final Authorization loginPlain(String user, String password) throws NotAuthorizedException, AuthorizationException, TigaseDBException, TigaseStringprepException
Deprecated.
-
logout
public final void logout() throws NotAuthorizedException- Overrides:
logoutin classRepositoryAccess- Throws:
NotAuthorizedException
-
nextStanzaId
public String nextStanzaId()
-
putCommonSessionData
public void putCommonSessionData(String key, Object value)
Method sets passed value under passed key in common sessionData kept in parentSession- Parameters:
key-value-
-
putCommonSessionDataIfAbsent
public Object putCommonSessionDataIfAbsent(String key, Object value)
Method sets passed value under passedkeyin commonsessionDatakept inparentSessionbut only if there is no value for thiskeyalready- Parameters:
key-value-- Returns:
- previous value
-
putSessionData
public final void putSessionData(String key, Object value)
Saves given session data. Data are saved to temporary storage only and are accessible during this session life only and only from this session instance.
AnyObjectcan be stored and retrieved throughgetSessionData(...).
To access permanent storage to keep data between session instances you must use one ofget/setData...(...)methods familly. They gives you access to hierachical permanent data base. Permanent data base however can be accessed after successuf authorization while session storage is availble all the time.- Parameters:
key- aStringvalue of stored data key ID.value- aObjectvalue of data stored in session.- See Also:
getSessionData(String)
-
putSessionDataIfAbsent
public Object putSessionDataIfAbsent(String key, Object value)
Method sets passed value under passedkeyinsessionDatabut only if there is no value for thiskeyalready- Parameters:
key-value-- Returns:
- previous value
-
queryAuth
public void queryAuth(Map<String,Object> authProps) throws TigaseDBException
- Overrides:
queryAuthin classRepositoryAccess- Throws:
TigaseDBException
-
removeParentSession
public void removeParentSession(XMPPSession parent)
-
removeSessionData
public final void removeSessionData(String key)
-
streamClosed
public void streamClosed()
-
getActiveSessions
public List<XMPPResourceConnection> getActiveSessions() throws NotAuthorizedException
Method returns list of active connection for the sameXMPPSession.- Returns:
- a value of
List<XMPPResourceConnection> - Throws:
NotAuthorizedException
-
getAllResourcesJIDs
public JID[] getAllResourcesJIDs()
Method returns list of jids of all connections for the sameXMPPSession(same user).- Returns:
- a value of
JID[]
-
getAuthRepository
public AuthRepository getAuthRepository()
-
getAuthTime
public long getAuthTime()
-
getBareJID
public final BareJID getBareJID() throws NotAuthorizedException
Description copied from class:RepositoryAccessReturns user JID but without resource part. This is real user ID not session ID. To retrieve session ID - full JID refer togetJID()method.
If session has not been authorized yet this method throwsNotAuthorizedException.- Specified by:
getBareJIDin classRepositoryAccess- Returns:
- a
Stringvalue of user ID - this is user JID without resource part. To obtain full user JID please refer togetJIDmethod. - Throws:
NotAuthorizedException- when this session has not been authorized yet and some parts of user JID are not known yet.
-
getConnectionId
public JID getConnectionId() throws NoConnectionIdException
Gets the value of connectionId- Returns:
- the value of connectionId
- Throws:
NoConnectionIdException
-
getConnectionId
public JID getConnectionId(boolean updateLastAccessed) throws NoConnectionIdException
- Throws:
NoConnectionIdException
-
setConnectionId
public void setConnectionId(JID connectionId)
Sets the value of connectionId- Parameters:
connectionId- is aJID
-
getConnectionId
public JID getConnectionId(JID jid) throws NoConnectionIdException
- Throws:
NoConnectionIdException
-
getCreationTime
public long getCreationTime()
-
getDefLang
public String getDefLang()
-
setDefLang
public void setDefLang(String lang)
-
getJID
public final JID getJID() throws NotAuthorizedException
Returns full user JID for this session or throwsNotAuthorizedExceptionif session is not authorized yet and therefore user name and resource is not known yet.- Returns:
- a
Stringvalue of calculated user full JID for this session including resource name. - Throws:
NotAuthorizedException
-
getLastAccessed
public long getLastAccessed()
Gets the value of lastAccessed- Returns:
- the value of lastAccessed
-
setLastAccessed
public void setLastAccessed(long argLastAccessed)
Sets the value of lastAccessed- Parameters:
argLastAccessed- Value to assign to this.lastAccessed
-
getPacketsCounter
public long getPacketsCounter()
-
getParentSession
public XMPPSession getParentSession()
-
setParentSession
public void setParentSession(XMPPSession parent) throws TigaseStringprepException
- Throws:
TigaseStringprepException
-
getPresence
public Element getPresence()
Returns last presence packet with the user presence status ornullif the user has not yet sent an initial presence.- Returns:
- an
Elementwith last presence status received from the user.
-
setPresence
public void setPresence(Element packet)
-
getPriority
public int getPriority()
-
setPriority
public void setPriority(int priority)
-
getResource
public String getResource()
Gets the value of resource- Returns:
- the value of resource
-
setResource
public void setResource(String argResource) throws NotAuthorizedException, TigaseStringprepException
Sets the connection resource- Parameters:
argResource- Value to assign to this.resource- Throws:
NotAuthorizedExceptionTigaseStringprepException
-
getSessionData
public final Object getSessionData(String key)
Retrieves session data. This method gives access to temporary session data only. You can retrieve earlier saved data giving key ID to receive needed value. Please seeputSessionDatadescription for more details.- Parameters:
key- aStringvalue of stored data ID.- Returns:
- a
Objectvalue of data for given key. - See Also:
putSessionData(String, Object)
-
getSessionId
public String getSessionId()
Gets the value of sessionId- Returns:
- the value of sessionId
-
setSessionId
public void setSessionId(String argSessionId)
Sets the value of sessionId- Parameters:
argSessionId- Value to assign to this.sessionId
-
getSMComponentId
public JID getSMComponentId()
-
getUserId
@Deprecated public BareJID getUserId() throws NotAuthorizedException
Deprecated.To get the user bare JID please usegetBareJIDmethod, to check the whether the user with given BareJID is owner of the session please use methodisUserId(...). From now one the user session may handle more than a single userId, hence getting just userId is not enough to check whether the user Id belongs to the session.- Returns:
- a value of
BareJID - Throws:
NotAuthorizedException
-
getUserName
public final String getUserName() throws NotAuthorizedException
- Specified by:
getUserNamein classRepositoryAccess- Throws:
NotAuthorizedException
-
isAuthorized
public boolean isAuthorized()
Description copied from class:RepositoryAccessThis method allows you test this session if it already has been authorized. Iftrueis returned as method result it means session has already been authorized, iffalsehowever session is still not authorized.- Overrides:
isAuthorizedin classRepositoryAccess- Returns:
- a
booleanvalue which informs whether this session has been already authorized or not.
-
isLocalDomain
public boolean isLocalDomain(String outDomain, boolean includeComponents)
-
isResourceSet
public boolean isResourceSet()
-
isServerSession
public boolean isServerSession()
Returns information whether this is a server (SessionManager) session or normal user session. The server session is used to handle packets addressed to the server itself (local domain name).- Returns:
- a
booleanvalue oftrueif this is the server session andfalseotherwise.
-
isTmpSession
public boolean isTmpSession()
-
setTmpSession
public void setTmpSession(boolean tmp)
-
isUserId
public boolean isUserId(BareJID bareJID) throws NotAuthorizedException
- Throws:
NotAuthorizedException
-
unregister
@Deprecated public Authorization unregister(String name_param) throws NotAuthorizedException, TigaseDBException, TigaseStringprepException
Deprecated.- Overrides:
unregisterin classRepositoryAccess- Throws:
NotAuthorizedExceptionTigaseDBExceptionTigaseStringprepException
-
isEncrypted
public boolean isEncrypted()
-
isTlsRequired
public boolean isTlsRequired()
-
login
protected void login()
- Specified by:
loginin classRepositoryAccess
-
-