Search in sources :

Example 1 with Registration

use of org.jivesoftware.smack.packet.Registration in project ecf by eclipse.

the class MultiUserChat method getRegistrationForm.

/**
 * Returns the room's registration form that an unaffiliated user, can use to become a member
 * of the room or <tt>null</tt> if no registration is possible. Some rooms may restrict the
 * privilege to register members and allow only room admins to add new members.<p>
 *
 * If the user requesting registration requirements is not allowed to register with the room
 * (e.g. because that privilege has been restricted), the room will return a "Not Allowed"
 * error to the user (error code 405).
 *
 * @return the registration Form that contains the fields to complete together with the
 * instrucions or <tt>null</tt> if no registration is possible.
 * @throws XMPPException if an error occurs asking the registration form for the room or a
 * 405 error if the user is not allowed to register with the room.
 */
public Form getRegistrationForm() throws XMPPException {
    Registration reg = new Registration();
    reg.setType(IQ.Type.GET);
    reg.setTo(room);
    PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
    PacketCollector collector = connection.createPacketCollector(filter);
    connection.sendPacket(reg);
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from server.");
    } else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
    return Form.getFormFrom(result);
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) PacketFilter(org.jivesoftware.smack.filter.PacketFilter) Registration(org.jivesoftware.smack.packet.Registration) IQ(org.jivesoftware.smack.packet.IQ) PacketCollector(org.jivesoftware.smack.PacketCollector) PacketTypeFilter(org.jivesoftware.smack.filter.PacketTypeFilter) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 2 with Registration

use of org.jivesoftware.smack.packet.Registration in project ecf by eclipse.

the class AccountManager method getRegistrationInfo.

/**
 * Gets the account registration info from the server.
 *
 * @throws XMPPException if an error occurs.
 */
private synchronized void getRegistrationInfo() throws XMPPException {
    Registration reg = new Registration();
    reg.setTo(connection.getServiceName());
    PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
    PacketCollector collector = connection.createPacketCollector(filter);
    connection.sendPacket(reg);
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from server.");
    } else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    } else {
        info = (Registration) result;
    }
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) PacketFilter(org.jivesoftware.smack.filter.PacketFilter) Registration(org.jivesoftware.smack.packet.Registration) IQ(org.jivesoftware.smack.packet.IQ) PacketTypeFilter(org.jivesoftware.smack.filter.PacketTypeFilter) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 3 with Registration

use of org.jivesoftware.smack.packet.Registration in project ecf by eclipse.

the class AccountManager method createAccount.

/**
 * Creates a new account using the specified username, password and account attributes.
 * The attributes Map must contain only String name/value pairs and must also have values
 * for all required attributes.
 *
 * @param username the username.
 * @param password the password.
 * @param attributes the account attributes.
 * @throws XMPPException if an error occurs creating the account.
 * @see #getAccountAttributes()
 */
public void createAccount(String username, String password, Map<String, String> attributes) throws XMPPException {
    if (!supportsAccountCreation()) {
        throw new XMPPException("Server does not support account creation.");
    }
    Registration reg = new Registration();
    reg.setType(IQ.Type.SET);
    reg.setTo(connection.getServiceName());
    attributes.put("username", username);
    attributes.put("password", password);
    reg.setAttributes(attributes);
    PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
    PacketCollector collector = connection.createPacketCollector(filter);
    connection.sendPacket(reg);
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from server.");
    } else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) PacketFilter(org.jivesoftware.smack.filter.PacketFilter) Registration(org.jivesoftware.smack.packet.Registration) IQ(org.jivesoftware.smack.packet.IQ) PacketTypeFilter(org.jivesoftware.smack.filter.PacketTypeFilter) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 4 with Registration

use of org.jivesoftware.smack.packet.Registration in project ecf by eclipse.

the class MultiUserChat method sendRegistrationForm.

/**
 * Sends the completed registration form to the server. After the user successfully submits
 * the form, the room may queue the request for review by the room admins or may immediately
 * add the user to the member list by changing the user's affiliation from "none" to "member.<p>
 *
 * If the desired room nickname is already reserved for that room, the room will return a
 * "Conflict" error to the user (error code 409). If the room does not support registration,
 * it will return a "Service Unavailable" error to the user (error code 503).
 *
 * @param form the completed registration form.
 * @throws XMPPException if an error occurs submitting the registration form. In particular, a
 *      409 error can occur if the desired room nickname is already reserved for that room;
 *      or a 503 error can occur if the room does not support registration.
 */
public void sendRegistrationForm(Form form) throws XMPPException {
    Registration reg = new Registration();
    reg.setType(IQ.Type.SET);
    reg.setTo(room);
    reg.addExtension(form.getDataFormToSend());
    PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
    PacketCollector collector = connection.createPacketCollector(filter);
    connection.sendPacket(reg);
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from server.");
    } else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) PacketFilter(org.jivesoftware.smack.filter.PacketFilter) Registration(org.jivesoftware.smack.packet.Registration) IQ(org.jivesoftware.smack.packet.IQ) PacketCollector(org.jivesoftware.smack.PacketCollector) PacketTypeFilter(org.jivesoftware.smack.filter.PacketTypeFilter) XMPPException(org.jivesoftware.smack.XMPPException) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Example 5 with Registration

use of org.jivesoftware.smack.packet.Registration in project ecf by eclipse.

the class AccountManager method changePassword.

/**
 * Changes the password of the currently logged-in account. This operation can only
 * be performed after a successful login operation has been completed. Not all servers
 * support changing passwords; an XMPPException will be thrown when that is the case.
 *
 * @throws IllegalStateException if not currently logged-in to the server.
 * @throws XMPPException if an error occurs when changing the password.
 */
public void changePassword(String newPassword) throws XMPPException {
    Registration reg = new Registration();
    reg.setType(IQ.Type.SET);
    reg.setTo(connection.getServiceName());
    Map<String, String> map = new HashMap<String, String>();
    map.put("username", StringUtils.parseName(connection.getUser()));
    map.put("password", newPassword);
    reg.setAttributes(map);
    PacketFilter filter = new AndFilter(new PacketIDFilter(reg.getPacketID()), new PacketTypeFilter(IQ.class));
    PacketCollector collector = connection.createPacketCollector(filter);
    connection.sendPacket(reg);
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();
    if (result == null) {
        throw new XMPPException("No response from server.");
    } else if (result.getType() == IQ.Type.ERROR) {
        throw new XMPPException(result.getError());
    }
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) PacketFilter(org.jivesoftware.smack.filter.PacketFilter) HashMap(java.util.HashMap) Registration(org.jivesoftware.smack.packet.Registration) IQ(org.jivesoftware.smack.packet.IQ) PacketTypeFilter(org.jivesoftware.smack.filter.PacketTypeFilter) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Aggregations

Registration (org.jivesoftware.smack.packet.Registration)7 AndFilter (org.jivesoftware.smack.filter.AndFilter)6 PacketFilter (org.jivesoftware.smack.filter.PacketFilter)6 PacketIDFilter (org.jivesoftware.smack.filter.PacketIDFilter)6 PacketTypeFilter (org.jivesoftware.smack.filter.PacketTypeFilter)6 IQ (org.jivesoftware.smack.packet.IQ)6 HashMap (java.util.HashMap)2 PacketCollector (org.jivesoftware.smack.PacketCollector)2 XMPPException (org.jivesoftware.smack.XMPPException)2