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 ...@@ -569,8 +569,11 @@ public abstract class BaseTransport implements Component, RosterEventListener, P
password = (password == null || password.equals("")) ? null : password; password = (password == null || password.equals("")) ? null : password;
nickname = (nickname == null || nickname.equals("")) ? null : nickname; nickname = (nickname == null || nickname.equals("")) ? null : nickname;
if (username == null || (isPasswordRequired() && password == null) || (isNicknameRequired() && nickname == null)) { if ( username == null
// Found nothing from stanza, lets yell. || (isPasswordRequired() && password == null)
|| (isNicknameRequired() && nickname == null)
|| !isUsernameValid(username)) {
// Invalid information from stanza, lets yell.
IQ result = IQ.createResultIQ(packet); IQ result = IQ.createResultIQ(packet);
result.setError(Condition.bad_request); result.setError(Condition.bad_request);
reply.add(result); reply.add(result);
...@@ -1446,4 +1449,9 @@ public abstract class BaseTransport implements Component, RosterEventListener, P ...@@ -1446,4 +1449,9 @@ public abstract class BaseTransport implements Component, RosterEventListener, P
*/ */
public abstract Boolean isNicknameRequired(); 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 { ...@@ -66,6 +66,13 @@ public class IRCTransport extends BaseTransport {
*/ */
public Boolean isNicknameRequired() { return true; } 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. * Handles creating a IRC session and triggering a login.
* *
......
...@@ -70,8 +70,8 @@ public class MSNSession extends TransportSession { ...@@ -70,8 +70,8 @@ public class MSNSession extends TransportSession {
* @param verboseStatus Long representation of status. * @param verboseStatus Long representation of status.
*/ */
public void logIn(PresenceType presenceType, String verboseStatus) { public void logIn(PresenceType presenceType, String verboseStatus) {
setLoginStatus(TransportLoginStatus.LOGGING_IN);
if (!this.isLoggedIn()) { if (!this.isLoggedIn()) {
setLoginStatus(TransportLoginStatus.LOGGING_IN);
msnMessenger.getOwner().setInitStatus(((MSNTransport)getTransport()).convertJabStatusToMSN(presenceType)); msnMessenger.getOwner().setInitStatus(((MSNTransport)getTransport()).convertJabStatusToMSN(presenceType));
msnMessenger.setLogIncoming(false); msnMessenger.setLogIncoming(false);
msnMessenger.setLogOutgoing(false); msnMessenger.setLogOutgoing(false);
...@@ -84,8 +84,8 @@ public class MSNSession extends TransportSession { ...@@ -84,8 +84,8 @@ public class MSNSession extends TransportSession {
* Log out of MSN. * Log out of MSN.
*/ */
public void logOut() { public void logOut() {
setLoginStatus(TransportLoginStatus.LOGGING_OUT);
if (this.isLoggedIn()) { if (this.isLoggedIn()) {
setLoginStatus(TransportLoginStatus.LOGGING_OUT);
msnMessenger.logout(); msnMessenger.logout();
} }
Presence p = new Presence(Presence.Type.unavailable); Presence p = new Presence(Presence.Type.unavailable);
......
...@@ -68,6 +68,13 @@ public class MSNTransport extends BaseTransport { ...@@ -68,6 +68,13 @@ public class MSNTransport extends BaseTransport {
*/ */
public Boolean isNicknameRequired() { return false; } 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. * Handles creating a MSN session and triggering a login.
* *
......
...@@ -11,10 +11,7 @@ ...@@ -11,10 +11,7 @@
package org.jivesoftware.wildfire.gateway.protocols.oscar; package org.jivesoftware.wildfire.gateway.protocols.oscar;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.wildfire.gateway.BaseTransport; import org.jivesoftware.wildfire.gateway.*;
import org.jivesoftware.wildfire.gateway.TransportSession;
import org.jivesoftware.wildfire.gateway.PresenceType;
import org.jivesoftware.wildfire.gateway.Registration;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
/** /**
...@@ -63,7 +60,19 @@ public class OSCARTransport extends BaseTransport { ...@@ -63,7 +60,19 @@ public class OSCARTransport extends BaseTransport {
/** /**
* @see org.jivesoftware.wildfire.gateway.BaseTransport#isNicknameRequired() * @see org.jivesoftware.wildfire.gateway.BaseTransport#isNicknameRequired()
*/ */
public Boolean isNicknameRequired() { return false; } 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. * Handles creating an OSCAR session and triggering a login.
......
...@@ -68,6 +68,13 @@ public class YahooTransport extends BaseTransport { ...@@ -68,6 +68,13 @@ public class YahooTransport extends BaseTransport {
*/ */
public Boolean isNicknameRequired() { return false; } 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. * 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