Search in sources :

Example 46 with User

use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.

the class UserServicePluginNG method addProperties.

/**
	 * Adds the properties.
	 *
	 * @param userEntity
	 *            the user entity
	 * @throws ServiceException
	 *             the service exception
	 */
private void addProperties(UserEntity userEntity) throws ServiceException {
    User user = getAndCheckUser(userEntity.getUsername());
    user.getProperties().clear();
    if (userEntity.getProperties() != null) {
        for (UserProperty property : userEntity.getProperties()) {
            user.getProperties().put(property.getKey(), property.getValue());
        }
    }
}
Also used : User(org.jivesoftware.openfire.user.User) UserProperty(org.jivesoftware.openfire.entity.UserProperty)

Example 47 with User

use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.

the class UserServicePluginNG method updateUser.

/**
	 * Update user.
	 *
	 * @param username
	 *            the username
	 * @param userEntity
	 *            the user entity
	 * @throws ServiceException
	 *             the service exception
	 */
public void updateUser(String username, UserEntity userEntity) throws ServiceException {
    if (userEntity != null && !username.isEmpty()) {
        User user = getAndCheckUser(username);
        if (userEntity.getPassword() != null) {
            user.setPassword(userEntity.getPassword());
        }
        if (userEntity.getName() != null) {
            user.setName(userEntity.getName());
        }
        if (userEntity.getEmail() != null) {
            user.setEmail(userEntity.getEmail());
        }
        addProperties(userEntity);
    }
}
Also used : User(org.jivesoftware.openfire.user.User)

Example 48 with User

use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.

the class WebManager method setPageProperty.

public void setPageProperty(String pageName, String property, int newValue) {
    String toStore = pageName + "=" + newValue;
    User user = getUser();
    if (user != null) {
        String values = user.getProperties().get(property);
        if (values != null) {
            if (values.contains(toStore)) {
                // The new value for the page was already stored so do nothing
                return;
            } else {
                if (values.contains(pageName)) {
                    // Replace an old value for the page with the new value
                    int oldValue = getPageProperty(pageName, property, -1);
                    String toRemove = pageName + "=" + oldValue;
                    user.getProperties().put(property, values.replace(toRemove, toStore));
                } else {
                    // Append the new page-value
                    user.getProperties().put(property, values + "," + toStore);
                }
            }
        } else {
            // Store the new page-value as a new user property
            user.getProperties().put(property, toStore);
        }
    }
}
Also used : User(org.jivesoftware.openfire.user.User)

Example 49 with User

use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.

the class CallbackOnOffline method interceptPacket.

public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) throws PacketRejectedException {
    if (processed && incoming && packet instanceof Message && packet.getTo() != null) {
        Message msg = (Message) packet;
        if (msg.getType() != Message.Type.chat) {
            return;
        }
        try {
            JID to = packet.getTo();
            User userTo = userManager.getUser(to.getNode());
            boolean available = presenceManager.isAvailable(userTo);
            if (debug) {
                Log.debug("intercepted message from {} to {}, recipient is available {}", packet.getFrom().toBareJID(), to.toBareJID(), available);
            }
            if (!available) {
                JID from = packet.getFrom();
                WebTarget target = client.target(url).queryParam("token", token).queryParam("from", from.toBareJID()).queryParam("to", to.toBareJID());
                if (debug) {
                    Log.debug("sending request to url='{}'", target);
                }
                Future<Response> responseFuture = target.request().async().get();
                if (debug) {
                    try {
                        Response response = responseFuture.get();
                        Log.debug("got response status url='{}' status='{}'", target, response.getStatus());
                    } catch (Exception e) {
                        Log.debug("can't get response status url='{}'", target, e);
                    }
                }
            }
        } catch (UserNotFoundException e) {
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) User(org.jivesoftware.openfire.user.User) Message(org.xmpp.packet.Message) JID(org.xmpp.packet.JID) WebTarget(javax.ws.rs.client.WebTarget) PacketRejectedException(org.jivesoftware.openfire.interceptor.PacketRejectedException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 50 with User

use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.

the class emailOnAway method interceptPacket.

public void interceptPacket(Packet packet, Session session, boolean read, boolean processed) throws PacketRejectedException {
    String emailTo = null;
    String emailFrom = null;
    if ((!processed) && (!read) && (packet instanceof Message) && (packet.getTo() != null)) {
        Message msg = (Message) packet;
        if (msg.getType() == Message.Type.chat) {
            try {
                User userTo = userManager.getUser(packet.getTo().getNode());
                if (presenceManager.getPresence(userTo).toString().toLowerCase().indexOf("away") != -1) {
                    // Status isn't away
                    if (msg.getBody() != null) {
                        // Build email/sms
                        // The to email address
                        emailTo = vcardManager.getVCardProperty(userTo.getUsername(), "EMAIL");
                        if (emailTo == null || emailTo.length() == 0) {
                            emailTo = vcardManager.getVCardProperty(userTo.getUsername(), "EMAIL:USERID");
                            if (emailTo == null || emailTo.length() == 0) {
                                emailTo = userTo.getEmail();
                                if (emailTo == null || emailTo.length() == 0) {
                                    emailTo = packet.getTo().getNode() + "@" + packet.getTo().getDomain();
                                }
                            }
                        }
                        // The From email address
                        User userFrom = userManager.getUser(packet.getFrom().getNode());
                        emailFrom = vcardManager.getVCardProperty(userFrom.getUsername(), "EMAIL");
                        if (emailFrom == null || emailFrom.length() == 0) {
                            emailFrom = vcardManager.getVCardProperty(userFrom.getUsername(), "EMAIL:USERID");
                            if (emailFrom == null || emailFrom.length() == 0) {
                                emailFrom = userFrom.getEmail();
                                if (emailFrom == null || emailFrom.length() == 0) {
                                    emailFrom = packet.getFrom().getNode() + "@" + packet.getFrom().getDomain();
                                }
                            }
                        }
                        //			    System.err.println(vcardManager.getVCardProperty(userTo.getUsername(), "EMAIL:USERID"));
                        // Send email/sms
                        // if this is an sms... modify the recipient address
                        emailService.sendMessage(userTo.getName(), emailTo, userFrom.getName(), emailFrom, "IM", msg.getBody(), null);
                        // Notify the sender that this went to email/sms
                        messageRouter.route(createServerMessage(packet.getFrom().getNode() + "@" + packet.getFrom().getDomain(), packet.getTo().getNode() + "@" + packet.getTo().getDomain(), emailTo));
                    }
                }
            } catch (UserNotFoundException e) {
            }
        }
    }
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) User(org.jivesoftware.openfire.user.User) Message(org.xmpp.packet.Message)

Aggregations

User (org.jivesoftware.openfire.user.User)58 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)26 Element (org.dom4j.Element)17 JID (org.xmpp.packet.JID)17 UserManager (org.jivesoftware.openfire.user.UserManager)10 ArrayList (java.util.ArrayList)9 Group (org.jivesoftware.openfire.group.Group)9 IQ (org.xmpp.packet.IQ)7 List (java.util.List)6 UserAlreadyExistsException (org.jivesoftware.openfire.user.UserAlreadyExistsException)6 RosterItem (org.jivesoftware.openfire.roster.RosterItem)5 Date (java.util.Date)4 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)4 Message (org.xmpp.packet.Message)4 Presence (org.xmpp.packet.Presence)4 HashSet (java.util.HashSet)3 StringTokenizer (java.util.StringTokenizer)3 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileInputStream (java.io.FileInputStream)2