1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-28 19:35:36 +02:00

[168977][api][refactor] - stage 3.2

- introduced the AbstractCredentialsProvider into the CredentialsProvider hierarchy.
This commit is contained in:
David Dykstal 2007-03-27 19:59:47 +00:00
parent 3fdff2f490
commit aca3ef566f
7 changed files with 67 additions and 58 deletions

View file

@ -42,7 +42,7 @@ public class DaytimeConnectorService extends AbstractConnectorService {
private boolean fIsConnected = false; private boolean fIsConnected = false;
private DaytimeService fDaytimeService; private DaytimeService fDaytimeService;
private ICredentialsProvider fCredentialsProvider = new BasicCredentialsProvider(); private ICredentialsProvider fCredentialsProvider = new BasicCredentialsProvider(this);
public DaytimeConnectorService(IHost host) { public DaytimeConnectorService(IHost host) {
super(DaytimeResources.Daytime_Connector_Name, DaytimeResources.Daytime_Connector_Description, host, 13); super(DaytimeResources.Daytime_Connector_Name, DaytimeResources.Daytime_Connector_Description, host, 13);

View file

@ -32,7 +32,7 @@ import samples.RSESamplesPlugin;
public class DeveloperConnectorService extends AbstractConnectorService { public class DeveloperConnectorService extends AbstractConnectorService {
private boolean connected = false; private boolean connected = false;
private ICredentialsProvider credentialsProvider = new BasicCredentialsProvider(); private ICredentialsProvider credentialsProvider = new BasicCredentialsProvider(this);
/** /**
* Constructor for DeveloperConnectorService. * Constructor for DeveloperConnectorService.

View file

@ -33,7 +33,7 @@ import org.eclipse.rse.core.subsystems.ICredentialsProvider;
public class LocalConnectorService extends AbstractConnectorService public class LocalConnectorService extends AbstractConnectorService
{ {
private ICredentialsProvider credentialsProvider = new BasicCredentialsProvider(); private ICredentialsProvider credentialsProvider = new BasicCredentialsProvider(this);
/** /**
* Constructor when we don't have a subsystem yet. * Constructor when we don't have a subsystem yet.

View file

@ -0,0 +1,41 @@
/********************************************************************************
* Copyright (c) 2007 IBM Corporation. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* David Dykstal (IBM) - 168977: refactoring IConnectorService
********************************************************************************/
package org.eclipse.rse.core.subsystems;
/**
* The {@link AbstractCredentialsProvider} provides the base
* implementation of the {@link ICredentialsProvider}
* interface. It remembers the connector service and suppression
* state for the provider.
* <p>
* This class is meant to be subclassed.
*/
public abstract class AbstractCredentialsProvider implements ICredentialsProvider {
private IConnectorService connectorService = null;
private boolean suppressed = false;
public AbstractCredentialsProvider(IConnectorService connectorService) {
this.connectorService = connectorService;
}
public final IConnectorService getConnectorService() {
return connectorService;
}
public final boolean isSuppressed() {
return suppressed;
}
public final void setSuppressed(boolean suppressed) {
this.suppressed = suppressed;
}
}

View file

@ -18,7 +18,12 @@ import org.eclipse.rse.services.clientserver.messages.SystemMessage;
* <p> * <p>
* This class is not meant to be subclassed. * This class is not meant to be subclassed.
*/ */
public class BasicCredentialsProvider implements ICredentialsProvider { public class BasicCredentialsProvider extends AbstractCredentialsProvider {
public BasicCredentialsProvider(IConnectorService connectorService) {
super(connectorService);
}
public void acquireCredentials(boolean reacquire) { public void acquireCredentials(boolean reacquire) {
} }
@ -26,26 +31,17 @@ public class BasicCredentialsProvider implements ICredentialsProvider {
} }
public void clearPassword() { public void clearPassword() {
// TODO Auto-generated method stub
} }
public ICredentials getCredentials() { public ICredentials getCredentials() {
// TODO Auto-generated method stub
return null; return null;
} }
public String getUserId() { public String getUserId() {
// TODO Auto-generated method stub
return null; return null;
} }
public boolean isSuppressed() {
// TODO Auto-generated method stub
return false;
}
public void repairCredentials(SystemMessage message) throws InterruptedException { public void repairCredentials(SystemMessage message) throws InterruptedException {
// TODO Auto-generated method stub
} }
public boolean requiresPassword() { public boolean requiresPassword() {
@ -57,15 +53,9 @@ public class BasicCredentialsProvider implements ICredentialsProvider {
} }
public void setPassword(String password) { public void setPassword(String password) {
// TODO Auto-generated method stub
}
public void setSuppressed(boolean suppressed) {
// TODO Auto-generated method stub
} }
public void setUserId(String userId) { public void setUserId(String userId) {
// TODO Auto-generated method stub
} }
public boolean supportsPassword() { public boolean supportsPassword() {
@ -76,8 +66,4 @@ public class BasicCredentialsProvider implements ICredentialsProvider {
return false; return false;
} }
public IConnectorService getConnectorService() {
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -12,6 +12,7 @@ package org.eclipse.rse.ui.subsystems;
import org.eclipse.rse.core.PasswordPersistenceManager; import org.eclipse.rse.core.PasswordPersistenceManager;
import org.eclipse.rse.core.model.IHost; import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.core.model.SystemSignonInformation; import org.eclipse.rse.core.model.SystemSignonInformation;
import org.eclipse.rse.core.subsystems.AbstractCredentialsProvider;
import org.eclipse.rse.core.subsystems.IConnectorService; import org.eclipse.rse.core.subsystems.IConnectorService;
import org.eclipse.rse.core.subsystems.ICredentials; import org.eclipse.rse.core.subsystems.ICredentials;
import org.eclipse.rse.core.subsystems.ICredentialsProvider; import org.eclipse.rse.core.subsystems.ICredentialsProvider;
@ -49,7 +50,7 @@ import org.eclipse.ui.PlatformUI;
* This class is may be subclassed. Typically to provide connector service * This class is may be subclassed. Typically to provide connector service
* specific prompting. * specific prompting.
*/ */
public class StandardCredentialsProvider implements ICredentialsProvider { public class StandardCredentialsProvider extends AbstractCredentialsProvider {
private class PromptForCredentials implements Runnable { private class PromptForCredentials implements Runnable {
private boolean canceled = false; private boolean canceled = false;
@ -60,7 +61,7 @@ public class StandardCredentialsProvider implements ICredentialsProvider {
public void run() { public void run() {
ISystemPasswordPromptDialog dialog = getPasswordPromptDialog(getShell()); ISystemPasswordPromptDialog dialog = getPasswordPromptDialog(getShell());
dialog.setSystemInput(connectorService); dialog.setSystemInput(getConnectorService());
dialog.setForceToUpperCase(forcePasswordToUpperCase()); dialog.setForceToUpperCase(forcePasswordToUpperCase());
dialog.setSignonValidator(getSignonValidator()); dialog.setSignonValidator(getSignonValidator());
if (supportsUserId()) { if (supportsUserId()) {
@ -98,7 +99,7 @@ public class StandardCredentialsProvider implements ICredentialsProvider {
} }
public void run() { public void run() {
SystemChangePasswordDialog dlg = new SystemChangePasswordDialog(getShell(), connectorService.getHostName(), getUserId(), message); SystemChangePasswordDialog dlg = new SystemChangePasswordDialog(getShell(), getConnectorService().getHostName(), getUserId(), message);
dlg.setSavePassword(savePassword); dlg.setSavePassword(savePassword);
dlg.open(); dlg.open();
canceled = dlg.wasCancelled(); canceled = dlg.wasCancelled();
@ -109,15 +110,13 @@ public class StandardCredentialsProvider implements ICredentialsProvider {
} }
} }
private IConnectorService connectorService = null;
private String userId = null; private String userId = null;
private String password = null; private String password = null;
private boolean suppressed = false;
private boolean savePassword = false; private boolean savePassword = false;
private boolean saveUserId = false; private boolean saveUserId = false;
public StandardCredentialsProvider(IConnectorService connectorService) { public StandardCredentialsProvider(IConnectorService connectorService) {
this.connectorService = connectorService; super(connectorService);
} }
/** /**
@ -144,7 +143,7 @@ public class StandardCredentialsProvider implements ICredentialsProvider {
String hostType = host.getSystemType(); String hostType = host.getSystemType();
savePassword = false; savePassword = false;
if (supportsUserId()) { if (supportsUserId()) {
boolean sameHost = hostName.equalsIgnoreCase(connectorService.getHostName()); boolean sameHost = hostName.equalsIgnoreCase(getConnectorService().getHostName());
if (!sameHost) { if (!sameHost) {
clearCredentials(); clearCredentials();
} }
@ -170,7 +169,7 @@ public class StandardCredentialsProvider implements ICredentialsProvider {
// Not sure this is necessary, shouldn't this message show up on the password prompt itself? // Not sure this is necessary, shouldn't this message show up on the password prompt itself?
if (!signonValid) { if (!signonValid) {
SystemMessage msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_COMM_PWD_INVALID); SystemMessage msg = RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_COMM_PWD_INVALID);
msg.makeSubstitution(userId, connectorService.getHostName()); msg.makeSubstitution(userId, getConnectorService().getHostName());
SystemMessageDialog dialog = new SystemMessageDialog(getShell(), msg); SystemMessageDialog dialog = new SystemMessageDialog(getShell(), msg);
dialog.open(); dialog.open();
} }
@ -180,12 +179,12 @@ public class StandardCredentialsProvider implements ICredentialsProvider {
if (passwordNeeded || userIdNeeded || reacquire) { if (passwordNeeded || userIdNeeded || reacquire) {
promptForCredentials(); promptForCredentials();
if (savePassword) { if (savePassword) {
connectorService.savePassword(); getConnectorService().savePassword();
} else { } else {
connectorService.removePassword(); getConnectorService().removePassword();
} }
if (saveUserId) { if (saveUserId) {
connectorService.saveUserId(); getConnectorService().saveUserId();
} }
} }
} }
@ -205,12 +204,8 @@ public class StandardCredentialsProvider implements ICredentialsProvider {
password = null; password = null;
} }
public IConnectorService getConnectorService() {
return connectorService;
}
public ICredentials getCredentials() { public ICredentials getCredentials() {
IHost host = connectorService.getHost(); IHost host = getConnectorService().getHost();
String hostName = host.getHostName(); String hostName = host.getHostName();
String systemType = host.getSystemType(); String systemType = host.getSystemType();
SystemSignonInformation result = new SystemSignonInformation(hostName, userId, password, systemType); SystemSignonInformation result = new SystemSignonInformation(hostName, userId, password, systemType);
@ -232,13 +227,6 @@ public class StandardCredentialsProvider implements ICredentialsProvider {
return userId; return userId;
} }
/* (non-Javadoc)
* @see org.eclipse.rse.core.subsystems.IConnectorService#isSuppressed()
*/
public final boolean isSuppressed() {
return suppressed;
}
public void repairCredentials(SystemMessage prompt) throws InterruptedException { public void repairCredentials(SystemMessage prompt) throws InterruptedException {
promptForNewPassword(prompt); promptForNewPassword(prompt);
} }
@ -266,24 +254,18 @@ public class StandardCredentialsProvider implements ICredentialsProvider {
if (getPrimarySubSystem().forceUserIdToUpperCase()) { if (getPrimarySubSystem().forceUserIdToUpperCase()) {
matchingUserId = matchingUserId.toUpperCase(); matchingUserId = matchingUserId.toUpperCase();
} }
SystemSignonInformation signonInformation = new SystemSignonInformation(connectorService.getHostName(), matchingUserId, password, connectorService.getHostType()); IConnectorService cs = getConnectorService();
String systemType = cs.getHostType();
String hostName = cs.getHostName();
SystemSignonInformation signonInformation = new SystemSignonInformation(hostName, matchingUserId, password, systemType);
setSignonInformation(signonInformation); setSignonInformation(signonInformation);
if (persist) { // if password should be persisted, then add to disk if (persist) { // if password should be persisted, then add to disk
PasswordPersistenceManager.getInstance().add(signonInformation, true, true); PasswordPersistenceManager.getInstance().add(signonInformation, true, true);
} else { // otherwise, remove from both memory and disk } else { // otherwise, remove from both memory and disk
String systemType = connectorService.getHostType();
String hostName = connectorService.getHostName();
PasswordPersistenceManager.getInstance().remove(systemType, hostName, userId); PasswordPersistenceManager.getInstance().remove(systemType, hostName, userId);
} }
} }
/* (non-Javadoc)
* @see org.eclipse.rse.core.subsystems.IConnectorService#setSuppressed(boolean)
*/
public final void setSuppressed(boolean suppressed) {
this.suppressed = suppressed;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.rse.core.subsystems.IConnectorService#setUserId(java.lang.String) * @see org.eclipse.rse.core.subsystems.IConnectorService#setUserId(java.lang.String)
*/ */
@ -344,7 +326,7 @@ public class StandardCredentialsProvider implements ICredentialsProvider {
} }
private ISubSystem getPrimarySubSystem() { private ISubSystem getPrimarySubSystem() {
return connectorService.getPrimarySubSystem(); return getConnectorService().getPrimarySubSystem();
} }
private Shell getShell() { private Shell getShell() {

View file

@ -20,7 +20,7 @@ import org.eclipse.rse.core.subsystems.ICredentialsProvider;
public class TestSubSystemConnectorService extends AbstractConnectorService { public class TestSubSystemConnectorService extends AbstractConnectorService {
private boolean connected = false; private boolean connected = false;
private ICredentialsProvider credentialsProvider = new BasicCredentialsProvider(); private ICredentialsProvider credentialsProvider = new BasicCredentialsProvider(this);
/** /**
* Constructor. * Constructor.