use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.
the class OpenfireExporter method exportUsers.
/* (non-Javadoc)
* @see org.jivesoftware.openfire.plugin.Exporter#exportUsers()
*/
@Override
public Document exportUsers() {
Log.debug("exportUsers");
Document document = DocumentHelper.createDocument();
Element root = document.addElement("Openfire");
Collection<User> users = userManager.getUsers();
for (User user : users) {
Element userElement = root.addElement("User");
String userName = user.getUsername();
userElement.addElement("Username").addText(userName);
try {
String pw = AuthFactory.getPassword(user.getUsername());
userElement.addElement("Password").addText(pw);
} catch (UserNotFoundException e) {
Log.info("User " + userName + " not found, setting their password to their username");
userElement.addElement("Password").addText(userName);
} catch (UnsupportedOperationException e) {
Log.info("Unable to retrieve " + userName + " password, setting their password to their username");
userElement.addElement("Password").addText(userName);
}
userElement.addElement("Email").addText(user.getEmail() == null ? "" : user.getEmail());
String name = user.getName();
userElement.addElement("Name").addText(name == null ? "" : name);
//creation and modified date are not used as part of the import process but are exported
//for historical purposes, should they be formatted differently?
userElement.addElement("CreationDate").addText(String.valueOf(user.getCreationDate().getTime()));
userElement.addElement("ModifiedDate").addText(String.valueOf(user.getModificationDate().getTime()));
Element rosterElement = userElement.addElement("Roster");
Collection<RosterItem> roster = user.getRoster().getRosterItems();
for (RosterItem ri : roster) {
Element itemElement = rosterElement.addElement("Item");
itemElement.addAttribute("jid", ri.getJid().toBareJID());
itemElement.addAttribute("askstatus", String.valueOf(ri.getAskStatus().getValue()));
itemElement.addAttribute("recvstatus", String.valueOf(ri.getRecvStatus().getValue()));
itemElement.addAttribute("substatus", String.valueOf(ri.getSubStatus().getValue()));
itemElement.addAttribute("name", ri.getNickname());
List<String> groups = ri.getGroups();
for (String group : groups) {
if (group != null && group.trim().length() > 0) {
itemElement.addElement("Group").addText(group);
}
}
}
}
return document;
}
use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.
the class Xep227ExporterTest method setUp.
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
URL url = this.getClass().getResource("test-openfire.xml");
File f = new File(url.getFile());
JiveGlobals.setConfigName(f.getName());
JiveGlobals.setHomeDirectory(f.getParent());
JiveGlobals.setProperty("provider.user.className", "org.jivesoftware.openfire.plugin.TestUserProvider");
offlineMessagesStore = new TestOfflineMessageStore();
vCardManager = new TestVCardManager();
privateStorage = null;
userManager = UserManager.getInstance();
rosterItemProvider = new TestRosterItemProvider();
//Empty users
List<User> l = new ArrayList<>(userManager.getUsers());
for (User user : l) {
userManager.deleteUser(user);
}
}
use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.
the class Xep227ExporterTest method testImportXInclude.
/**
* Test if XInclude is working
*
* @throws IOException
* @throws DocumentException
*
*/
@Test
public void testImportXInclude() throws DocumentException, IOException {
logger.finest("testImportIncludeUser");
InExporter testobject = new Xep227Exporter("serverName", offlineMessagesStore, vCardManager, privateStorage, userManager, rosterItemProvider);
String IMPORT_FILE_NAME = "/test-export-xinclude/xep227.xml";
URL streamurl = this.getClass().getResource(IMPORT_FILE_NAME);
assertNotNull(streamurl);
logger.fine("testImportIncludeUser:" + streamurl.getFile());
InputStream stream = new FileInputStream(streamurl.getFile());
assertTrue("Invalid input", testobject.validate(stream));
stream.close();
String previousDomain = null;
boolean isUserProviderReadOnly = false;
stream = this.getClass().getResourceAsStream(IMPORT_FILE_NAME);
List<String> res = testobject.importUsers(stream, previousDomain, isUserProviderReadOnly);
assertNotNull(res);
assertEquals(0, res.size());
stream.close();
Collection<User> users = userManager.getUsers();
assertEquals(2, users.size());
}
use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.
the class UserServicePlugin method deleteUser.
public void deleteUser(String username) throws UserNotFoundException, SharedGroupException {
User user = getUser(username);
userManager.deleteUser(user);
rosterManager.deleteRoster(server.createJID(username, null));
}
use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.
the class UserServicePlugin method getUserGroups.
/**
* Returns all group names or an empty collection for specific user
*
*/
public Collection<String> getUserGroups(String username) throws UserNotFoundException {
User user = getUser(username);
Collection<Group> groups = GroupManager.getInstance().getGroups(user);
Collection<String> groupNames = new ArrayList<String>();
for (Group group : groups) {
groupNames.add(group.getName());
}
return groupNames;
}
Aggregations