use of org.wso2.carbon.identity.api.server.idp.v1.model.OutboundConnector in project identity-api-server by wso2.
the class ServerIdpManagementService method getOutboundConnector.
/**
* Get specific outbound provisioning connector of an Identity Provider.
*
* @param idpId Identity Provider resource ID.
* @param connectorId Outbound provisioning connector ID.
* @return OutboundConnector.
*/
public OutboundConnector getOutboundConnector(String idpId, String connectorId) {
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);
}
ProvisioningConnectorConfig[] connectorConfigs = idp.getProvisioningConnectorConfigs();
if (connectorConfigs != null) {
for (ProvisioningConnectorConfig config : connectorConfigs) {
if (StringUtils.equals(config.getName(), base64URLDecode(connectorId))) {
return createOutboundConnector(connectorId, idp);
}
}
}
throw handleException(Response.Status.NOT_FOUND, Constants.ErrorMessage.ERROR_CODE_CONNECTOR_NOT_FOUND_FOR_IDP, connectorId);
} catch (IdentityProviderManagementException e) {
throw handleIdPException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_IDP_CONNECTOR, connectorId);
}
}
use of org.wso2.carbon.identity.api.server.idp.v1.model.OutboundConnector in project identity-api-server by wso2.
the class ServerIdpManagementService method createOutboundConnector.
/**
* Create external OutboundConnector from Provisioning Config.
*
* @param connectorId Outbound provisioning connector resource ID.
* @param identityProvider Identity Provider information.
* @return External outbound connector.
*/
private OutboundConnector createOutboundConnector(String connectorId, IdentityProvider identityProvider) {
ProvisioningConnectorConfig[] connectorConfigs = identityProvider.getProvisioningConnectorConfigs();
if (ArrayUtils.isEmpty(connectorConfigs)) {
return null;
}
ProvisioningConnectorConfig config = null;
boolean isDefaultConnector = false;
String connectorName = base64URLDecode(connectorId);
for (ProvisioningConnectorConfig connectorConfig : connectorConfigs) {
if (StringUtils.equals(connectorConfig.getName(), connectorName)) {
config = connectorConfig;
}
}
if (identityProvider.getDefaultProvisioningConnectorConfig() != null && StringUtils.equals(identityProvider.getDefaultProvisioningConnectorConfig().getName(), connectorName)) {
isDefaultConnector = true;
}
OutboundConnector outboundConnector = null;
if (config != null) {
outboundConnector = new OutboundConnector();
outboundConnector.setConnectorId(connectorId);
outboundConnector.setName(config.getName());
outboundConnector.setIsEnabled(config.isEnabled());
outboundConnector.setIsDefault(isDefaultConnector);
outboundConnector.setBlockingEnabled(config.isBlocking());
outboundConnector.setRulesEnabled(config.isRulesEnabled());
List<org.wso2.carbon.identity.api.server.idp.v1.model.Property> properties = Arrays.stream(config.getProvisioningProperties()).map(propertyToExternal).collect(Collectors.toList());
outboundConnector.setProperties(properties);
}
return outboundConnector;
}
use of org.wso2.carbon.identity.api.server.idp.v1.model.OutboundConnector in project identity-api-server by wso2.
the class ServerIdpManagementService method updateOutboundConnectorConfig.
private void updateOutboundConnectorConfig(IdentityProvider idp, OutboundProvisioningRequest outboundProvisioningRequest) {
if (outboundProvisioningRequest != null) {
List<OutboundConnector> outboundConnectors = outboundProvisioningRequest.getConnectors();
String defaultConnectorId = outboundProvisioningRequest.getDefaultConnectorId();
ProvisioningConnectorConfig defaultConnectorConfig = null;
List<ProvisioningConnectorConfig> connectorConfigs = new ArrayList<>();
for (OutboundConnector connector : outboundConnectors) {
ProvisioningConnectorConfig connectorConfig = new ProvisioningConnectorConfig();
connectorConfig.setName(base64URLDecode(connector.getConnectorId()));
connectorConfig.setEnabled(connector.getIsEnabled());
List<org.wso2.carbon.identity.api.server.idp.v1.model.Property> connectorProperties = connector.getProperties();
if (connectorProperties != null) {
if (!areAllDistinct(connectorProperties)) {
throw handleException(Response.Status.BAD_REQUEST, Constants.ErrorMessage.ERROR_CODE_INVALID_INPUT, " Duplicate properties are found in " + "the request.");
}
List<Property> properties = connectorProperties.stream().map(propertyToInternal).collect(Collectors.toList());
connectorConfig.setProvisioningProperties(properties.toArray(new Property[0]));
}
connectorConfigs.add(connectorConfig);
if (StringUtils.equals(defaultConnectorId, connector.getConnectorId())) {
defaultConnectorConfig = connectorConfig;
}
}
if (StringUtils.isNotBlank(defaultConnectorId) && defaultConnectorConfig == null) {
throw handleException(Response.Status.BAD_REQUEST, Constants.ErrorMessage.ERROR_CODE_INVALID_DEFAULT_OUTBOUND_CONNECTOR, null);
}
idp.setProvisioningConnectorConfigs(connectorConfigs.toArray(new ProvisioningConnectorConfig[0]));
idp.setDefaultProvisioningConnectorConfig(defaultConnectorConfig);
}
}
use of org.wso2.carbon.identity.api.server.idp.v1.model.OutboundConnector 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