Search in sources :

Example 1 with GoogleUserSettingExtension

use of net.sf.kraken.protocols.xmpp.packet.GoogleUserSettingExtension in project Openfire by igniterealtime.

the class XMPPSession method logIn.

/**
     * @see net.sf.kraken.session.TransportSession#logIn(net.sf.kraken.type.PresenceType, String)
     */
@Override
public void logIn(PresenceType presenceType, String verboseStatus) {
    final org.jivesoftware.smack.packet.Presence presence = new org.jivesoftware.smack.packet.Presence(org.jivesoftware.smack.packet.Presence.Type.available);
    if (JiveGlobals.getBooleanProperty("plugin.gateway." + getTransport().getType() + ".avatars", true) && getAvatar() != null) {
        Avatar avatar = getAvatar();
        // Same thing in this case, so lets go ahead and set them.
        avatar.setLegacyIdentifier(avatar.getXmppHash());
        VCardUpdateExtension ext = new VCardUpdateExtension();
        ext.setPhotoHash(avatar.getLegacyIdentifier());
        presence.addExtension(ext);
    }
    final Presence.Mode pMode = ((XMPPTransport) getTransport()).convertGatewayStatusToXMPP(presenceType);
    if (pMode != null) {
        presence.setMode(pMode);
    }
    if (verboseStatus != null && verboseStatus.trim().length() > 0) {
        presence.setStatus(verboseStatus);
    }
    setPendingPresenceAndStatus(presenceType, verboseStatus);
    if (!this.isLoggedIn()) {
        listener = new XMPPListener(this);
        presenceHandler = new XMPPPresenceHandler(this);
        runThread = new Thread() {

            @Override
            public void run() {
                String userName = generateUsername(registration.getUsername());
                conn = new XMPPConnection(config);
                try {
                    conn.getSASLAuthentication().registerSASLMechanism("DIGEST-MD5", MySASLDigestMD5Mechanism.class);
                    if (getTransport().getType().equals(TransportType.facebook) && registration.getUsername().equals("{PLATFORM}")) {
                        conn.getSASLAuthentication().registerSASLMechanism("X-FACEBOOK-PLATFORM", FacebookConnectSASLMechanism.class);
                        conn.getSASLAuthentication().supportSASLMechanism("X-FACEBOOK-PLATFORM", 0);
                    }
                    Roster.setDefaultSubscriptionMode(SubscriptionMode.manual);
                    conn.connect();
                    conn.addConnectionListener(listener);
                    try {
                        conn.addPacketListener(presenceHandler, new PacketTypeFilter(org.jivesoftware.smack.packet.Presence.class));
                        // Use this to filter out anything we don't care about
                        conn.addPacketListener(listener, new OrFilter(new PacketTypeFilter(GoogleMailBoxPacket.class), new PacketExtensionFilter(GoogleNewMailExtension.ELEMENT_NAME, GoogleNewMailExtension.NAMESPACE)));
                        conn.login(userName, registration.getPassword(), xmppResource);
                        // send initial presence.
                        conn.sendPacket(presence);
                        conn.getChatManager().addChatListener(listener);
                        conn.getRoster().addRosterListener(listener);
                        if (JiveGlobals.getBooleanProperty("plugin.gateway." + getTransport().getType() + ".avatars", !TransportType.facebook.equals(getTransport().getType())) && getAvatar() != null) {
                            new Thread() {

                                @Override
                                public void run() {
                                    Avatar avatar = getAvatar();
                                    VCard vCard = new VCard();
                                    try {
                                        vCard.load(conn);
                                        vCard.setAvatar(Base64.decode(avatar.getImageData()), avatar.getMimeType());
                                        vCard.save(conn);
                                    } catch (XMPPException e) {
                                        Log.debug("XMPP: Error while updating vcard for avatar change.", e);
                                    } catch (NotFoundException e) {
                                        Log.debug("XMPP: Unable to find avatar while setting initial.", e);
                                    }
                                }
                            }.start();
                        }
                        setLoginStatus(TransportLoginStatus.LOGGED_IN);
                        syncUsers();
                        if (getTransport().getType().equals(TransportType.gtalk) && JiveGlobals.getBooleanProperty("plugin.gateway.gtalk.mailnotifications", true)) {
                            conn.sendPacket(new IQWithPacketExtension(generateFullJID(getRegistration().getUsername()), new GoogleUserSettingExtension(null, true, null), IQ.Type.SET));
                            conn.sendPacket(new IQWithPacketExtension(generateFullJID(getRegistration().getUsername()), new GoogleMailNotifyExtension()));
                            mailCheck = new MailCheck();
                            timer.schedule(mailCheck, timerInterval, timerInterval);
                        }
                    } catch (XMPPException e) {
                        Log.debug(getTransport().getType() + " user's login/password does not appear to be correct: " + getRegistration().getUsername(), e);
                        setFailureStatus(ConnectionFailureReason.USERNAME_OR_PASSWORD_INCORRECT);
                        sessionDisconnectedNoReconnect(LocaleUtils.getLocalizedString("gateway.xmpp.passwordincorrect", "kraken"));
                    }
                } catch (XMPPException e) {
                    Log.debug(getTransport().getType() + " user is not able to connect: " + getRegistration().getUsername(), e);
                    setFailureStatus(ConnectionFailureReason.CAN_NOT_CONNECT);
                    sessionDisconnected(LocaleUtils.getLocalizedString("gateway.xmpp.connectionfailed", "kraken"));
                }
            }
        };
        runThread.start();
    }
}
Also used : FacebookConnectSASLMechanism(net.sf.kraken.protocols.xmpp.mechanisms.FacebookConnectSASLMechanism) NotFoundException(org.jivesoftware.util.NotFoundException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) GoogleMailBoxPacket(net.sf.kraken.protocols.xmpp.packet.GoogleMailBoxPacket) VCardUpdateExtension(net.sf.kraken.protocols.xmpp.packet.VCardUpdateExtension) Presence(org.jivesoftware.smack.packet.Presence) VCard(org.jivesoftware.smackx.packet.VCard) GoogleUserSettingExtension(net.sf.kraken.protocols.xmpp.packet.GoogleUserSettingExtension) MySASLDigestMD5Mechanism(net.sf.kraken.protocols.xmpp.mechanisms.MySASLDigestMD5Mechanism) GoogleMailNotifyExtension(net.sf.kraken.protocols.xmpp.packet.GoogleMailNotifyExtension) Presence(org.jivesoftware.smack.packet.Presence) org.jivesoftware.smack(org.jivesoftware.smack) IQWithPacketExtension(net.sf.kraken.protocols.xmpp.packet.IQWithPacketExtension) PacketTypeFilter(org.jivesoftware.smack.filter.PacketTypeFilter) OrFilter(org.jivesoftware.smack.filter.OrFilter) Avatar(net.sf.kraken.avatars.Avatar) PacketExtensionFilter(org.jivesoftware.smack.filter.PacketExtensionFilter)

Aggregations

Avatar (net.sf.kraken.avatars.Avatar)1 FacebookConnectSASLMechanism (net.sf.kraken.protocols.xmpp.mechanisms.FacebookConnectSASLMechanism)1 MySASLDigestMD5Mechanism (net.sf.kraken.protocols.xmpp.mechanisms.MySASLDigestMD5Mechanism)1 GoogleMailBoxPacket (net.sf.kraken.protocols.xmpp.packet.GoogleMailBoxPacket)1 GoogleMailNotifyExtension (net.sf.kraken.protocols.xmpp.packet.GoogleMailNotifyExtension)1 GoogleUserSettingExtension (net.sf.kraken.protocols.xmpp.packet.GoogleUserSettingExtension)1 IQWithPacketExtension (net.sf.kraken.protocols.xmpp.packet.IQWithPacketExtension)1 VCardUpdateExtension (net.sf.kraken.protocols.xmpp.packet.VCardUpdateExtension)1 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)1 org.jivesoftware.smack (org.jivesoftware.smack)1 OrFilter (org.jivesoftware.smack.filter.OrFilter)1 PacketExtensionFilter (org.jivesoftware.smack.filter.PacketExtensionFilter)1 PacketTypeFilter (org.jivesoftware.smack.filter.PacketTypeFilter)1 Presence (org.jivesoftware.smack.packet.Presence)1 VCard (org.jivesoftware.smackx.packet.VCard)1 NotFoundException (org.jivesoftware.util.NotFoundException)1