Search in sources :

Example 21 with ClientSession

use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.

the class JustMarriedPlugin method deleteUser.

private static void deleteUser(User oldUser) {
    UserManager.getInstance().deleteUser(oldUser);
    final StreamError error = new StreamError(StreamError.Condition.not_authorized);
    for (ClientSession sess : SessionManager.getInstance().getSessions(oldUser.getUsername())) {
        sess.deliverRawText(error.toXML());
        sess.close();
    }
}
Also used : StreamError(org.xmpp.packet.StreamError) ClientSession(org.jivesoftware.openfire.session.ClientSession)

Example 22 with ClientSession

use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.

the class SessionController method removeUserSessions.

/**
	 * Removes the user sessions.
	 *
	 * @param username the username
	 * @throws ServiceException the service exception
	 */
public void removeUserSessions(String username) throws ServiceException {
    final StreamError error = new StreamError(StreamError.Condition.not_authorized);
    for (ClientSession session : SessionManager.getInstance().getSessions(username)) {
        session.deliverRawText(error.toXML());
        session.close();
    }
}
Also used : StreamError(org.xmpp.packet.StreamError) LocalClientSession(org.jivesoftware.openfire.session.LocalClientSession) ClientSession(org.jivesoftware.openfire.session.ClientSession)

Example 23 with ClientSession

use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.

the class SessionController method getAllSessions.

/**
	 * Gets the all sessions.
	 *
	 * @return the all sessions
	 * @throws ServiceException the service exception
	 */
public SessionEntities getAllSessions() throws ServiceException {
    Collection<ClientSession> clientSessions = SessionManager.getInstance().getSessions();
    SessionEntities sessionEntities = convertToSessionEntities(clientSessions);
    return sessionEntities;
}
Also used : LocalClientSession(org.jivesoftware.openfire.session.LocalClientSession) ClientSession(org.jivesoftware.openfire.session.ClientSession) SessionEntities(org.jivesoftware.openfire.plugin.rest.entity.SessionEntities)

Example 24 with ClientSession

use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.

the class SessionController method convertToSessionEntities.

/**
	 * Convert to session entities.
	 *
	 * @param clientSessions the client sessions
	 * @return the session entities
	 * @throws ServiceException the service exception
	 */
private SessionEntities convertToSessionEntities(Collection<ClientSession> clientSessions) throws ServiceException {
    List<SessionEntity> sessions = new ArrayList<SessionEntity>();
    SessionEntities sessionEntities = new SessionEntities(sessions);
    for (ClientSession clientSession : clientSessions) {
        SessionEntity session = new SessionEntity();
        session.setSessionId(clientSession.getAddress().toString());
        if (!clientSession.isAnonymousUser()) {
            try {
                session.setUsername(clientSession.getUsername());
            } catch (UserNotFoundException e) {
                throw new ServiceException("Could not get user", "", ExceptionType.USER_NOT_FOUND_EXCEPTION, Response.Status.NOT_FOUND, e);
            }
        } else {
            session.setUsername("Anonymous");
        }
        session.setRessource(clientSession.getAddress().getResource());
        if (clientSession instanceof LocalClientSession) {
            session.setNode("Local");
        } else {
            session.setNode("Remote");
        }
        String status = "";
        if (clientSession.getStatus() == Session.STATUS_CLOSED) {
            status = "Closed";
        } else if (clientSession.getStatus() == Session.STATUS_CONNECTED) {
            status = "Connected";
        } else if (clientSession.getStatus() == Session.STATUS_AUTHENTICATED) {
            status = "Authenticated";
        } else {
            status = "Unkown";
        }
        session.setSessionStatus(status);
        if (clientSession.getPresence() != null) {
            session.setPresenceMessage(clientSession.getPresence().getStatus());
            Presence.Show show = clientSession.getPresence().getShow();
            if (show == Presence.Show.away) {
                session.setPresenceStatus("Away");
            } else if (show == Presence.Show.chat) {
                session.setPresenceStatus("Available to Chat");
            } else if (show == Presence.Show.dnd) {
                session.setPresenceStatus("Do Not Disturb");
            } else if (show == Presence.Show.xa) {
                session.setPresenceStatus("Extended Away");
            } else if (show == null) {
                session.setPresenceStatus("Online");
            } else {
                session.setPresenceStatus("Unknown/Not Recognized");
            }
            session.setPriority(clientSession.getPresence().getPriority());
        }
        try {
            session.setHostAddress(clientSession.getHostAddress());
            session.setHostName(clientSession.getHostName());
        } catch (UnknownHostException e) {
            LOG.error("UnknownHostException", e);
        }
        session.setCreationDate(clientSession.getCreationDate());
        session.setLastActionDate(clientSession.getLastActiveDate());
        session.setSecure(clientSession.isSecure());
        sessions.add(session);
    }
    return sessionEntities;
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) LocalClientSession(org.jivesoftware.openfire.session.LocalClientSession) ServiceException(org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException) UnknownHostException(java.net.UnknownHostException) SessionEntity(org.jivesoftware.openfire.plugin.rest.entity.SessionEntity) LocalClientSession(org.jivesoftware.openfire.session.LocalClientSession) ClientSession(org.jivesoftware.openfire.session.ClientSession) ArrayList(java.util.ArrayList) Presence(org.xmpp.packet.Presence) SessionEntities(org.jivesoftware.openfire.plugin.rest.entity.SessionEntities)

Example 25 with ClientSession

use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.

the class JustMarriedController method deleteUser.

/**
	 * Delete user.
	 *
	 * @param oldUser
	 *            the old user
	 */
private static void deleteUser(User oldUser) {
    UserManager.getInstance().deleteUser(oldUser);
    LockOutManager.getInstance().enableAccount(oldUser.getUsername());
    final StreamError error = new StreamError(StreamError.Condition.not_authorized);
    for (ClientSession sess : SessionManager.getInstance().getSessions(oldUser.getUsername())) {
        sess.deliverRawText(error.toXML());
        sess.close();
    }
}
Also used : StreamError(org.xmpp.packet.StreamError) ClientSession(org.jivesoftware.openfire.session.ClientSession)

Aggregations

ClientSession (org.jivesoftware.openfire.session.ClientSession)49 JID (org.xmpp.packet.JID)15 Element (org.dom4j.Element)14 LocalClientSession (org.jivesoftware.openfire.session.LocalClientSession)14 IQ (org.xmpp.packet.IQ)12 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)8 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)7 PrivacyList (org.jivesoftware.openfire.privacy.PrivacyList)7 StreamError (org.xmpp.packet.StreamError)7 DataForm (org.xmpp.forms.DataForm)6 FormField (org.xmpp.forms.FormField)6 Message (org.xmpp.packet.Message)6 Presence (org.xmpp.packet.Presence)6 PacketRejectedException (org.jivesoftware.openfire.interceptor.PacketRejectedException)5 StringprepException (gnu.inet.encoding.StringprepException)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)3 SessionEntities (org.jivesoftware.openfire.plugin.rest.entity.SessionEntities)3 SQLException (java.sql.SQLException)2