List<MessageSecurityConfig> mscs = secService.getMessageSecurityConfig();
// Let's find the correct MessageSecurityConfig. As of now,
// there can be only two of them - one for SOAP and one for
// HttpServlet
MessageSecurityConfig msgSecCfg = null;
for (MessageSecurityConfig msc : mscs) {
if (msc.getAuthLayer().equals(authLayer)) {
msgSecCfg = msc;
}
}
// If there is message security config for this type of layer
// then, add a new provider config under it provided it is not duplicate
if (msgSecCfg != null) {
// check if there exists a provider config by the
// specified provider name; if so return failure.
List<ProviderConfig> pcs = msgSecCfg.getProviderConfig();
for (ProviderConfig pc : pcs) {
if (pc.getProviderId().equals(providerId)) {
report.setMessage(localStrings.getLocalString(
"create.message.security.provider.duplicatefound",
"Message security provider named {0} exists. " +
"Cannot add duplicate.", providerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
// No duplicate message security providers found. So add one.
try {
ConfigSupport.apply(new SingleConfigCode<MessageSecurityConfig>() {
public Object run(MessageSecurityConfig param)
throws PropertyVetoException, TransactionFailure {
ProviderConfig newPC = param.createChild(ProviderConfig.class);
populateProviderConfigElement(newPC);
param.getProviderConfig().add(newPC);
// Depending on the providerType of the new provider
// the isDefaultProvider=true results in creation of
// either default-provider attribute or
// default-client-provider or BOTH in the message
// security config object
if (isDefaultProvider) {
if (providerType.equals(SERVER) ||
providerType.equals(CLIENT_SERVER) )
param.setDefaultProvider(providerId);
if (providerType.equals(CLIENT) ||
providerType.equals(CLIENT_SERVER) )
param.setDefaultClientProvider(providerId);
}
return newPC;
}
}, msgSecCfg);
} catch(TransactionFailure e) {
report.setMessage(localStrings.getLocalString(
"create.message.security.provider.fail",
"Creation of message security provider named {0} failed",
providerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setFailureCause(e);
return;
}
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
report.setMessage(localStrings.getLocalString(
"create.message.security.provider.success",
"Creation of message security provider named {0} completed " +
"successfully", providerId));
}
// Now if there is NO message security config for this type of layer
// then, first add a message security config for the layer and then
// add a provider config under this message security config
else {
try {
ConfigSupport.apply(new SingleConfigCode<SecurityService>() {
public Object run(SecurityService param)
throws PropertyVetoException, TransactionFailure {
MessageSecurityConfig newMSC = param.createChild(MessageSecurityConfig.class);
newMSC.setAuthLayer(authLayer);
param.getMessageSecurityConfig().add(newMSC);
ProviderConfig newPC = newMSC.createChild(ProviderConfig.class);
populateProviderConfigElement(newPC);
newMSC.getProviderConfig().add(newPC);
// Depending on the providerType of the new provider
// the isDefaultProvider=true results in creation of
// either default-provider attribute or
// default-client-provider or BOTH in the message
// security config object
if (isDefaultProvider) {
if (providerType.equals(SERVER) ||
providerType.equals(CLIENT_SERVER) )
newMSC.setDefaultProvider(providerId);
if (providerType.equals(CLIENT) ||
providerType.equals(CLIENT_SERVER) )
newMSC.setDefaultClientProvider(providerId);
}
return newMSC;
}
}, secService);
} catch(TransactionFailure e) {