use of org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig in project identity-api-server by wso2.
the class ServerIdpManagementService method updateOutboundConnector.
/**
* Update outbound provisioning connector config.
*
* @param idpId Identity Provider resource ID.
* @param connectorId Outbound provisioning connector ID.
* @param outboundConnector New Outbound Connector information.
* @return OutboundConnector OutboundConnector response.
*/
public OutboundConnector updateOutboundConnector(String idpId, String connectorId, OutboundConnectorPUTRequest outboundConnector) {
try {
IdentityProvider idp = IdentityProviderServiceHolder.getIdentityProviderManager().getIdPByResourceId(idpId, ContextLoader.getTenantDomainFromContext(), true);
if (idp == null) {
throw handleException(Response.Status.NOT_FOUND, Constants.ErrorMessage.ERROR_CODE_IDP_NOT_FOUND, idpId);
}
IdentityProvider idpToUpdate = createIdPClone(idp);
ProvisioningConnectorConfig connectorConfig = createProvisioningConnectorConfig(connectorId, outboundConnector);
ProvisioningConnectorConfig[] provConnectorConfigs = createProvisioningConnectorArrayClone(connectorId, idp.getProvisioningConnectorConfigs());
int configPos = getExistingProvConfigPosition(provConnectorConfigs, connectorId);
if (configPos != -1) {
provConnectorConfigs[configPos] = connectorConfig;
} else {
// if configPos is -1 add new authenticator to the list.
if (isValidConnector(connectorId)) {
List<ProvisioningConnectorConfig> connectorConfigsList = new ArrayList<>(Arrays.asList(provConnectorConfigs));
connectorConfigsList.add(connectorConfig);
provConnectorConfigs = connectorConfigsList.toArray(new ProvisioningConnectorConfig[0]);
} else {
throw handleException(Response.Status.NOT_FOUND, Constants.ErrorMessage.ERROR_CODE_CONNECTOR_NOT_FOUND_FOR_IDP, connectorId);
}
}
idpToUpdate.setProvisioningConnectorConfigs(provConnectorConfigs);
if (outboundConnector.getIsDefault()) {
idpToUpdate.setDefaultProvisioningConnectorConfig(connectorConfig);
} else if (idpToUpdate.getDefaultProvisioningConnectorConfig() != null && idpToUpdate.getDefaultProvisioningConnectorConfig().getName().equals(connectorConfig.getName())) {
idpToUpdate.setDefaultProvisioningConnectorConfig(null);
}
IdentityProvider updatedIdP = IdentityProviderServiceHolder.getIdentityProviderManager().updateIdPByResourceId(idpId, idpToUpdate, ContextLoader.getTenantDomainFromContext());
return createOutboundConnector(connectorId, updatedIdP);
} catch (IdentityProviderManagementException e) {
throw handleIdPException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_UPDATING_IDP_CONNECTOR, connectorId);
}
}
Aggregations