Search in sources :

Example 36 with 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());
}
Also used : User(org.jivesoftware.openfire.user.User) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) URL(java.net.URL) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 37 with User

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));
}
Also used : User(org.jivesoftware.openfire.user.User)

Example 38 with User

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;
}
Also used : Group(org.jivesoftware.openfire.group.Group) User(org.jivesoftware.openfire.user.User) ArrayList(java.util.ArrayList)

Example 39 with User

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

the class UserServicePluginNG method addProperties.

/**
	 * Adds the properties.
	 *
	 * @param userEntity
	 *            the user entity
	 * @throws ServiceException
	 *             the service exception
	 */
private void addProperties(UserEntity userEntity) throws ServiceException {
    User user = getAndCheckUser(userEntity.getUsername());
    user.getProperties().clear();
    if (userEntity.getProperties() != null) {
        for (UserProperty property : userEntity.getProperties()) {
            user.getProperties().put(property.getKey(), property.getValue());
        }
    }
}
Also used : User(org.jivesoftware.openfire.user.User) UserProperty(org.jivesoftware.openfire.entity.UserProperty)

Example 40 with User

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

the class UserServicePluginNG method updateUser.

/**
	 * Update user.
	 *
	 * @param username
	 *            the username
	 * @param userEntity
	 *            the user entity
	 * @throws ServiceException
	 *             the service exception
	 */
public void updateUser(String username, UserEntity userEntity) throws ServiceException {
    if (userEntity != null && !username.isEmpty()) {
        User user = getAndCheckUser(username);
        if (userEntity.getPassword() != null) {
            user.setPassword(userEntity.getPassword());
        }
        if (userEntity.getName() != null) {
            user.setName(userEntity.getName());
        }
        if (userEntity.getEmail() != null) {
            user.setEmail(userEntity.getEmail());
        }
        addProperties(userEntity);
    }
}
Also used : User(org.jivesoftware.openfire.user.User)

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