Commit b11bf489 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

[GATE-66] Added validity check for usernames.

Fixed stupid bug with MSN sessions setting login status and then immediately checking it.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk/src/plugins/gateway@5525 b35dd754-fafc-0310-a699-88a17e54d16e
parent 1f732e18
......@@ -569,8 +569,11 @@ public abstract class BaseTransport implements Component, RosterEventListener, P
password = (password == null || password.equals("")) ? null : password;
nickname = (nickname == null || nickname.equals("")) ? null : nickname;
if (username == null || (isPasswordRequired() && password == null) || (isNicknameRequired() && nickname == null)) {
// Found nothing from stanza, lets yell.
if ( username == null
|| (isPasswordRequired() && password == null)
|| (isNicknameRequired() && nickname == null)
|| !isUsernameValid(username)) {
// Invalid information from stanza, lets yell.
IQ result = IQ.createResultIQ(packet);
result.setError(Condition.bad_request);
reply.add(result);
......@@ -1446,4 +1449,9 @@ public abstract class BaseTransport implements Component, RosterEventListener, P
*/
public abstract Boolean isNicknameRequired();
/**
* Returns true or false whether the passed username is valud for the service.
*/
public abstract Boolean isUsernameValid(String username);
}
......@@ -66,6 +66,13 @@ public class IRCTransport extends BaseTransport {
*/
public Boolean isNicknameRequired() { return true; }
/**
* @see org.jivesoftware.wildfire.gateway.BaseTransport#isUsernameValid(String)
*/
public Boolean isUsernameValid(String username) {
return username.matches("\\p{Alnum}+");
}
/**
* Handles creating a IRC session and triggering a login.
*
......
......@@ -70,8 +70,8 @@ public class MSNSession extends TransportSession {
* @param verboseStatus Long representation of status.
*/
public void logIn(PresenceType presenceType, String verboseStatus) {
setLoginStatus(TransportLoginStatus.LOGGING_IN);
if (!this.isLoggedIn()) {
setLoginStatus(TransportLoginStatus.LOGGING_IN);
msnMessenger.getOwner().setInitStatus(((MSNTransport)getTransport()).convertJabStatusToMSN(presenceType));
msnMessenger.setLogIncoming(false);
msnMessenger.setLogOutgoing(false);
......@@ -84,8 +84,8 @@ public class MSNSession extends TransportSession {
* Log out of MSN.
*/
public void logOut() {
setLoginStatus(TransportLoginStatus.LOGGING_OUT);
if (this.isLoggedIn()) {
setLoginStatus(TransportLoginStatus.LOGGING_OUT);
msnMessenger.logout();
}
Presence p = new Presence(Presence.Type.unavailable);
......
......@@ -68,6 +68,13 @@ public class MSNTransport extends BaseTransport {
*/
public Boolean isNicknameRequired() { return false; }
/**
* @see org.jivesoftware.wildfire.gateway.BaseTransport#isUsernameValid(String)
*/
public Boolean isUsernameValid(String username) {
return username.matches("\\w+@[\\w\\.]+");
}
/**
* Handles creating a MSN session and triggering a login.
*
......
......@@ -11,10 +11,7 @@
package org.jivesoftware.wildfire.gateway.protocols.oscar;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.wildfire.gateway.BaseTransport;
import org.jivesoftware.wildfire.gateway.TransportSession;
import org.jivesoftware.wildfire.gateway.PresenceType;
import org.jivesoftware.wildfire.gateway.Registration;
import org.jivesoftware.wildfire.gateway.*;
import org.xmpp.packet.JID;
/**
......@@ -65,6 +62,18 @@ public class OSCARTransport extends BaseTransport {
*/
public Boolean isNicknameRequired() { return false; }
/**
* @see org.jivesoftware.wildfire.gateway.BaseTransport#isUsernameValid(String)
*/
public Boolean isUsernameValid(String username) {
if (getType() == TransportType.icq) {
return username.matches("\\p{Digit}+");
}
else {
return username.matches("\\p{Alnum}+") || username.matches("\\w+@[\\w\\.]+");
}
}
/**
* Handles creating an OSCAR session and triggering a login.
*
......
......@@ -68,6 +68,13 @@ public class YahooTransport extends BaseTransport {
*/
public Boolean isNicknameRequired() { return false; }
/**
* @see org.jivesoftware.wildfire.gateway.BaseTransport#isUsernameValid(String)
*/
public Boolean isUsernameValid(String username) {
return username.matches("\\p{Alnum}+");
}
/**
* Handles creating a Yahoo session and triggering a login.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment