- setEditableUserName, isEditableUserName methods added to enable protocols to specify if the user name is editable through login.

- Fix client behavior when logging with wrong password or when trying to log in and there's no network connection. Enhancements of the Login window.
cusax-fix
Yana Stamcheva 18 years ago
parent e48c9eea04
commit 12f1596096

@ -56,7 +56,7 @@ authenticationWindowTitle=Authentication requested
authRejected=contact has rejected your authorization request.
authorizationRequested=Authorization requested
authorizationRequestedInfo=The {0} contact requests your authorization.
authenticationFailed=The authentication failed for the following account: User name: {0}, Server name: {1}. The password you entered is not valid.
authenticationFailed=Authentication failed. The password you entered is not valid.
authorizationResponse=Authorization response
autoPopup=Bring window to front
awayStatus=Away

@ -738,10 +738,15 @@ public ConfigurationWindow getConfigurationWindow()
*/
public ExportedWindow getAuthenticationWindow(
ProtocolProviderService protocolProvider,
String realm, UserCredentials userCredentials)
{
return new AuthenticationWindow(mainFrame, protocolProvider,
realm, userCredentials);
String realm,
UserCredentials userCredentials,
boolean isUserNameEditable)
{
return new AuthenticationWindow(mainFrame,
protocolProvider,
realm,
userCredentials,
isUserNameEditable);
}
/**

@ -37,7 +37,7 @@ public class AuthenticationWindow
private JLabel passwdLabel = new JLabel(
Messages.getI18NString("passwd").getText());
private JLabel uinValueLabel;
private JComponent uinValue;
private JPasswordField passwdField = new JPasswordField(15);
@ -68,22 +68,29 @@ public class AuthenticationWindow
private String realm;
private boolean isUserNameEditable = false;
/**
* Creates an instance of the <tt>LoginWindow</tt>.
* @param mainFrame the parent <tt>MainFrame</tt> window.
* @param protocolProvider the protocol provider.
* @param realm the realm
* @param userCredentials the user credentials
* @param isUserNameEditable indicates if the user name should be editable
* by the user or not.
*/
public AuthenticationWindow(MainFrame mainFrame,
ProtocolProviderService protocolProvider,
String realm,
UserCredentials userCredentials) {
UserCredentials userCredentials,
boolean isUserNameEditable)
{
this.userCredentials = userCredentials;
this.realm = realm;
this.isUserNameEditable = isUserNameEditable;
ProtocolIcon protocolIcon = protocolProvider.getProtocolIcon();
Image logoImage = null;
@ -123,21 +130,53 @@ else if(protocolIcon.isSizeSupported(ProtocolIcon.ICON_SIZE_48x48))
this.enableKeyActions();
}
/**
* Creates an instance of the <tt>LoginWindow</tt>.
* @param mainFrame the parent <tt>MainFrame</tt> window.
* @param protocolProvider the protocol provider.
* @param realm the realm
* @param userCredentials the user credentials
* @param isUserNameEditable indicates if the user name should be editable
* by the user or not.
* @param errorMessage an error message explaining a reason for opening
* the authentication dialog (when a wrong password was provided, etc.)
*/
public AuthenticationWindow(MainFrame mainFrame,
ProtocolProviderService protocolProvider,
String realm,
UserCredentials userCredentials,
boolean isUserNameEditable,
String errorMessage)
{
this( mainFrame,
protocolProvider,
realm,
userCredentials,
isUserNameEditable);
this.realmTextArea.setForeground(Color.RED);
this.realmTextArea.setText(errorMessage);
}
/**
* Constructs the <tt>LoginWindow</tt>.
*/
private void init() {
private void init()
{
if(!isUserNameEditable)
this.uinValue = new JLabel(userCredentials.getUserName());
else
this.uinValue = new JTextField(userCredentials.getUserName());
this.uinValueLabel = new JLabel(userCredentials.getUserName());
if(userCredentials.getPassword() != null) {
this.passwdField.setText(userCredentials.getPassword().toString());
}
this.realmTextArea.setEditable(false);
this.realmTextArea.setOpaque(false);
this.realmTextArea.setLineWrap(true);
this.realmTextArea.setWrapStyleWord(true);
this.realmTextArea.setFont(Constants.FONT.deriveFont(Font.BOLD, 12f));
this.realmTextArea.setEditable(false);
this.realmTextArea.setText(
Messages.getI18NString("securityAuthorityRealm",
new String[]{realm}).getText());
@ -151,7 +190,7 @@ private void init() {
this.rememberPassCheckBox.setOpaque(false);
this.textFieldsPanel.add(uinValueLabel);
this.textFieldsPanel.add(uinValue);
this.textFieldsPanel.add(passwdField);
this.textFieldsPanel.add(rememberPassCheckBox);

@ -262,18 +262,18 @@ else if (evt.getReasonCode() == RegistrationStateChangeEvent
Messages.getI18NString("error").getText(),
msgText).showDialog();
}
else if (evt.getReasonCode() == RegistrationStateChangeEvent
.REASON_AUTHENTICATION_FAILED)
{
String msgText = Messages.getI18NString("authenticationFailed",
new String[]
{ accountID.getUserID(), accountID.getService() })
.getText();
new ErrorDialog(null,
Messages.getI18NString("error").getText(),
msgText).showDialog();
}
// else if (evt.getReasonCode() == RegistrationStateChangeEvent
// .REASON_AUTHENTICATION_FAILED)
// {
// String msgText = Messages.getI18NString("authenticationFailed",
// new String[]
// { accountID.getUserID(), accountID.getService() })
// .getText();
//
// new ErrorDialog(null,
// Messages.getI18NString("error").getText(),
// msgText).showDialog();
// }
logger.error(evt.getReason());
}
else if (evt.getNewState().equals(RegistrationState.CONNECTION_FAILED))

@ -6,6 +6,7 @@
*/
package net.java.sip.communicator.impl.gui.main.login;
import net.java.sip.communicator.impl.gui.i18n.*;
import net.java.sip.communicator.impl.gui.main.*;
import net.java.sip.communicator.service.protocol.*;
@ -21,6 +22,8 @@ public class SecurityAuthorityImpl implements SecurityAuthority {
private ProtocolProviderService protocolProvider;
private boolean isUserNameEditable = false;
/**
* Creates an instance of <tt>SecurityAuthorityImpl</tt>.
* @param mainFrame The parent window of the <tt>AuthenticationWIndow</tt>
@ -29,7 +32,8 @@ public class SecurityAuthorityImpl implements SecurityAuthority {
* <tt>SecurityAuthority</tt>.
*/
public SecurityAuthorityImpl(MainFrame mainFrame,
ProtocolProviderService protocolProvider) {
ProtocolProviderService protocolProvider)
{
this.mainFrame = mainFrame;
this.protocolProvider = protocolProvider;
}
@ -38,15 +42,90 @@ public SecurityAuthorityImpl(MainFrame mainFrame,
* Implements the <code>SecurityAuthority.obtainCredentials</code> method.
* Creates and show an <tt>AuthenticationWindow</tt>, where user could enter
* its password.
* @param realm The realm that the credentials are needed for.
* @param userCredentials the values to propose the user by default
* @param reasonCode indicates the reason for which we're obtaining the
* credentials.
* @return The credentials associated with the specified realm or null if
* none could be obtained.
*/
public UserCredentials obtainCredentials(String realm,
UserCredentials userCredentials)
public UserCredentials obtainCredentials(
String realm,
UserCredentials userCredentials,
int reasonCode)
{
AuthenticationWindow loginWindow = new AuthenticationWindow(
mainFrame, protocolProvider, realm, userCredentials);
String errorMessage = null;
if (reasonCode == WRONG_PASSWORD)
{
errorMessage
= Messages.getI18NString("authenticationFailed").getText();
}
else if (reasonCode == WRONG_USERNAME)
{
errorMessage
= Messages.getI18NString("authenticationFailed").getText();
}
AuthenticationWindow loginWindow = null;
if (errorMessage == null)
loginWindow = new AuthenticationWindow( mainFrame,
protocolProvider,
realm,
userCredentials,
isUserNameEditable);
else
loginWindow = new AuthenticationWindow( mainFrame,
protocolProvider,
realm,
userCredentials,
isUserNameEditable,
errorMessage);
loginWindow.setVisible(true);
return userCredentials;
}
/**
* Implements the <code>SecurityAuthority.obtainCredentials</code> method.
* Creates and show an <tt>AuthenticationWindow</tt>, where user could enter
* its password.
* @param realm The realm that the credentials are needed for.
* @param userCredentials the values to propose the user by default
* @return The credentials associated with the specified realm or null if
* none could be obtained.
*/
public UserCredentials obtainCredentials(
String realm,
UserCredentials userCredentials)
{
return this.obtainCredentials(realm, userCredentials,
SecurityAuthority.AUTHENTICATION_REQUIRED);
}
/**
* Sets the userNameEditable property, which indicates if the user name
* could be changed by user or not.
*
* @param isUserNameEditable indicates if the user name could be changed by
* user
*/
public void setUserNameEditable(boolean isUserNameEditable)
{
this.isUserNameEditable = isUserNameEditable;
}
/**
* Indicates if the user name is currently editable, i.e. could be changed
* by user or not.
*
* @return <code>true</code> if the user name could be changed,
* <code>false</code> - otherwise.
*/
public boolean isUserNameEditable()
{
return isUserNameEditable;
}
}

@ -326,8 +326,9 @@ public void register(SecurityAuthority authority)
credentials.setUserName(getAccountID().getUserID());
//request a password from the user
credentials = authority.obtainCredentials("Gibberish"
, credentials);
credentials = authority.obtainCredentials(
"Gibberish",
credentials);
//extract the password the user passed us.
char[] pass = credentials.getPassword();

@ -8,7 +8,6 @@
import java.util.*;
import net.java.sip.communicator.impl.protocol.gibberish.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
@ -101,7 +100,12 @@ public class ProtocolProviderServiceIcqImpl
* Property whether we are using AIM or ICQ service
*/
boolean USING_ICQ = true;
/**
* Used when we need to re-register
*/
private SecurityAuthority authority = null;
/**
* Returns the state of the registration of this protocol provider
* @return the <tt>RegistrationState</tt> that this provider is
@ -206,17 +210,55 @@ public void register(SecurityAuthority authority)
"The register method needs a valid non-null authority impl "
+ " in order to be able and retrieve passwords.");
// Keep the authority in case we need to re-register.
this.authority = authority;
connectAndLogin(authority, SecurityAuthority.AUTHENTICATION_REQUIRED);
}
/**
* Reconnects if fails fire connection failed.
* @param reasonCode the appropriate <tt>SecurityAuthority</tt> reasonCode,
* which would specify the reason for which we're re-calling the login.
*/
void reconnect(int reasonCode)
{
try
{
connectAndLogin(authority, reasonCode);
}
catch (OperationFailedException ex)
{
fireRegistrationStateChanged(
getRegistrationState(),
RegistrationState.CONNECTION_FAILED,
RegistrationStateChangeEvent.REASON_NOT_SPECIFIED, null);
}
}
/**
* Connects and logins to the server
* @param authority SecurityAuthority
* @throws OperationFailedException if login parameters
* as server port are not correct
*/
private void connectAndLogin(SecurityAuthority authority, int reasonCode)
throws OperationFailedException
{
synchronized(initializationLock)
{
ProtocolProviderFactoryIcqImpl protocolProviderFactory = null;
if(USING_ICQ)
protocolProviderFactory = IcqActivator.getIcqProtocolProviderFactory();
protocolProviderFactory
= IcqActivator.getIcqProtocolProviderFactory();
else
protocolProviderFactory = IcqActivator.getAimProtocolProviderFactory();
protocolProviderFactory
= IcqActivator.getAimProtocolProviderFactory();
//verify whether a password has already been stored for this account
String password = protocolProviderFactory.loadPassword(getAccountID());
String password
= protocolProviderFactory.loadPassword(getAccountID());
//decode
if( password == null )
@ -226,9 +268,11 @@ public void register(SecurityAuthority authority)
credentials.setUserName(this.getAccountID().getUserID());
//request a password from the user
credentials = authority.obtainCredentials(getProtocolName()
, credentials);
credentials = authority.obtainCredentials(
getProtocolName(),
credentials,
reasonCode);
// in case user has canceled the login window
if(credentials == null)
{
@ -791,13 +835,18 @@ else if (newState == State.DISCONNECTED)
else
IcqActivator.getAimProtocolProviderFactory().storePassword(
getAccountID(), null);
reconnect(SecurityAuthority.WRONG_PASSWORD);
}
//now tell all interested parties about what happened.
fireRegistrationStateChanged(oldState, event.getOldStateInfo()
, newState, event.getNewStateInfo()
, reasonCode, reasonStr);
fireRegistrationStateChanged(
oldState,
event.getOldStateInfo(),
newState,
event.getNewStateInfo(),
reasonCode,
reasonStr);
}
}

@ -341,7 +341,10 @@ public void register(SecurityAuthority authority)
//request a password from the user
credentials
= authority.obtainCredentials(ProtocolNames.IRC, credentials);
= authority.obtainCredentials(
ProtocolNames.IRC,
credentials,
SecurityAuthority.AUTHENTICATION_REQUIRED);
//extract the password the user passed us.
char[] pass = credentials.getPassword();

@ -519,7 +519,8 @@ public void run()
{
logger.error("unregistering.");
// fireUnregisterd();
jabberProvider.reregister();
jabberProvider
.reregister(SecurityAuthority.CONNECTION_FAILED);
failedKeepalivePackets = 0;
}
}

@ -17,11 +17,7 @@
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.util.*;
import org.jivesoftware.smack.filter.*;
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smackx.*;
import org.jivesoftware.smackx.packet.*;
/**
* An implementation of the protocol provider service over the Jabber protocol
@ -150,7 +146,8 @@ public void register(final SecurityAuthority authority)
try
{
connectAndLogin(authority);
connectAndLogin(authority,
SecurityAuthority.AUTHENTICATION_REQUIRED);
}
catch (XMPPException ex)
{
@ -174,9 +171,13 @@ public void register(final SecurityAuthority authority)
{
JabberActivator.getProtocolProviderFactory().
storePassword(getAccountID(), null);
reason
= RegistrationStateChangeEvent.REASON_AUTHENTICATION_FAILED;
reason = RegistrationStateChangeEvent
.REASON_AUTHENTICATION_FAILED;
regState = RegistrationState.AUTHENTICATION_FAILED;
// Try to reregister and to ask user for a new password.
reregister(SecurityAuthority.WRONG_PASSWORD);
}
fireRegistrationStateChanged(
@ -185,9 +186,11 @@ public void register(final SecurityAuthority authority)
}
/**
* Connects and logins again to the server
* Connects and logins again to the server.
*
* @param authReasonCode indicates the reason of the re-authentication.
*/
void reregister()
void reregister(int authReasonCode)
{
try
{
@ -199,7 +202,8 @@ void reregister()
this.reconnecting = true;
connectAndLogin(authority);
connectAndLogin(authority,
authReasonCode);
}
catch(OperationFailedException ex)
{
@ -228,11 +232,13 @@ void reregister()
/**
* Connects and logins to the server
* @param authority SecurityAuthority
* @param reasonCode the authentication reason code. Indicates the reason of
* this authentication.
* @throws XMPPException if we cannot connect to the server - network problem
* @throws OperationFailedException if login parameters
* as server port are not correct
*/
private void connectAndLogin(SecurityAuthority authority)
private void connectAndLogin(SecurityAuthority authority, int reasonCode)
throws XMPPException, OperationFailedException
{
synchronized(initializationLock)
@ -249,8 +255,10 @@ private void connectAndLogin(SecurityAuthority authority)
credentials.setUserName(getAccountID().getUserID());
//request a password from the user
credentials = authority.obtainCredentials(ProtocolNames.JABBER
, credentials);
credentials = authority.obtainCredentials(
ProtocolNames.JABBER,
credentials,
reasonCode);
// in case user has canceled the login window
if(credentials == null)
@ -425,7 +433,7 @@ private void unregister(boolean fireEvent)
{
RegistrationState currRegState = getRegistrationState();
if(connection != null)
if(connection != null && connection.isConnected())
connection.disconnect();
if(fireEvent)
@ -801,7 +809,7 @@ public void connectionClosedOnError(Exception exception)
exception.getLocalizedMessage());
if(!reconnecting)
reregister();
reregister(SecurityAuthority.CONNECTION_FAILED);
else
reconnecting = false;
}

@ -229,7 +229,7 @@ public void run()
if(!connected && msnProvider.isRegistered())
{
msnProvider.unregister(false);
msnProvider.reconnect();
msnProvider.reconnect(SecurityAuthority.CONNECTION_FAILED);
}
}
}, 20000);

@ -7,6 +7,8 @@
*/
package net.java.sip.communicator.impl.protocol.msn;
import java.io.*;
import java.net.*;
import java.nio.channels.*;
import java.util.*;
@ -107,18 +109,21 @@ public void register(final SecurityAuthority authority)
this.authority = authority;
connectAndLogin(authority);
connectAndLogin(authority, SecurityAuthority.AUTHENTICATION_REQUIRED);
}
/**
* Reconnects if fails fire connection failed.
* @param reasonCode the appropriate <tt>SecurityAuthority</tt> reasonCode,
* which would specify the reason for which we're re-calling the login.
*/
void reconnect()
void reconnect(int reasonCode)
{
try
{
connectAndLogin(authority);
} catch (OperationFailedException ex)
connectAndLogin(authority, reasonCode);
}
catch (OperationFailedException ex)
{
fireRegistrationStateChanged(
getRegistrationState(),
@ -133,7 +138,7 @@ void reconnect()
* @throws OperationFailedException if login parameters
* as server port are not correct
*/
private void connectAndLogin(SecurityAuthority authority)
private void connectAndLogin(SecurityAuthority authority, int reasonCode)
throws OperationFailedException
{
synchronized(initializationLock)
@ -150,8 +155,10 @@ private void connectAndLogin(SecurityAuthority authority)
credentials.setUserName(getAccountID().getUserID());
//request a password from the user
credentials = authority.obtainCredentials(ProtocolNames.MSN
, credentials);
credentials = authority.obtainCredentials(
ProtocolNames.MSN,
credentials,
reasonCode);
// in case user has canceled the login window
if(credentials == null)
@ -177,7 +184,6 @@ private void connectAndLogin(SecurityAuthority authority)
}
password = new String(pass);
if (credentials.isPasswordPersistent())
{
MsnActivator.getProtocolProviderFactory()
@ -185,7 +191,6 @@ private void connectAndLogin(SecurityAuthority authority)
}
}
messenger = MsnMessengerFactory.createMsnMessenger(
getAccountID().getUserID(),
password);
@ -501,21 +506,36 @@ public void logout(MsnMessenger msnMessenger)
// getRegistrationState(),
// RegistrationState.UNREGISTERED,
// RegistrationStateChangeEvent.REASON_NOT_SPECIFIED, null);
}
public void exceptionCaught(MsnMessenger msnMessenger, Throwable throwable)
public void exceptionCaught(MsnMessenger msnMessenger,
Throwable throwable)
{
if(throwable instanceof IncorrectPasswordException)
{
unregister(false);
MsnActivator.getProtocolProviderFactory().
storePassword(getAccountID(), null);
fireRegistrationStateChanged(
getRegistrationState(),
RegistrationState.AUTHENTICATION_FAILED,
RegistrationStateChangeEvent.REASON_AUTHENTICATION_FAILED,
"Incorrect Password");
// We try to reconnect and ask user to retype password.
reconnect(SecurityAuthority.WRONG_PASSWORD);
}
else if(throwable instanceof UnknownHostException
|| throwable instanceof SocketException)
{
unregister(false);
fireRegistrationStateChanged(
getRegistrationState(),
RegistrationState.CONNECTION_FAILED,
RegistrationStateChangeEvent.REASON_SERVER_NOT_FOUND,
"A network error occured. Could not connect to server.");
}
else
{
@ -524,7 +544,6 @@ public void exceptionCaught(MsnMessenger msnMessenger, Throwable throwable)
MsnProtocolException exception =
(MsnProtocolException)throwable;
logger.error("Error in Msn lib ", exception);
switch(exception.getErrorCode())
@ -553,6 +572,10 @@ public void exceptionCaught(MsnMessenger msnMessenger, Throwable throwable)
RegistrationState.AUTHENTICATION_FAILED,
RegistrationStateChangeEvent.
REASON_AUTHENTICATION_FAILED, null);
// We try to reconnect and ask user to retype
// password.
reconnect(SecurityAuthority.WRONG_PASSWORD);
}
break;
}

@ -519,6 +519,10 @@ public void register(SecurityAuthority authority)
return;
}
// Enable the user name modification. Setting this property to true we'll
// allow the user to change the user name stored in the given authority.
authority.setUserNameEditable(true);
//init the security manager before doing the actual registration to
//avoid being asked for credentials before being ready to provide them
sipSecurityManager.setSecurityAuthority(authority);

@ -197,7 +197,8 @@ else if (challenge.getStatusCode()
//obtain new credentials
logger.trace("We don't seem to have a good pass! Get one.");
ccEntry = createCcEntryWithNewCredentials(realm);
ccEntry = createCcEntryWithNewCredentials(
realm, SecurityAuthority.AUTHENTICATION_REQUIRED);
if(ccEntry == null)
throw new OperationFailedException(
@ -220,7 +221,8 @@ else if (challenge.getStatusCode()
SipActivator.getProtocolProviderFactory().storePassword(
accountID, null);
ccEntry = createCcEntryWithNewCredentials(realm);
ccEntry = createCcEntryWithNewCredentials(
realm, SecurityAuthority.WRONG_PASSWORD);
if(ccEntry == null)
throw new OperationFailedException(
@ -488,7 +490,9 @@ private void removeBranchID(Request request)
* @return a newly created <tt>CredentialsCacheEntry</tt> corresponding to
* the specified <tt>realm</tt>.
*/
private CredentialsCacheEntry createCcEntryWithNewCredentials(String realm)
private CredentialsCacheEntry createCcEntryWithNewCredentials(
String realm,
int reasonCode)
{
CredentialsCacheEntry ccEntry = new CredentialsCacheEntry();
@ -498,7 +502,8 @@ private CredentialsCacheEntry createCcEntryWithNewCredentials(String realm)
UserCredentials newCredentials =
getSecurityAuthority().obtainCredentials(
realm,
defaultCredentials);
defaultCredentials,
reasonCode);
// in case user has canceled the login window
if(newCredentials == null)

@ -8,12 +8,13 @@
import java.io.*;
import java.util.*;
import java.nio.channels.*;
import net.java.sip.communicator.impl.protocol.msn.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;
import org.jivesoftware.smack.*;
import ymsg.network.*;
import ymsg.network.event.*;
@ -108,17 +109,20 @@ public void register(final SecurityAuthority authority)
this.authority = authority;
connectAndLogin(authority);
connectAndLogin(authority, SecurityAuthority.AUTHENTICATION_REQUIRED);
}
/**
* Connects and logins to the server
* @param authority SecurityAuthority
* @param authReasonCode the authentication reason code, which should
* indicate why are making an authentication request
* @throws XMPPException if we cannot connect to the server - network problem
* @throws OperationFailedException if login parameters
* as server port are not correct
*/
private void connectAndLogin(SecurityAuthority authority)
private void connectAndLogin( SecurityAuthority authority,
int authReasonCode)
throws OperationFailedException
{
synchronized(initializationLock)
@ -135,8 +139,10 @@ private void connectAndLogin(SecurityAuthority authority)
credentials.setUserName(getAccountID().getUserID());
//request a password from the user
credentials = authority.obtainCredentials(ProtocolNames.YAHOO
, credentials);
credentials = authority.obtainCredentials(
ProtocolNames.YAHOO,
credentials,
authReasonCode);
//extract the password the user passed us.
char[] pass = credentials.getPassword();
@ -152,7 +158,6 @@ private void connectAndLogin(SecurityAuthority authority)
}
password = new String(pass);
if (credentials.isPasswordPersistent())
{
YahooActivator.getProtocolProviderFactory()
@ -192,7 +197,11 @@ private void connectAndLogin(SecurityAuthority authority)
fireRegistrationStateChanged(
getRegistrationState(),
RegistrationState.AUTHENTICATION_FAILED,
RegistrationStateChangeEvent.REASON_AUTHENTICATION_FAILED, null);
RegistrationStateChangeEvent.REASON_AUTHENTICATION_FAILED,
null);
// Try to re-register and ask the user to retype the password.
reregister(SecurityAuthority.WRONG_PASSWORD);
}
catch (IOException ex)
{
@ -204,6 +213,26 @@ private void connectAndLogin(SecurityAuthority authority)
}
}
/**
* Reconnects if fails fire connection failed.
* @param reasonCode the appropriate <tt>SecurityAuthority</tt> reasonCode,
* which would specify the reason for which we're re-calling the login.
*/
void reregister(int reasonCode)
{
try
{
connectAndLogin(authority, reasonCode);
}
catch (OperationFailedException ex)
{
fireRegistrationStateChanged(
getRegistrationState(),
RegistrationState.CONNECTION_FAILED,
RegistrationStateChangeEvent.REASON_NOT_SPECIFIED, null);
}
}
/**
* Ends the registration of this protocol provider with the service.
*/

@ -30,6 +30,8 @@ public class ProviderRegistration
*/
private ProtocolProviderService protocolProvider;
private boolean isUserNameEditable = false;
/**
* The logger for this class.
*/
@ -90,17 +92,63 @@ else if (errorCode == OperationFailedException
*
* @param realm the realm that the credentials are needed for
* @param userCredentials the values to propose the user by default
*
* @param reasonCode the reason for which we're asking for credentials
* @return The Credentials associated with the speciefied realm
*/
public UserCredentials obtainCredentials(String realm,
UserCredentials userCredentials)
public UserCredentials obtainCredentials(
String realm,
UserCredentials userCredentials,
int reasonCode)
{
ExportedWindow loginWindow = SystrayActivator.getUIService()
.getAuthenticationWindow(protocolProvider, realm, userCredentials);
ExportedWindow loginWindow
= SystrayActivator.getUIService()
.getAuthenticationWindow(protocolProvider,
realm,
userCredentials,
isUserNameEditable);
loginWindow.setVisible(true);
return userCredentials;
}
/**
* Used to login to the protocol providers
*
* @param realm the realm that the credentials are needed for
* @param userCredentials the values to propose the user by default
* @return The Credentials associated with the speciefied realm
*/
public UserCredentials obtainCredentials(
String realm,
UserCredentials userCredentials)
{
return obtainCredentials( realm,
userCredentials,
SecurityAuthority.AUTHENTICATION_REQUIRED);
}
/**
* Sets the userNameEditable property, which should indicate to the
* implementations of this interface if the user name could be changed by
* user or not.
*
* @param isUserNameEditable indicates if the user name could be changed by
* user in the implementation of this interface.
*/
public void setUserNameEditable(boolean isUserNameEditable)
{
this.isUserNameEditable = isUserNameEditable;
}
/**
* Indicates if the user name is currently editable, i.e. could be changed
* by user or not.
*
* @return <code>true</code> if the user name could be changed,
* <code>false</code> - otherwise.
*/
public boolean isUserNameEditable()
{
return isUserNameEditable;
}
}

@ -328,13 +328,16 @@ public ExportedWindow getExportedWindow(WindowID windowID)
* @param realm the realm
* @param userCredentials the <tt>UserCredentials</tt>, where the username
* and password details are stored
* @param isUserNameEditable indicates if the user name could be changed
* by user.
* @return an <tt>ExportableComponent</tt> that corresponds to an
* authentication window for the given protocol provider and user information.
*/
public ExportedWindow getAuthenticationWindow(
ProtocolProviderService protocolProvider,
String realm,
UserCredentials userCredentials);
UserCredentials userCredentials,
boolean isUserNameEditable);
/**
* Returns the <tt>ConfigurationWindow</tt> implementation for this

@ -8,28 +8,87 @@
/**
* Implemented by the user interface, this interface allows a protocol provider
* to asynchronosly demand passwords necessary for authentication agaisn various
* realms.
* to asynchronously demand passwords necessary for authentication against
* various realms.
* <p>
* Or in other (simpler words) this is a callback or a hook that the UI would
* give a protocol provider so that the protocol provider could
* requestCredentials() when necessary (when a password is not available for
* a server, or once it has changed, or redemand one after a faulty
* a server, or once it has changed, or re-demand one after a faulty
* authentication)
*
* @author Emil Ivov
* @author Yana Stamcheva
*/
public interface SecurityAuthority
{
/**
* Indicates that the reason for obtaining credentials is that an
* authentication is required.
*/
public static final int AUTHENTICATION_REQUIRED = 0;
/**
* Returns a Credentials object associated with the specified realm.
* Indicates that the reason for obtaining credentials is that the last time
* a wrong password has been provided.
*/
public static final int WRONG_PASSWORD = 1;
/**
* Indicates that the reason for obtaining credentials is that the last time
* a wrong user name has been provided.
*/
public static final int WRONG_USERNAME = 2;
/**
* Indicates that the reason for obtaining credentials is that the last time
* a wrong user name has been provided.
*/
public static final int CONNECTION_FAILED = 3;
/**
* Returns a UserCredentials object associated with the specified realm, by
* specifying the reason of this operation.
* <p>
* @param realm The realm that the credentials are needed for.
* @param defaultValues the values to propose the user by default
* @param reasonCode indicates the reason for which we're obtaining the
* credentials.
* @return The credentials associated with the specified realm or null if
* none could be obtained.
*/
public UserCredentials obtainCredentials(String realm,
UserCredentials defaultValues);
public UserCredentials obtainCredentials(String realm,
UserCredentials defaultValues,
int reasonCode);
/**
* Returns a UserCredentials object associated with the specified realm, by
* specifying the reason of this operation.
* <p>
* @param realm The realm that the credentials are needed for.
* @param defaultValues the values to propose the user by default
* @return The credentials associated with the specified realm or null if
* none could be obtained.
*/
public UserCredentials obtainCredentials(String realm,
UserCredentials defaultValues);
/**
* Sets the userNameEditable property, which should indicate to the
* implementations of this interface if the user name could be changed by
* user or not.
*
* @param isUserNameEditable indicates if the user name could be changed by
* user in the implementation of this interface.
*/
public void setUserNameEditable(boolean isUserNameEditable);
/**
* Indicates if the user name is currently editable, i.e. could be changed
* by user or not.
*
* @return <code>true</code> if the user name could be changed,
* <code>false</code> - otherwise.
*/
public boolean isUserNameEditable();
}

@ -252,6 +252,8 @@ public void waitForEvent(long waitFor)
public class SecurityAuthorityImpl
implements SecurityAuthority
{
private boolean isUserNameEditable = false;
/**
* The password to return when asked for credentials
*/
@ -269,6 +271,23 @@ public SecurityAuthorityImpl(char[] passwd)
this.passwd = passwd;
}
/**
* Returns a Credentials object associated with the specified realm.
* <p>
* @param realm The realm that the credentials are needed for.
* @param defaultValues the values to propose the user by default
* @param reasonCode the reason for which we're obtaining the
* credentials.
* @return The credentials associated with the specified realm or null
* if none could be obtained.
*/
public UserCredentials obtainCredentials(String realm,
UserCredentials defaultValues,
int reasonCode)
{
return obtainCredentials(realm, defaultValues);
}
/**
* Returns a Credentials object associated with the specified realm.
* <p>
@ -284,6 +303,27 @@ public UserCredentials obtainCredentials(String realm,
return defaultValues;
}
/**
* Sets the userNameEditable property, which should indicate if the
* user name could be changed by user or not.
*
* @param isUserNameEditable indicates if the user name could be changed
*/
public void setUserNameEditable(boolean isUserNameEditable)
{
this.isUserNameEditable = isUserNameEditable;
}
/**
* Indicates if the user name is currently editable, i.e. could be changed
* by user or not.
*
* @return <code>true</code> if the user name could be changed,
* <code>false</code> - otherwise.
*/
public boolean isUserNameEditable()
{
return isUserNameEditable;
}
}
}

@ -502,6 +502,8 @@ public class SecurityAuthorityImpl implements SecurityAuthority
*/
private char[] passwd = null;
private boolean isUserNameEditable = false;
/**
* Creates an instance of this class that would always return "passwd"
* when asked for credentials.
@ -519,6 +521,24 @@ public SecurityAuthorityImpl(char[] passwd)
* <p>
* @param realm The realm that the credentials are needed for.
* @param defaultValues the values to propose the user by default
* @param reasonCode the reason for which we're obtaining the
* credentials.
* @return The credentials associated with the specified realm or null if
* none could be obtained.
*/
public UserCredentials obtainCredentials(String realm,
UserCredentials defaultValues,
int reasonCode)
{
return obtainCredentials(realm, defaultValues);
}
/**
* Returns a Credentials object associated with the specified realm.
* <p>
* @param realm The realm that the credentials are needed for.
* @param defaultValues the values to propose the user by default
*
* @return The credentials associated with the specified realm or null if
* none could be obtained.
*/
@ -529,5 +549,27 @@ public UserCredentials obtainCredentials(String realm,
return defaultValues;
}
/**
* Sets the userNameEditable property, which should indicate if the
* user name could be changed by user or not.
*
* @param isUserNameEditable indicates if the user name could be changed
*/
public void setUserNameEditable(boolean isUserNameEditable)
{
this.isUserNameEditable = isUserNameEditable;
}
/**
* Indicates if the user name is currently editable, i.e. could be changed
* by user or not.
*
* @return <code>true</code> if the user name could be changed,
* <code>false</code> - otherwise.
*/
public boolean isUserNameEditable()
{
return isUserNameEditable;
}
}
}

@ -299,6 +299,7 @@ public void registrationStateChanged(RegistrationStateChangeEvent evt)
*/
public class SecurityAuthorityImpl implements SecurityAuthority
{
private boolean isUserNameEditable = false;
/**
* Creates an instance of this class that would would authentify our
@ -308,6 +309,24 @@ public class SecurityAuthorityImpl implements SecurityAuthority
public SecurityAuthorityImpl()
{}
/**
* Returns a Credentials object containing the password for our
* tested implementation.
* <p>
* @param realm The realm that the credentials are needed for.
* @param defaultValues the values to propose the user by default
* @param reasonCode the reason for which we're obtaining the
* credentials.
* @return The credentials associated with the specified realm or null if
* none could be obtained.
*/
public UserCredentials obtainCredentials(String realm,
UserCredentials defaultValues,
int reasonCode)
{
return obtainCredentials(realm, defaultValues);
}
/**
* Returns a Credentials object containing the password for our
* tested implementation.
@ -325,6 +344,29 @@ public UserCredentials obtainCredentials(String realm,
defaultValues.setPassword(passwd.toCharArray());
return defaultValues;
}
/**
* Sets the userNameEditable property, which should indicate if the
* user name could be changed by user or not.
*
* @param isUserNameEditable indicates if the user name could be changed
*/
public void setUserNameEditable(boolean isUserNameEditable)
{
this.isUserNameEditable = isUserNameEditable;
}
/**
* Indicates if the user name is currently editable, i.e. could be changed
* by user or not.
*
* @return <code>true</code> if the user name could be changed,
* <code>false</code> - otherwise.
*/
public boolean isUserNameEditable()
{
return isUserNameEditable;
}
}
}

@ -257,6 +257,8 @@ public class SecurityAuthorityImpl
*/
private char[] passwd = null;
private boolean isUserNameEditable = false;
/**
* Creates an instance of this class that would always return "passwd"
* when asked for credentials.
@ -284,6 +286,45 @@ public UserCredentials obtainCredentials(String realm,
return defaultValues;
}
/**
* Returns a Credentials object associated with the specified realm.
* <p>
* @param realm The realm that the credentials are needed for.
* @param defaultValues the values to propose the user by default
* @param reasonCode the reason for which we're obtaining the
* credentials.
* @return The credentials associated with the specified realm or null
* if none could be obtained.
*/
public UserCredentials obtainCredentials(String realm,
UserCredentials defaultValues,
int reasonCode)
{
return obtainCredentials(realm, defaultValues);
}
/**
* Sets the userNameEditable property, which should indicate if the
* user name could be changed by user or not.
*
* @param isUserNameEditable indicates if the user name could be changed
*/
public void setUserNameEditable(boolean isUserNameEditable)
{
this.isUserNameEditable = isUserNameEditable;
}
/**
* Indicates if the user name is currently editable, i.e. could be changed
* by user or not.
*
* @return <code>true</code> if the user name could be changed,
* <code>false</code> - otherwise.
*/
public boolean isUserNameEditable()
{
return isUserNameEditable;
}
}
}

@ -255,6 +255,8 @@ public class SecurityAuthorityImpl
*/
private char[] passwd = null;
private boolean isUserNameEditable = false;
/**
* Creates an instance of this class that would always return "passwd"
* when asked for credentials.
@ -267,6 +269,23 @@ public SecurityAuthorityImpl(char[] passwd)
this.passwd = passwd;
}
/**
* Returns a Credentials object associated with the specified realm.
* <p>
* @param realm The realm that the credentials are needed for.
* @param defaultValues the values to propose the user by default
* @param reasonCode the reason for which we're obtaining the
* credentials.
* @return The credentials associated with the specified realm or null
* if none could be obtained.
*/
public UserCredentials obtainCredentials(String realm,
UserCredentials defaultValues,
int reasonCode)
{
return obtainCredentials(realm, defaultValues);
}
/**
* Returns a Credentials object associated with the specified realm.
* <p>
@ -281,5 +300,28 @@ public UserCredentials obtainCredentials(String realm,
defaultValues.setPassword(passwd);
return defaultValues;
}
/**
* Sets the userNameEditable property, which should indicate if the
* user name could be changed by user or not.
*
* @param isUserNameEditable indicates if the user name could be changed
*/
public void setUserNameEditable(boolean isUserNameEditable)
{
this.isUserNameEditable = isUserNameEditable;
}
/**
* Indicates if the user name is currently editable, i.e. could be changed
* by user or not.
*
* @return <code>true</code> if the user name could be changed,
* <code>false</code> - otherwise.
*/
public boolean isUserNameEditable()
{
return isUserNameEditable;
}
}
}

@ -225,11 +225,28 @@ public void waitForEvent(long waitFor)
* @author Mihai Balan
*/
public class NullSecurityAuthority
implements SecurityAuthority
implements SecurityAuthority
{
public UserCredentials obtainCredentials(String realm,
UserCredentials defaultValues) {
return null;
}
public UserCredentials obtainCredentials(String realm,
UserCredentials defaultValues,
int reasonCode)
{
return null;
}
public UserCredentials obtainCredentials(String realm,
UserCredentials defaultValues)
{
return null;
}
public void setUserNameEditable(boolean isUserNameEditable)
{
}
public boolean isUserNameEditable()
{
return false;
}
}
}

@ -257,6 +257,8 @@ public class SecurityAuthorityImpl
*/
private char[] passwd = null;
private boolean isUserNameEditable = false;
/**
* Creates an instance of this class that would always return "passwd"
* when asked for credentials.
@ -269,6 +271,23 @@ public SecurityAuthorityImpl(char[] passwd)
this.passwd = passwd;
}
/**
* Returns a Credentials object associated with the specified realm.
* <p>
* @param realm The realm that the credentials are needed for.
* @param defaultValues the values to propose the user by default
* @param reasonCode the reason for which we're obtaining the
* credentials.
* @return The credentials associated with the specified realm or null
* if none could be obtained.
*/
public UserCredentials obtainCredentials(String realm,
UserCredentials defaultValues,
int reasonCode)
{
return obtainCredentials(realm, defaultValues);
}
/**
* Returns a Credentials object associated with the specified realm.
* <p>
@ -284,6 +303,28 @@ public UserCredentials obtainCredentials(String realm,
return defaultValues;
}
/**
* Sets the userNameEditable property, which should indicate if the
* user name could be changed by user or not.
*
* @param isUserNameEditable indicates if the user name could be changed
*/
public void setUserNameEditable(boolean isUserNameEditable)
{
this.isUserNameEditable = isUserNameEditable;
}
/**
* Indicates if the user name is currently editable, i.e. could be changed
* by user or not.
*
* @return <code>true</code> if the user name could be changed,
* <code>false</code> - otherwise.
*/
public boolean isUserNameEditable()
{
return isUserNameEditable;
}
}
}

@ -255,6 +255,8 @@ public class SecurityAuthorityImpl
*/
private char[] passwd = null;
private boolean isUserNameEditable = false;
/**
* Creates an instance of this class that would always return "passwd"
* when asked for credentials.
@ -267,6 +269,23 @@ public SecurityAuthorityImpl(char[] passwd)
this.passwd = passwd;
}
/**
* Returns a Credentials object associated with the specified realm.
* <p>
* @param realm The realm that the credentials are needed for.
* @param defaultValues the values to propose the user by default
* @param reasonCode the reason for which we're obtaining the
* credentials.
* @return The credentials associated with the specified realm or null
* if none could be obtained.
*/
public UserCredentials obtainCredentials(String realm,
UserCredentials defaultValues,
int reasonCode)
{
return obtainCredentials(realm, defaultValues);
}
/**
* Returns a Credentials object associated with the specified realm.
* <p>
@ -281,5 +300,28 @@ public UserCredentials obtainCredentials(String realm,
defaultValues.setPassword(passwd);
return defaultValues;
}
/**
* Sets the userNameEditable property, which should indicate if the
* user name could be changed by user or not.
*
* @param isUserNameEditable indicates if the user name could be changed
*/
public void setUserNameEditable(boolean isUserNameEditable)
{
this.isUserNameEditable = isUserNameEditable;
}
/**
* Indicates if the user name is currently editable, i.e. could be
* changed by user or not.
*
* @return <code>true</code> if the user name could be changed,
* <code>false</code> - otherwise.
*/
public boolean isUserNameEditable()
{
return isUserNameEditable;
}
}
}

Loading…
Cancel
Save