use of org.jivesoftware.openfire.group.GroupManager in project Openfire by igniterealtime.
the class RequestQueue method getGroupObjects.
private Collection<Group> getGroupObjects() {
final GroupManager groupManager = GroupManager.getInstance();
Set<Group> objects = new HashSet<Group>(groups.size());
for (String group : groups) {
try {
objects.add(groupManager.getGroup(group));
} catch (GroupNotFoundException e) {
Log.error("Error retrieving group: " + group, e);
}
}
return objects;
}
use of org.jivesoftware.openfire.group.GroupManager in project Openfire by igniterealtime.
the class RosterAccess method canSubscribe.
@Override
public boolean canSubscribe(Node node, JID owner, JID subscriber) {
// Let node owners and sysadmins always subscribe to the node
if (node.isAdmin(owner)) {
return true;
}
for (JID nodeOwner : node.getOwners()) {
if (nodeOwner.equals(owner)) {
return true;
}
}
// Check that the subscriber is a local user
XMPPServer server = XMPPServer.getInstance();
if (server.isLocal(owner)) {
GroupManager gMgr = GroupManager.getInstance();
Collection<String> nodeGroups = node.getRosterGroupsAllowed();
for (String groupName : nodeGroups) {
try {
Group group = gMgr.getGroup(groupName);
// access allowed if the node group is visible to the subscriber
if (server.getRosterManager().isGroupVisible(group, owner)) {
return true;
}
} catch (GroupNotFoundException gnfe) {
// ignore
}
}
} else {
// Subscriber is a remote user. This should never happen.
Log.warn("Node with access model Roster has a remote user as subscriber: {}", node.getUniqueIdentifier());
}
return false;
}
use of org.jivesoftware.openfire.group.GroupManager in project Openfire by igniterealtime.
the class BookmarkInterceptor method isBookmarkForJID.
/**
* True if the specified bookmark should be appended to the users list of
* bookmarks.
*
* @param jid the jid of the user.
* @param bookmark the bookmark.
* @return true if bookmark should be appended.
*/
private static boolean isBookmarkForJID(JID jid, Bookmark bookmark) {
String username = jid.getNode();
if (bookmark.getUsers().contains(username)) {
return true;
}
Collection<String> groups = bookmark.getGroups();
if (groups != null && !groups.isEmpty()) {
GroupManager groupManager = GroupManager.getInstance();
for (String groupName : groups) {
try {
Group group = groupManager.getGroup(groupName);
if (group.isUser(jid.getNode())) {
return true;
}
} catch (GroupNotFoundException e) {
Log.debug(e.getMessage(), e);
}
}
}
return false;
}
use of org.jivesoftware.openfire.group.GroupManager in project Openfire by igniterealtime.
the class SearchGroupServlet method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String param = req.getParameter("search");
Element root = new DefaultElement("result");
if (param != null && param.length() > 0) {
GroupManager manager = GroupManager.getInstance();
Collection<Group> groups = manager.getGroups();
for (Group gr : groups) {
if (gr.getName().startsWith(param)) {
root.addElement("item").addText(gr.getName());
}
}
}
resp.getOutputStream().write(root.asXML().getBytes());
resp.getOutputStream().close();
}
use of org.jivesoftware.openfire.group.GroupManager 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;
}
Aggregations