use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.
the class SimpleSession method sendNotify.
public void sendNotify(Dialog dialog) throws ParseException, SipException, InvalidArgumentException {
Request notifyRequest = prepareNotifyRequest(dialog);
try {
User me = XMPPServer.getInstance().getUserManager().getUser(getJID().getNode());
Presence myPresence = XMPPServer.getInstance().getPresenceManager().getPresence(me);
String presenceContent;
SimplePresence simplePresence = new SimplePresence();
simplePresence.setEntity("pres:" + registration.getUsername() + "@" + sipHost);
simplePresence.setDmNote(myPresence.getStatus());
if (myPresence.getStatus() != null && myPresence.getStatus().equalsIgnoreCase("Offline"))
simplePresence.setTupleStatus(SimplePresence.TupleStatus.CLOSED);
else {
simplePresence.setTupleStatus(SimplePresence.TupleStatus.OPEN);
if (myPresence.getShow() != null) {
switch(myPresence.getShow()) {
case away:
simplePresence.setRpid(SimplePresence.Rpid.AWAY);
break;
case dnd:
simplePresence.setRpid(SimplePresence.Rpid.BUSY);
break;
case xa:
simplePresence.setRpid(SimplePresence.Rpid.AWAY);
break;
default:
break;
}
}
}
presenceContent = simplePresence.toXML();
ContentTypeHeader contentTypeHeader = headerFactory.createContentTypeHeader("application", "pidf+xml");
notifyRequest.setContent(presenceContent, contentTypeHeader);
} catch (Exception e) {
Log.debug("Unable to include presence details in the packet.", e);
}
sendRequest(notifyRequest, ListeningPoint.UDP, dialog);
}
use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.
the class ConfigManager method savePermissions.
/**
* Saves permissions settings from web interface.
*
* We validate all of the groups before actually adding them.
*
* @param transportName Name of the transport to have it's options saved (type of transport)
* @param overallSetting The general "all(1), some(2), or none(3)" setting for the permissions.
* @param users List of specific users that have access.
* @param groups List of specific groups that have access.
* @param strict Strict permissions associted with setting.
* @return List of usernames and groups (@ preceded) that were rejected.
*/
public List<String> savePermissions(String transportName, Integer overallSetting, List<String> users, List<String> groups, Boolean strict) {
JiveGlobals.setProperty("plugin.gateway." + transportName + ".registration", overallSetting.toString());
JiveGlobals.setProperty("plugin.gateway." + transportName + ".registrationstrict", strict ? "true" : "false");
PermissionManager permissionManager = new PermissionManager(TransportType.valueOf(transportName));
List<String> errorList = new ArrayList<String>();
ArrayList<User> userList = new ArrayList<User>();
UserManager userManager = UserManager.getInstance();
for (String username : users) {
if (username.matches("\\s*")) {
continue;
}
try {
if (username.contains("@")) {
JID jid = new JID(username);
if (!jid.getDomain().equals(XMPPServer.getInstance().getServerInfo().getXMPPDomain())) {
throw new UserNotFoundException();
}
username = username.substring(0, username.indexOf("@"));
}
User user = userManager.getUser(username);
if (user == null || user.getUsername() == null) {
throw new UserNotFoundException();
}
userList.add(user);
} catch (UserNotFoundException e) {
Log.warn("User " + username + " not found while adding access rules.");
errorList.add(username);
}
}
permissionManager.storeUserList(userList);
ArrayList<Group> groupList = new ArrayList<Group>();
GroupManager groupManager = GroupManager.getInstance();
for (String grpname : groups) {
if (grpname.matches("\\s*")) {
continue;
}
try {
Group group = groupManager.getGroup(grpname);
if (group == null || group.getName() == null) {
throw new GroupNotFoundException();
}
groupList.add(group);
} catch (GroupNotFoundException e) {
Log.warn("Group " + grpname + " not found while adding access rules.");
errorList.add("@" + grpname);
}
}
permissionManager.storeGroupList(groupList);
return errorList;
}
use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.
the class PresencePlugin method getPresence.
/**
* Returns the presence of the requested user or <tt>null</tt> if the user is offline. If
* presences are not public then the user presence will be returned if and only if the sender
* of the request is subscribed to the user presence.
*
* @param sender the bare JID of the user making the request.
* @param jid the bare JID of the entity whose presence is being probed.
* @return the presence of the requested user.
* @throws UserNotFoundException If presences are not public and the sender is null or the
* sender cannot probe the presence of the requested user. Or if the requested user
* does not exist in the local server.
*/
public Presence getPresence(String sender, String jid) throws UserNotFoundException {
if (jid == null) {
throw new UserNotFoundException("Target JID not found in request");
}
JID targetJID = new JID(jid);
// Check that the sender is not requesting information of a remote server entity
if (targetJID.getDomain() == null || XMPPServer.getInstance().isRemote(targetJID)) {
throw new UserNotFoundException("Domain does not matches local server domain");
}
if (!hostname.equals(targetJID.getDomain())) {
// Sender is requesting information about component presence, so we send a
// presence probe to the component.
presenceManager.probePresence(componentJID, targetJID);
// Wait 30 seconds until we get the probe presence result
int count = 0;
Presence presence = probedPresence.get(jid);
while (presence == null) {
if (count > 300) {
// After 30 seconds, timeout
throw new UserNotFoundException("Request for component presence has timed-out.");
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// don't care!
}
presence = probedPresence.get(jid);
count++;
}
// Clean-up probe presence result
probedPresence.remove(jid);
// Return component presence
return presence;
}
if (targetJID.getNode() == null || !UserManager.getInstance().isRegisteredUser(targetJID.getNode())) {
// Sender is requesting presence information of an anonymous user
throw new UserNotFoundException("Username is null");
}
if (!isPresencePublic()) {
if (sender == null) {
throw new UserNotFoundException("Sender is null");
} else {
// If sender is same as target, then we can see ourselves
JID senderJID = new JID(sender);
if (!senderJID.getNode().equals(targetJID.getNode()) && !presenceManager.canProbePresence(new JID(sender), targetJID.getNode())) {
throw new UserNotFoundException("Sender is not allowed to probe this user");
}
}
}
User user = userManager.getUser(targetJID.getNode());
return presenceManager.getPresence(user);
}
use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.
the class TextPresenceProvider method sendInfo.
@Override
public void sendInfo(HttpServletRequest request, HttpServletResponse response, Presence presence) throws IOException {
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
if (presence == null) {
// Recreate the unavailable presence with the last known status
JID targetJID = new JID(request.getParameter("jid"));
presence = new Presence(Presence.Type.unavailable);
XMPPServer server = XMPPServer.getInstance();
try {
User user = server.getUserManager().getUser(targetJID.getNode());
String status = server.getPresenceManager().getLastPresenceStatus(user);
if (status != null) {
presence.setStatus(status);
} else {
presence.setStatus(JiveGlobals.getProperty("plugin.presence.unavailable.status", "Unavailable"));
}
} catch (UserNotFoundException e) {
}
presence.setFrom(targetJID);
}
out.println(presence.getStatus());
out.flush();
}
use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.
the class XMLPresenceProvider method sendInfo.
@Override
public void sendInfo(HttpServletRequest request, HttpServletResponse response, Presence presence) throws IOException {
response.setContentType("text/xml");
PrintWriter out = response.getWriter();
if (presence == null) {
// Recreate the unavailable presence with the last known status
JID targetJID = new JID(request.getParameter("jid"));
presence = new Presence(Presence.Type.unavailable);
XMPPServer server = XMPPServer.getInstance();
try {
User user = server.getUserManager().getUser(targetJID.getNode());
String status = server.getPresenceManager().getLastPresenceStatus(user);
if (status != null) {
presence.setStatus(status);
} else {
presence.setStatus(JiveGlobals.getProperty("plugin.presence.unavailable.status", "Unavailable"));
}
} catch (UserNotFoundException e) {
}
presence.setFrom(targetJID);
}
out.println(presence.toXML());
out.flush();
}
Aggregations