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());
}
}
}
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);
}
}
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);
}
}
}
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) {
}
}
}
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) {
}
}
}
}
Aggregations