use of org.xmpp.packet.JID in project Openfire by igniterealtime.
the class CrowdAdminProvider method getAdmins.
@Override
public List<JID> getAdmins() {
List<JID> results = new ArrayList<>();
GroupProvider provider = GroupManager.getInstance().getProvider();
String groups = JiveGlobals.getProperty(JIVE_AUTHORIZED_GROUPS);
groups = (groups == null || groups.trim().length() == 0) ? "" : groups;
// make sure the property is created
JiveGlobals.setProperty(JIVE_AUTHORIZED_GROUPS, groups);
StringTokenizer tokenizer = new StringTokenizer(groups, ",");
while (tokenizer.hasMoreTokens()) {
String groupName = tokenizer.nextToken().trim().toLowerCase();
if (groupName != null && groupName.length() > 0) {
try {
LOG.info("Adding admin users from group: " + groupName);
Group group = provider.getGroup(groupName);
if (group != null) {
results.addAll(group.getMembers());
}
} catch (GroupNotFoundException gnfe) {
LOG.error("Error when trying to load the members of group:" + String.valueOf(groupName), gnfe);
}
}
}
if (results.isEmpty()) {
// Add default admin account when none was specified
results.add(new JID("admin", XMPPServer.getInstance().getServerInfo().getXMPPDomain(), null, true));
}
if (LOG.isDebugEnabled()) {
LOG.debug("admin users: " + results.toString());
}
return results;
}
use of org.xmpp.packet.JID in project Openfire by igniterealtime.
the class CrowdGroupProvider method getGroup.
@Override
public Group getGroup(String name) throws GroupNotFoundException {
try {
Cache<String, org.jivesoftware.openfire.crowd.jaxb.Group> groupCache = CacheFactory.createLocalCache(GROUP_CACHE_NAME);
org.jivesoftware.openfire.crowd.jaxb.Group group = groupCache.get(name);
if (group == null) {
group = manager.getGroup(name);
groupCache.put(name, group);
}
Collection<JID> members = getGroupMembers(name);
Collection<JID> admins = Collections.emptyList();
return new Group(name, group.description, members, admins);
} catch (RemoteException re) {
LOG.error("Failure to load group:" + String.valueOf(name), re);
throw new GroupNotFoundException(re);
}
}
use of org.xmpp.packet.JID in project Openfire by igniterealtime.
the class AuthenticateUser method execute.
@Override
public void execute(SessionData data, Element command) {
Element note = command.addElement("note");
JID account;
try {
account = new JID(data.getData().get("accountjid").get(0));
} catch (NullPointerException ne) {
note.addAttribute("type", "error");
note.setText("JID required parameter.");
return;
}
if (!XMPPServer.getInstance().isLocal(account)) {
note.addAttribute("type", "error");
note.setText("Cannot authenticate remote user.");
return;
}
String password = data.getData().get("password").get(0);
// Get requested user
User user;
try {
user = UserManager.getInstance().getUser(account.getNode());
} catch (UserNotFoundException e) {
// User not found
note.addAttribute("type", "error");
note.setText("User does not exists.");
return;
}
try {
AuthFactory.authenticate(user.getUsername(), password);
} catch (UnauthorizedException | ConnectionException | InternalUnauthenticatedException e) {
// Auth failed
note.addAttribute("type", "error");
note.setText("Authentication failed.");
return;
}
// Answer that the operation was successful
note.addAttribute("type", "info");
note.setText("Operation finished successfully.");
}
use of org.xmpp.packet.JID in project Openfire by igniterealtime.
the class PacketsNotification method execute.
@Override
public void execute(SessionData data, Element command) {
boolean presenceEnabled = false;
boolean messageEnabled = false;
boolean iqEnabled = false;
for (String packet_type : data.getData().get("packet_type")) {
if ("presence".equals(packet_type)) {
presenceEnabled = true;
} else if ("iq".equals(packet_type)) {
iqEnabled = true;
} else if ("message".equals(packet_type)) {
messageEnabled = true;
}
}
boolean incoming = "incoming".equals(data.getData().get("direction").get(0));
boolean processed = "true".equals(data.getData().get("processed").get(0));
JID componentJID = data.getOwner();
// Create or update subscription of the component to receive packet notifications
PacketCopier.getInstance().addSubscriber(componentJID, iqEnabled, messageEnabled, presenceEnabled, incoming, processed);
// Inform that everything went fine
Element note = command.addElement("note");
note.addAttribute("type", "info");
note.setText("Operation finished successfully");
}
use of org.xmpp.packet.JID in project Openfire by igniterealtime.
the class AddGroup method execute.
@Override
public void execute(SessionData data, Element command) {
Element note = command.addElement("note");
// Check if groups cannot be modified (backend is read-only)
if (GroupManager.getInstance().isReadOnly()) {
note.addAttribute("type", "error");
note.setText("Groups are read only");
return;
}
// Get requested group
Group group;
try {
group = GroupManager.getInstance().createGroup(data.getData().get("group").get(0));
} catch (GroupAlreadyExistsException e) {
// Group not found
note.addAttribute("type", "error");
note.setText("Group already exists");
return;
}
List<String> desc = data.getData().get("desc");
if (desc != null && !desc.isEmpty()) {
group.setDescription(desc.get(0));
}
List<String> members = data.getData().get("members");
boolean withErrors = false;
if (members != null) {
Collection<JID> users = group.getMembers();
for (String user : members) {
try {
users.add(new JID(user));
} catch (Exception e) {
Log.warn("User not added to group", e);
withErrors = true;
}
}
}
String showInRoster = data.getData().get("showInRoster").get(0);
if ("nobody".equals(showInRoster)) {
// New group is not a shared group
group.getProperties().put("sharedRoster.showInRoster", "nobody");
group.getProperties().put("sharedRoster.displayName", " ");
group.getProperties().put("sharedRoster.groupList", " ");
} else {
// New group is configured as a shared group
if ("spefgroups".equals(showInRoster)) {
// Show shared group to other groups
showInRoster = "onlyGroup";
}
List<String> displayName = data.getData().get("displayName");
List<String> groupList = data.getData().get("groupList");
if (displayName != null) {
group.getProperties().put("sharedRoster.showInRoster", showInRoster);
group.getProperties().put("sharedRoster.displayName", displayName.get(0));
if (groupList != null) {
StringBuilder buf = new StringBuilder();
String sep = "";
for (String groupName : groupList) {
buf.append(sep).append(groupName);
sep = ",";
}
group.getProperties().put("sharedRoster.groupList", buf.toString());
}
} else {
withErrors = true;
}
}
note.addAttribute("type", "info");
note.setText("Operation finished" + (withErrors ? " with errors" : " successfully"));
}
Aggregations