Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not display passwords of GeoResources and Services in UI #262

Merged
merged 7 commits into from
Feb 12, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,7 @@ public URI getSource() {
}

public String getTitle() {
return "MySQL " + getIdentifier(); //$NON-NLS-1$
//return "MySQL " + getIdentifier().getHost() + URLUtils.urlToFile(getIdentifier()).getAbsolutePath(); //$NON-NLS-1$
return "MySQL " + getDisplayID(); //$NON-NLS-1$
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.locationtech.udig.catalog;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.net.URL;

import org.eclipse.core.runtime.IProgressMonitor;
import org.junit.Test;

public class IGeoResourceTest {
@Test
public void testGetDisplayIDWithUserInfoHasNoPassword() throws Exception {
final URL urlWithUserInfo = new URL("http://testuser:testpasswd@localhost:1523");
IGeoResource geoResourceMock = new IGeoResource() {

@Override
public Status getStatus() {
return null;
}

@Override
public Throwable getMessage() {
return null;
}

@Override
public URL getIdentifier() {
return urlWithUserInfo;
}

@Override
protected IGeoResourceInfo createInfo(IProgressMonitor monitor) throws IOException {
return null;
}
};

String displayID = geoResourceMock.getDisplayID();

assertNotNull(displayID);
assertTrue(!displayID.contains("testpasswd"));
assertTrue(displayID.contains("testuser:**"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected Control createContents(Composite parent) {
label.setText("ID:");

Text text = new Text( page, SWT.SINGLE | SWT.BORDER );
text.setText( resource.getID().toString() );
text.setText( resource.getDisplayID() );
text.setEditable(false);
text.setLayoutData("width 100:300:,wrap");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,23 @@ public ID getID() {
return new ID(getIdentifier());
}

/**
* hide user password from the layer ID if it exists and returns
* ID as String.
*
* @param layer
* @return
*/
public String getDisplayID() {
String userInfo = getIdentifier().getUserInfo();
if (userInfo != null) {
userInfo = userInfo.substring(0, userInfo.indexOf(":")+1);
userInfo = userInfo.concat("******");
return new ID(getIdentifier().toString().replace(getIdentifier().getUserInfo(), userInfo), null).toString();
}
return getID().toString();
}

/**
* Disposes of any resources or listeners required. Default implementation does nothing.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,35 +339,52 @@ public IServiceInfo getInfo( IProgressMonitor monitor ) throws IOException {
throw new IllegalStateException("Lookup of getInfo not available from the display thread"); //$NON-NLS-1$
}
info = createInfo(monitor);

if( info == null ){
info = INFO_UNAVAILABLE;
}
else {
// broadcast the change - code taken from ArcServiceImpl

// this delta describes what has changed
/*
IResolveDelta delta = new ResolveDelta(this, IResolveDelta.Kind.CHANGED);

// fire the change
CatalogImpl localCatalog = (CatalogImpl) CatalogPlugin.getDefault().getLocalCatalog();
localCatalog.fire(new ResolveChangeEvent(this, IResolveChangeEvent.Type.POST_CHANGE, delta));
*/
*/
}
}
}
}
if (info == INFO_UNAVAILABLE) {
return null; // info was not available
}
return info;
return info;
}

public ID getID() {
return new ID(getIdentifier());
}

/**
* hide user password from the layer ID if it exists and returns
* ID as String.
*
* @param layer
* @return
*/
public String getDisplayID() {
String userInfo = getIdentifier().getUserInfo();
if (userInfo != null) {
userInfo = userInfo.substring(0, userInfo.indexOf(":")+1);
userInfo = userInfo.concat("******");
return new ID(getIdentifier().toString().replace(getIdentifier().getUserInfo(), userInfo), null).toString();
}
return getID().toString();
}

/**
* Map of parameters used to create this entry. There is no guarantee that these params created
* a usable service (@see getStatus() ). These params may have been modified within the factory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected Control createContents( Composite parent ) {
nameData.setModifier(new NameModifier());
data.add(nameData);
newName=oldName=nameData.getInfo();
data.add(new SummaryData(Messages.LayerSummary_id,layer.getID()));
data.add(new SummaryData(Messages.LayerSummary_id, layer.getGeoResource().getDisplayID()));
data.add(new SummaryData(Messages.LayerSummary_bounds, bounds==null?Messages.LayerSummary_unknownBounds:parseBounds(bounds)));
data.add(new SummaryData(Messages.LayerSummary_selection,layer.getFilter()));
data.add(new SummaryData(Messages.LayerSummary_status, layer.getStatusMessage()));
Expand Down