当前位置: 首页>>代码示例>>Java>>正文


Java Authentication类代码示例

本文整理汇总了Java中org.jivesoftware.smack.packet.Authentication的典型用法代码示例。如果您正苦于以下问题:Java Authentication类的具体用法?Java Authentication怎么用?Java Authentication使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Authentication类属于org.jivesoftware.smack.packet包,在下文中一共展示了Authentication类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: authenticateAnonymously

import org.jivesoftware.smack.packet.Authentication; //导入依赖的package包/类
public String authenticateAnonymously() throws XMPPException {
    // Create the authentication packet we'll send to the server.
    Authentication auth = new Authentication();

    PacketCollector collector =
        connection.createPacketCollector(new PacketIDFilter(auth.getPacketID()));
    // Send the packet.
    connection.sendPacket(auth);
    // Wait up to a certain number of seconds for a response from the server.
    IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    if (response == null) {
        throw new XMPPException("Anonymous login failed.");
    }
    else if (response.getType() == IQ.Type.ERROR) {
        throw new XMPPException(response.getError());
    }
    // We're done with the collector, so explicitly cancel it.
    collector.cancel();

    if (response.getTo() != null) {
        return response.getTo();
    }
    else {
        return connection.getServiceName() + "/" + ((Authentication) response).getResource();
    }
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:27,代码来源:NonSASLAuthentication.java

示例2: parseIQ

import org.jivesoftware.smack.packet.Authentication; //导入依赖的package包/类
private IQ parseIQ(Element doc) {
    Element pingEl = doc.element(Ping.ELEMENT);
    if (pingEl != null
            && pingEl.getNamespace().getURI().equals(Ping.NAMESPACE)) {
        return new Ping(doc);
    }

    Element bindEl = doc.element(Bind.ELEMENT);
    if (bindEl != null
            && bindEl.getNamespace().getURI().equals(Bind.NAMESPACE)) {
        return new Bind(doc);
    }

    Element query = doc.element("query");
    if (query != null) {
        if ("jabber:iq:roster".equals(query.getNamespaceURI())) {
            return new Roster(doc);
        }
        if ("jabber:iq:auth".equals(query.getNamespaceURI())) {
            return new Authentication(doc);
        }
    }

    return new IQ(doc);
}
 
开发者ID:abmargb,项目名称:jamppa,代码行数:26,代码来源:PacketReader.java

示例3: parseAuthentication

import org.jivesoftware.smack.packet.Authentication; //导入依赖的package包/类
private static Authentication parseAuthentication(XmlPullParser parser) throws Exception {
    Authentication authentication = new Authentication();
    boolean done = false;
    while (!done) {
        int eventType = parser.next();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("username")) {
                authentication.setUsername(parser.nextText());
            }
            else if (parser.getName().equals("password")) {
                authentication.setPassword(parser.nextText());
            }
            else if (parser.getName().equals("digest")) {
                authentication.setDigest(parser.nextText());
            }
            else if (parser.getName().equals("resource")) {
                authentication.setResource(parser.nextText());
            }
        }
        else if (eventType == XmlPullParser.END_TAG) {
            if (parser.getName().equals("query")) {
                done = true;
            }
        }
    }
    return authentication;
}
 
开发者ID:samuelhehe,项目名称:androidpn_enhanced_client,代码行数:28,代码来源:PacketParserUtils.java

示例4: authenticateAnonymously

import org.jivesoftware.smack.packet.Authentication; //导入依赖的package包/类
public String authenticateAnonymously() throws XMPPException {
	// Create the authentication packet we'll send to the server.
	Authentication auth = new Authentication();

	PacketCollector collector = connection
			.createPacketCollector(new PacketIDFilter(auth.getPacketID()));
	// Send the packet.
	connection.sendPacket(auth);
	// Wait up to a certain number of seconds for a response from the
	// server.
	IQ response = (IQ) collector.nextResult(SmackConfiguration
			.getPacketReplyTimeout());
	if (response == null) {
		throw new XMPPException("Anonymous login failed.");
	} else if (response.getType() == IQ.Type.ERROR) {
		throw new XMPPException(response.getError());
	}
	// We're done with the collector, so explicitly cancel it.
	collector.cancel();

	if (response.getTo() != null) {
		return response.getTo();
	} else {
		return connection.getServiceName() + "/"
				+ ((Authentication) response).getResource();
	}
}
 
开发者ID:ikantech,项目名称:xmppsupport_v2,代码行数:28,代码来源:NonSASLAuthentication.java

示例5: authenticateAnonymously

import org.jivesoftware.smack.packet.Authentication; //导入依赖的package包/类
public String authenticateAnonymously() throws XMPPException {
    // Create the authentication packet we'll send to the server.
    Authentication auth = new Authentication();

    PacketCollector collector = connection
            .createPacketCollector(new PacketIDFilter(auth.getID()));
    // Send the packet.
    connection.sendPacket(auth);
    // Wait up to a certain number of seconds for a response from the
    // server.
    IQ response = (IQ) collector.nextResult(SmackConfiguration
            .getPacketReplyTimeout());
    if (response == null) {
        throw new XMPPException("Anonymous login failed.");
    } else if (response.getType() == IQ.Type.error) {
        throw new XMPPException(response.getError());
    }
    // We're done with the collector, so explicitly cancel it.
    collector.cancel();

    if (response.getTo() != null) {
        return response.getTo().toFullJID();
    } else {
        return connection.getServiceName() + "/"
                + ((Authentication) response).getResource();
    }
}
 
开发者ID:abmargb,项目名称:jamppa,代码行数:28,代码来源:NonSASLAuthentication.java

示例6: authenticate

import org.jivesoftware.smack.packet.Authentication; //导入依赖的package包/类
public String authenticate(String username, String password, String resource) throws
        XMPPException {
    // If we send an authentication packet in "get" mode with just the username,
    // the server will return the list of authentication protocols it supports.
    Authentication discoveryAuth = new Authentication();
    discoveryAuth.setType(IQ.Type.GET);
    discoveryAuth.setUsername(username);

    PacketCollector collector =
        connection.createPacketCollector(new PacketIDFilter(discoveryAuth.getPacketID()));
    // Send the packet
    connection.sendPacket(discoveryAuth);
    // Wait up to a certain number of seconds for a response from the server.
    IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    if (response == null) {
        throw new XMPPException("No response from the server.");
    }
    // If the server replied with an error, throw an exception.
    else if (response.getType() == IQ.Type.ERROR) {
        throw new XMPPException(response.getError());
    }
    // Otherwise, no error so continue processing.
    Authentication authTypes = (Authentication) response;
    collector.cancel();

    // Now, create the authentication packet we'll send to the server.
    Authentication auth = new Authentication();
    auth.setUsername(username);

    // Figure out if we should use digest or plain text authentication.
    if (authTypes.getDigest() != null) {
        auth.setDigest(connection.getConnectionID(), password);
    }
    else if (authTypes.getPassword() != null) {
        auth.setPassword(password);
    }
    else {
        throw new XMPPException("Server does not support compatible authentication mechanism.");
    }

    auth.setResource(resource);

    collector = connection.createPacketCollector(new PacketIDFilter(auth.getPacketID()));
    // Send the packet.
    connection.sendPacket(auth);
    // Wait up to a certain number of seconds for a response from the server.
    response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    if (response == null) {
        throw new XMPPException("Authentication failed.");
    }
    else if (response.getType() == IQ.Type.ERROR) {
        throw new XMPPException(response.getError());
    }
    // We're done with the collector, so explicitly cancel it.
    collector.cancel();

    return response.getTo();
}
 
开发者ID:ice-coffee,项目名称:EIM,代码行数:59,代码来源:NonSASLAuthentication.java

示例7: authenticate

import org.jivesoftware.smack.packet.Authentication; //导入依赖的package包/类
public String authenticate(String username, String password, String resource)
		throws XMPPException {
	// If we send an authentication packet in "get" mode with just the
	// username,
	// the server will return the list of authentication protocols it
	// supports.
	Authentication discoveryAuth = new Authentication();
	discoveryAuth.setType(IQ.Type.GET);
	discoveryAuth.setUsername(username);

	PacketCollector collector = connection
			.createPacketCollector(new PacketIDFilter(discoveryAuth
					.getPacketID()));
	// Send the packet
	connection.sendPacket(discoveryAuth);
	// Wait up to a certain number of seconds for a response from the
	// server.
	IQ response = (IQ) collector.nextResult(SmackConfiguration
			.getPacketReplyTimeout());
	if (response == null) {
		throw new XMPPException("No response from the server.");
	}
	// If the server replied with an error, throw an exception.
	else if (response.getType() == IQ.Type.ERROR) {
		throw new XMPPException(response.getError());
	}
	// Otherwise, no error so continue processing.
	Authentication authTypes = (Authentication) response;
	collector.cancel();

	// Now, create the authentication packet we'll send to the server.
	Authentication auth = new Authentication();
	auth.setUsername(username);

	// Figure out if we should use digest or plain text authentication.
	if (authTypes.getDigest() != null) {
		auth.setDigest(connection.getConnectionID(), password);
	} else if (authTypes.getPassword() != null) {
		auth.setPassword(password);
	} else {
		throw new XMPPException(
				"Server does not support compatible authentication mechanism.");
	}

	auth.setResource(resource);

	collector = connection.createPacketCollector(new PacketIDFilter(auth
			.getPacketID()));
	// Send the packet.
	connection.sendPacket(auth);
	// Wait up to a certain number of seconds for a response from the
	// server.
	response = (IQ) collector.nextResult(SmackConfiguration
			.getPacketReplyTimeout());
	if (response == null) {
		throw new XMPPException("Authentication failed.");
	} else if (response.getType() == IQ.Type.ERROR) {
		throw new XMPPException(response.getError());
	}
	// We're done with the collector, so explicitly cancel it.
	collector.cancel();

	return response.getTo();
}
 
开发者ID:ikantech,项目名称:xmppsupport_v2,代码行数:65,代码来源:NonSASLAuthentication.java


注:本文中的org.jivesoftware.smack.packet.Authentication类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。