Search in sources :

Example 1 with User

use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.

the class Xep227Exporter method exportUsers.

/* (non-Javadoc)
   * @see org.jivesoftware.openfire.plugin.Exporter#exportUsers(org.jivesoftware.openfire.user.UserManager)
   */
@Override
public Document exportUsers() {
    Log.debug("exportUsers");
    Document document = DocumentHelper.createDocument();
    Element root = document.addElement(SERVER_DATA_ELEMENT_NAME, URN_XMPP_PIE_0_NS);
    Element host = root.addElement(HOST_ELEMENT_NAME);
    host.addAttribute(JID_NAME, serverName);
    Collection<User> users = userManager.getUsers();
    for (User user : users) {
        String userName = user.getUsername();
        Element userElement = host.addElement(USER_ELEMENT_NAME);
        exportUser(userElement, user);
        exportOfflineMessages(serverName, userElement, userName);
        exportRoster(userElement, user);
        exportVCard(userElement, userName);
        exportPrivateStorage(userName, userElement);
    }
    return document;
}
Also used : User(org.jivesoftware.openfire.user.User) Element(org.dom4j.Element) Document(org.dom4j.Document)

Example 2 with User

use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.

the class TestUserProvider method createUser.

/* (non-Javadoc)
   * @see org.jivesoftware.openfire.user.UserProvider#createUser(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
   */
@Override
public User createUser(String username, String password, String name, String email) throws UserAlreadyExistsException {
    logger.finest("createUser");
    Date creationDate = new Date();
    Date modificationDate = new Date();
    User u = new TestUser(username, name, email, creationDate, modificationDate);
    userList.put(username, u);
    return u;
}
Also used : User(org.jivesoftware.openfire.user.User) Date(java.util.Date)

Example 3 with User

use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.

the class Xep227ExporterTest method testImportUser.

/**
   * @throws IOException 
   * @throws DocumentException 
   * 
   */
@Test
public void testImportUser() throws DocumentException, IOException {
    logger.finest("testImportUser");
    InExporter testobject = new Xep227Exporter("serverName", offlineMessagesStore, vCardManager, privateStorage, userManager, rosterItemProvider);
    InputStream stream = this.getClass().getResourceAsStream("test-xepp227-import.xml");
    String previousDomain = null;
    boolean isUserProviderReadOnly = false;
    List<String> res = testobject.importUsers(stream, previousDomain, isUserProviderReadOnly);
    assertNotNull(res);
    assertEquals(0, res.size());
    stream.close();
    Collection<User> users = userManager.getUsers();
    assertEquals(4, users.size());
}
Also used : User(org.jivesoftware.openfire.user.User) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 4 with User

use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.

the class UserServicePlugin method updateUser.

public void updateUser(String username, String password, String name, String email, String groupNames) throws UserNotFoundException, GroupAlreadyExistsException {
    User user = getUser(username);
    if (password != null)
        user.setPassword(password);
    if (name != null)
        user.setName(name);
    if (email != null)
        user.setEmail(email);
    if (groupNames != null) {
        Collection<Group> newGroups = new ArrayList<Group>();
        StringTokenizer tkn = new StringTokenizer(groupNames, ",");
        while (tkn.hasMoreTokens()) {
            String groupName = tkn.nextToken();
            Group group = null;
            try {
                group = GroupManager.getInstance().getGroup(groupName);
            } catch (GroupNotFoundException e) {
                // Create this group ;
                group = GroupManager.getInstance().createGroup(groupName);
                group.getProperties().put("sharedRoster.showInRoster", "onlyGroup");
                group.getProperties().put("sharedRoster.displayName", groupName);
                group.getProperties().put("sharedRoster.groupList", "");
            }
            newGroups.add(group);
        }
        Collection<Group> existingGroups = GroupManager.getInstance().getGroups(user);
        // Get the list of groups to add to the user
        Collection<Group> groupsToAdd = new ArrayList<Group>(newGroups);
        groupsToAdd.removeAll(existingGroups);
        // Get the list of groups to remove from the user
        Collection<Group> groupsToDelete = new ArrayList<Group>(existingGroups);
        groupsToDelete.removeAll(newGroups);
        // Add the user to the new groups
        for (Group group : groupsToAdd) {
            group.getMembers().add(server.createJID(username, null));
        }
        // Remove the user from the old groups
        for (Group group : groupsToDelete) {
            group.getMembers().remove(server.createJID(username, null));
        }
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group) StringTokenizer(java.util.StringTokenizer) User(org.jivesoftware.openfire.user.User) ArrayList(java.util.ArrayList) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 5 with User

use of org.jivesoftware.openfire.user.User in project Openfire by igniterealtime.

the class UserServicePluginNG method getUserGroups.

/**
	 * Gets the user groups.
	 *
	 * @param username
	 *            the username
	 * @return the user groups
	 * @throws ServiceException
	 *             the service exception
	 */
public List<String> getUserGroups(String username) throws ServiceException {
    User user = getAndCheckUser(username);
    Collection<Group> groups = GroupManager.getInstance().getGroups(user);
    List<String> groupNames = new ArrayList<String>();
    for (Group group : groups) {
        groupNames.add(group.getName());
    }
    return groupNames;
}
Also used : Group(org.jivesoftware.openfire.group.Group) User(org.jivesoftware.openfire.user.User) ArrayList(java.util.ArrayList)

Aggregations

User (org.jivesoftware.openfire.user.User)58 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)26 Element (org.dom4j.Element)17 JID (org.xmpp.packet.JID)17 UserManager (org.jivesoftware.openfire.user.UserManager)10 ArrayList (java.util.ArrayList)9 Group (org.jivesoftware.openfire.group.Group)9 IQ (org.xmpp.packet.IQ)7 List (java.util.List)6 UserAlreadyExistsException (org.jivesoftware.openfire.user.UserAlreadyExistsException)6 RosterItem (org.jivesoftware.openfire.roster.RosterItem)5 Date (java.util.Date)4 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)4 Message (org.xmpp.packet.Message)4 Presence (org.xmpp.packet.Presence)4 HashSet (java.util.HashSet)3 StringTokenizer (java.util.StringTokenizer)3 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 FileInputStream (java.io.FileInputStream)2