Skip to content

Commit

Permalink
TEIIDDES-1469: Security Properties added to the ds xml
Browse files Browse the repository at this point in the history
* Although the connection profile includes the security settings
  for accessing the wsdl the modelled version does not hence these
  properties are never transferred to the datasource xml file
  when the vdb is deployed. This ensures that these settings do
  appear in both the modelled connection profile and are injected
  into the -ds.xml file
  • Loading branch information
Paul Richardson committed Aug 29, 2012
1 parent 2bf2a22 commit 0ff543b
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ public interface IWSProfileConstants extends ICredentialsCommon {
* Currently only EndPoint is the only property provided by Data Tools connection profile that matches up.
*/
String DS_ENDPOINT = "wsdlURI"; //$NON-NLS-1$
String DS_SECURITY_TYPE = "SecurityType"; //$NON-NLS-1$";
String DS_SECURITY_TYPE = SECURITY_TYPE_ID;
String DS_AUTH_USER_NAME = "AuthUserName"; //$NON-NLS-1$
String DS_AUTH_PASSWORD = "AuthPassword"; //$NON-NLS-1$
String DS_WS_SECURITY_CONFIG_URL = "WsSecurityConfigURL"; //$NON-NLS-1$
String DS_WS_SECURITY_CONFIG_NAME = "WsSecurityConfigName"; //$NON-NLS-1$

String SOURCE_ENDPOINT = "EndPoint"; //$NON-NLS-1$
String SOAP_SERVICE_MODE = "DefaultServiceMode"; //$NON-NLS-1$
String SOAP_BINDING = "DefaultBinding"; //$NON-NLS-1$

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,63 @@
package org.teiid.designer.modelgenerator.wsdl;

import java.util.Properties;

import org.eclipse.datatools.connectivity.IConnectionProfile;
import org.teiid.designer.core.workspace.ModelResource;
import org.teiid.designer.core.workspace.ModelWorkspaceException;
import org.teiid.designer.datatools.connection.ConnectionInfoHelper;
import org.teiid.designer.datatools.connection.DataSourceConnectionConstants;
import org.teiid.designer.datatools.connection.IConnectionInfoProvider;
import org.teiid.designer.datatools.profiles.ws.IWSProfileConstants;
import org.teiid.designer.ui.common.ICredentialsCommon;


/**
* @since 8.0
*/
public class WSSoapConnectionInfoProvider extends ConnectionInfoHelper implements IConnectionInfoProvider, IWSProfileConstants {

/**
* Adds properties relating to the security access of the wsdl from the source set of properties
* to the target set of properties.
*
* When adding these properties to the resource the namespace is required yet when gathering
* the properties for the teiid -ds xml, the namespace is stripped. Thus, a flag is added to handle
* the two slightly different property keys
*
* @param source
* @param target
* @param includeNameSpace
*/
private void addSecurityProperties(Properties source, Properties target, boolean includeNameSpace) {
String securityTypeId = source.getProperty(ICredentialsCommon.SECURITY_TYPE_ID);
SecurityType securityType = SecurityType.retrieveValue(securityTypeId);
switch (securityType) {
case HTTPBasic:
String username = source.getProperty(ICredentialsCommon.USERNAME_PROP_ID);
if (username == null) {
username = source.getProperty(IWSProfileConstants.DS_AUTH_USER_NAME);
}

String key = includeNameSpace ? CONNECTION_NAMESPACE + DS_AUTH_USER_NAME : DS_AUTH_USER_NAME;
target.put(key, username);

String password = source.getProperty(ICredentialsCommon.PASSWORD_PROP_ID);
if (password == null) {
password = source.getProperty(IWSProfileConstants.DS_AUTH_PASSWORD);
}

key = includeNameSpace ? CONNECTION_NAMESPACE + DS_AUTH_PASSWORD : DS_AUTH_PASSWORD;
target.put(key, password);
break;
default:
// Do Nothing
}

/* Add the security type even if none */
String key = includeNameSpace ? CONNECTION_NAMESPACE + DS_SECURITY_TYPE : DS_SECURITY_TYPE;
target.put(key, securityType.name());
}

/**
* {@inheritDoc}
*
Expand All @@ -37,16 +79,20 @@ public void setConnectionInfo( ModelResource modelResource,

String nameInSource = modelResource.getModelAnnotation().getNameInSource();
if (nameInSource != null) {
connectionProps.put(CONNECTION_NAMESPACE + SOURCE_ENDPOINT, nameInSource);
connectionProps.put(CONNECTION_NAMESPACE + END_POINT_URI_PROP_ID, nameInSource);
}

if (props.getProperty(SOAP_ENDPOINT_KEY) != null) {
connectionProps.put(CONNECTION_NAMESPACE + DS_ENDPOINT, props.getProperty(SOAP_ENDPOINT_KEY));
String wsdlURI = props.getProperty(WSDL_URI_PROP_ID);
if (wsdlURI != null) {
connectionProps.put(CONNECTION_NAMESPACE + DS_ENDPOINT, wsdlURI);
}

String url = readURLProperty(props);
if (url != null) {
connectionProps.put(CONNECTION_NAMESPACE + END_POINT_URI_PROP_ID, url);
// Security
addSecurityProperties(props, connectionProps, true);

String endPointURI = readEndPointProperty(props);
if (endPointURI != null) {
connectionProps.put(CONNECTION_NAMESPACE + END_POINT_URI_PROP_ID, endPointURI);
}

if (props.getProperty(CONNECTION_CLASS_KEY) != null) {
Expand Down Expand Up @@ -82,9 +128,16 @@ public Properties getConnectionProperties( ModelResource modelResource ) throws
Properties rawConnectionProps = removeNamespaces(getHelper().getProperties(modelResource, CONNECTION_NAMESPACE));
Properties connectionProps = new Properties();

if (rawConnectionProps.get(SOURCE_ENDPOINT) != null) {
connectionProps.put(DS_ENDPOINT, rawConnectionProps.get(SOURCE_ENDPOINT));
if (rawConnectionProps.get(WSDL_URI_PROP_ID) != null) {
connectionProps.put(DS_ENDPOINT, rawConnectionProps.get(WSDL_URI_PROP_ID));
}

if (rawConnectionProps.get(END_POINT_URI_PROP_ID) != null) {
connectionProps.put(END_POINT_URI_PROP_ID, rawConnectionProps.get(END_POINT_URI_PROP_ID));
}

// Security
addSecurityProperties(rawConnectionProps, connectionProps, false);

return connectionProps;
}
Expand All @@ -97,14 +150,15 @@ public Properties getConnectionProperties( ModelResource modelResource ) throws
@Override
public Properties getTeiidRelatedProperties( IConnectionProfile connectionProfile ) {
Properties connectionProps = new Properties();
// connectionProps.put(IConnectionInfoHelper.PROFILE_PROVIDER_ID_KEY, connectionProfile.getProviderId());

Properties props = connectionProfile.getBaseProperties();
if (props.get(DS_ENDPOINT) != null) {
connectionProps.put(SOURCE_ENDPOINT, props.get(DS_ENDPOINT));
} else if (props.get(SOURCE_ENDPOINT) != null) {
connectionProps.put(SOURCE_ENDPOINT, props.get(SOURCE_ENDPOINT));
Properties profileProperties = connectionProfile.getBaseProperties();

String endPointProperty = ConnectionInfoHelper.readEndPointProperty(profileProperties);
if (endPointProperty != null) {
connectionProps.put(END_POINT_URI_PROP_ID, endPointProperty);
}

// Security
addSecurityProperties(profileProperties, connectionProps, false);

return connectionProps;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public interface ICredentialsCommon {

enum SecurityType {
None,
HTTPBasic
HTTPBasic;

/*
* Disabled since it is not currently
Expand All @@ -33,5 +33,23 @@ enum SecurityType {
* method of the class PropertyPage.
*/
// WSSecurity

/**
* Safely return one of the enum values for the given string.
* If the given string is not one of the enums then return
* the enum {@link #None}.
*
* @param securityType
* @return one of the enums, {@link #None} by default.
*/
public static SecurityType retrieveValue(String securityType) {
for (SecurityType type : SecurityType.values()) {
if (type.name().equals(securityType)) {
return type;
}
}

return SecurityType.None;
}
}
}

0 comments on commit 0ff543b

Please sign in to comment.