本文整理汇总了Java中org.jivesoftware.openfire.session.LocalClientSession类的典型用法代码示例。如果您正苦于以下问题:Java LocalClientSession类的具体用法?Java LocalClientSession怎么用?Java LocalClientSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LocalClientSession类属于org.jivesoftware.openfire.session包,在下文中一共展示了LocalClientSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: evaluateResponse
import org.jivesoftware.openfire.session.LocalClientSession; //导入依赖的package包/类
@Override
public byte[] evaluateResponse( byte[] response ) throws SaslException
{
if ( isComplete() )
{
throw new IllegalStateException( "Authentication exchange already completed." );
}
complete = true;
// Verify server-wide policy.
if ( !JiveGlobals.getBooleanProperty( "xmpp.auth.anonymous" ) )
{
throw new SaslException( "Authentication failed" );
}
// Verify that client can connect from his IP address.
final boolean forbidAccess = !LocalClientSession.isAllowedAnonymous( session.getConnection() );
if ( forbidAccess )
{
throw new SaslException( "Authentication failed" );
}
// Just accept the authentication :)
return null;
}
示例2: anonymousLogin
import org.jivesoftware.openfire.session.LocalClientSession; //导入依赖的package包/类
private IQ anonymousLogin(LocalClientSession session, IQ packet) {
IQ response = IQ.createResultIQ(packet);
if (JiveGlobals.getBooleanProperty("xmpp.auth.anonymous")) {
// Verify that client can connect from his IP address
boolean forbidAccess = !LocalClientSession.isAllowedAnonymous( session.getConnection() );
if (forbidAccess) {
// Connection forbidden from that IP address
response.setChildElement(packet.getChildElement().createCopy());
response.setError(PacketError.Condition.forbidden);
}
else {
// Anonymous authentication allowed
session.setAnonymousAuth();
response.setTo(session.getAddress());
Element auth = response.setChildElement("query", "jabber:iq:auth");
auth.addElement("resource").setText(session.getAddress().getResource());
}
}
else {
// Anonymous authentication is not allowed
response.setChildElement(packet.getChildElement().createCopy());
response.setError(PacketError.Condition.forbidden);
}
return response;
}
示例3: createClientSession
import org.jivesoftware.openfire.session.LocalClientSession; //导入依赖的package包/类
/**
* Creates a new <tt>ClientSession</tt> with the specified streamID.
*
* @param conn the connection to create the session from.
* @param id the streamID to use for the new session.
* @return a newly created session.
*/
public LocalClientSession createClientSession(Connection conn, StreamID id) {
if (serverName == null) {
throw new IllegalStateException("Server not initialized");
}
LocalClientSession session = new LocalClientSession(serverName, conn, id);
conn.init(session);
// Register to receive close notification on this session so we can
// remove and also send an unavailable presence if it wasn't
// sent before
conn.registerCloseListener(clientSessionListener, session);
// Add to pre-authenticated sessions.
localSessionManager.getPreAuthenticatedSessions().put(session.getAddress().getResource(), session);
// Increment the counter of user sessions
connectionsCounter.incrementAndGet();
return session;
}
示例4: addSession
import org.jivesoftware.openfire.session.LocalClientSession; //导入依赖的package包/类
/**
* Add a new session to be managed. The session has been authenticated and resource
* binding has been done.
*
* @param session the session that was authenticated.
*/
public void addSession(LocalClientSession session) {
// Remove the pre-Authenticated session but remember to use the temporary ID as the key
localSessionManager.getPreAuthenticatedSessions().remove(session.getStreamID().toString());
// Add session to the routing table (routing table will know session is not available yet)
routingTable.addClientRoute(session.getAddress(), session);
SessionEventDispatcher.EventType event = session.getAuthToken().isAnonymous() ?
SessionEventDispatcher.EventType.anonymous_session_created :
SessionEventDispatcher.EventType.session_created;
// Fire session created event.
SessionEventDispatcher.dispatchEvent(session, event);
if (ClusterManager.isClusteringStarted()) {
// Track information about the session and share it with other cluster nodes
sessionInfoCache.put(session.getAddress().toString(), new ClientSessionInfo(session));
}
}
示例5: broadcastPresenceOfOtherResource
import org.jivesoftware.openfire.session.LocalClientSession; //导入依赖的package包/类
/**
* Sends the presences of other connected resources to the resource that just connected.
*
* @param session the newly created session.
*/
private void broadcastPresenceOfOtherResource(LocalClientSession session) {
Presence presence;
// Get list of sessions of the same user
JID searchJID = new JID(session.getAddress().getNode(), session.getAddress().getDomain(), null);
List<JID> addresses = routingTable.getRoutes(searchJID, null);
for (JID address : addresses) {
if (address.equals(session.getAddress())) {
continue;
}
// Send the presence of an existing session to the session that has just changed
// the presence
ClientSession userSession = routingTable.getClientRoute(address);
presence = userSession.getPresence().createCopy();
presence.setTo(session.getAddress());
session.process(presence);
}
}
示例6: onConnectionClose
import org.jivesoftware.openfire.session.LocalClientSession; //导入依赖的package包/类
/**
* Handle a session that just closed.
*
* @param handback The session that just closed
*/
public void onConnectionClose(Object handback) {
try {
LocalClientSession session = (LocalClientSession) handback;
try {
if ((session.getPresence().isAvailable() || !session.wasAvailable()) &&
routingTable.hasClientRoute(session.getAddress())) {
// Send an unavailable presence to the user's subscribers
// Note: This gives us a chance to send an unavailable presence to the
// entities that the user sent directed presences
Presence presence = new Presence();
presence.setType(Presence.Type.unavailable);
presence.setFrom(session.getAddress());
router.route(presence);
}
}
finally {
// Remove the session
removeSession(session);
}
}
catch (Exception e) {
// Can't do anything about this problem...
Log.error(LocaleUtils.getLocalizedString("admin.error.close"), e);
}
}
示例7: sendNotificationToAllUser
import org.jivesoftware.openfire.session.LocalClientSession; //导入依赖的package包/类
/**
* send notification to all users
*
* */
public void sendNotificationToAllUser(String title, String message, String uri){
Log.info("sendNotificationToAllUser.......title = " + title);
IQ notificationIQ = createNotificationIQ("1234567890", title, message, uri);
notificationIQ.setFrom("[email protected]");
Log.info("sendNotificationToAllUser...getIQRouter[].......route[]......");
int sessionNumber = sessionManager.getSessions().size();
Log.info("sendNotificationToAllUser.....get session number = " + sessionNumber);
Iterator iterator = sessionManager.getSessions().iterator();
while (iterator.hasNext()){
Log.info("sendNotificationToAllUser......iterator.hasNext()");
LocalClientSession localClientSession = (LocalClientSession) iterator.next();
if(localClientSession.getPresence().isAvailable()){
notificationIQ.setTo(localClientSession.getAddress());
Log.info("sendNotificationToAllUser......get local session address");
try {
localClientSession.deliver(notificationIQ);
Log.info("sendNotificationToAllUser......deliver");
} catch (UnauthorizedException e) {
e.printStackTrace();
}
}
}
}
示例8: sendNotificationToSignal
import org.jivesoftware.openfire.session.LocalClientSession; //导入依赖的package包/类
/**
* send notification to a signal
* */
public void sendNotificationToSignal(String userName, String title, String message, String uri){
Log.info("sendNotificationToSignal.......title = " + title);
IQ notificationIQ = createNotificationIQ("1234567890", title, message, uri);
notificationIQ.setFrom("[email protected]");
JID userJID = new JID(userName);
LocalClientSession localClientSession = (LocalClientSession) sessionManager.getSession(userJID);
if(localClientSession.getPresence().isAvailable()){
notificationIQ.setTo(localClientSession.getAddress());
Log.info("sendNotificationToSignal......get local session address");
try {
localClientSession.deliver(notificationIQ);
Log.info("sendNotificationToSignal......deliver");
} catch (UnauthorizedException e) {
e.printStackTrace();
}
}
}
示例9: sessionAvailable
import org.jivesoftware.openfire.session.LocalClientSession; //导入依赖的package包/类
/**
* Notification message sent when a client sent an available presence for the session. Making
* the session available means that the session is now eligible for receiving messages from
* other clients. Sessions whose presence is not available may only receive packets (IQ packets)
* from the server. Therefore, an unavailable session remains invisible to other clients.
*
* @param session the session that receieved an available presence.
* @param presence the presence for the session.
*/
public void sessionAvailable(LocalClientSession session, Presence presence) {
if (session.getAuthToken().isAnonymous()) {
// Anonymous session always have resources so we only need to add one route. That is
// the route to the anonymous session
routingTable.addClientRoute(session.getAddress(), session);
}
else {
// A non-anonymous session is now available
// Add route to the new session
routingTable.addClientRoute(session.getAddress(), session);
// Broadcast presence between the user's resources
broadcastPresenceOfOtherResource(session);
broadcastPresenceToOtherResources(session.getAddress(), presence);
}
}
示例10: broadcastPresenceOfOtherResource
import org.jivesoftware.openfire.session.LocalClientSession; //导入依赖的package包/类
/**
* Sends the presences of other connected resources to the resource that just connected.
*
* @param session the newly created session.
*/
private void broadcastPresenceOfOtherResource(LocalClientSession session) {
if (!SessionManager.isOtherResourcePresenceEnabled()) {
return;
}
Presence presence;
// Get list of sessions of the same user
JID searchJID = new JID(session.getAddress().getNode(), session.getAddress().getDomain(), null);
List<JID> addresses = routingTable.getRoutes(searchJID, null);
for (JID address : addresses) {
if (address.equals(session.getAddress())) {
continue;
}
// Send the presence of an existing session to the session that has just changed
// the presence
ClientSession userSession = routingTable.getClientRoute(address);
presence = userSession.getPresence().createCopy();
presence.setTo(session.getAddress());
session.process(presence);
}
}
示例11: createClientSession
import org.jivesoftware.openfire.session.LocalClientSession; //导入依赖的package包/类
/**
* Creates a new client session that was established to the specified connection manager.
* The new session will not be findable through its stream ID.
*
* @param connectionManagerDomain the connection manager that is handling the connection
* of the session.
* @param streamID the stream ID created by the connection manager for the new session.
* @param hostName the address's hostname of the client or null if using old connection manager.
* @param hostAddress the textual representation of the address of the client or null if using old CM.
* @return true if a session was created or false if the client should disconnect.
*/
public boolean createClientSession(String connectionManagerDomain, StreamID streamID, String hostName, String hostAddress) {
Connection connection = new ClientSessionConnection(connectionManagerDomain, hostName, hostAddress);
// Check if client is allowed to connect from the specified IP address. Ignore the checking if connection
// manager is old version and is not passing client's address
byte[] address = null;
try {
address = connection.getAddress();
} catch (UnknownHostException e) {
// Ignore
}
if (address == null || LocalClientSession.isAllowed(connection)) {
LocalClientSession session =
SessionManager.getInstance().createClientSession(connection, streamID);
// Register that this streamID belongs to the specified connection manager
streamIDs.put(streamID, connectionManagerDomain);
// Register which sessions are being hosted by the speicifed connection manager
Map<StreamID, LocalClientSession> sessions = sessionsByManager.get(connectionManagerDomain);
if (sessions == null) {
synchronized (connectionManagerDomain.intern()) {
sessions = sessionsByManager.get(connectionManagerDomain);
if (sessions == null) {
sessions = new ConcurrentHashMap<>();
sessionsByManager.put(connectionManagerDomain, sessions);
}
}
}
sessions.put(streamID, session);
return true;
}
return false;
}
示例12: closeClientSession
import org.jivesoftware.openfire.session.LocalClientSession; //导入依赖的package包/类
/**
* Closes an existing client session that was established through a connection manager.
*
* @param connectionManagerDomain the connection manager that is handling the connection
* of the session.
* @param streamID the stream ID created by the connection manager for the session.
*/
public void closeClientSession(String connectionManagerDomain, StreamID streamID) {
Map<StreamID, LocalClientSession> sessions = sessionsByManager.get(connectionManagerDomain);
if (sessions != null) {
Session session = sessions.remove(streamID);
if (session != null) {
// Close the session
session.close();
}
}
}
示例13: multiplexerAvailable
import org.jivesoftware.openfire.session.LocalClientSession; //导入依赖的package包/类
/**
* A connection manager has become available. Clients can now connect to the server through
* the connection manager.
*
* @param connectionManagerName the connection manager that has become available.
*/
public void multiplexerAvailable(String connectionManagerName) {
// Add a new entry in the list of available managers. Here is where we are going to store
// which clients were connected through which connection manager
Map<StreamID, LocalClientSession> sessions = sessionsByManager.get(connectionManagerName);
if (sessions == null) {
synchronized (connectionManagerName.intern()) {
sessions = sessionsByManager.get(connectionManagerName);
if (sessions == null) {
sessions = new ConcurrentHashMap<>();
sessionsByManager.put(connectionManagerName, sessions);
}
}
}
}
示例14: multiplexerUnavailable
import org.jivesoftware.openfire.session.LocalClientSession; //导入依赖的package包/类
/**
* A connection manager has gone unavailable. Close client sessions that were established
* to the specified connection manager.
*
* @param connectionManagerName the connection manager that is no longer available.
*/
public void multiplexerUnavailable(String connectionManagerName) {
// Remove the connection manager and the hosted sessions
Map<StreamID, LocalClientSession> sessions = sessionsByManager.remove(connectionManagerName);
if (sessions != null) {
for (StreamID streamID : sessions.keySet()) {
// Remove inverse track of connection manager hosting streamIDs
streamIDs.remove(streamID);
// Close the session
sessions.get(streamID).close();
}
}
}
示例15: getNumConnectedClients
import org.jivesoftware.openfire.session.LocalClientSession; //导入依赖的package包/类
/**
* Returns the number of connected clients to a specific connection manager.
*
* @param managerName the name of the connection manager.
* @return the number of connected clients to a specific connection manager.
*/
public int getNumConnectedClients(String managerName) {
Map<StreamID, LocalClientSession> clients = sessionsByManager.get(managerName);
if (clients == null) {
return 0;
}
else {
return clients.size();
}
}