Search in sources :

Example 61 with ProvisioningConnectorConfig

use of org.wso2.carbon.identity.application.common.model.xsd.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);
    }
}
Also used : ArrayList(java.util.ArrayList) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException) ProvisioningConnectorConfig(org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)

Aggregations

ProvisioningConnectorConfig (org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)39 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)19 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)19 Property (org.wso2.carbon.identity.application.common.model.Property)19 ArrayList (java.util.ArrayList)17 IdentityProviderManagementException (org.wso2.carbon.idp.mgt.IdentityProviderManagementException)14 ClaimConfig (org.wso2.carbon.identity.application.common.model.ClaimConfig)10 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)10 ProvisioningConnectorConfig (org.wso2.carbon.identity.application.common.model.idp.xsd.ProvisioningConnectorConfig)10 PreparedStatement (java.sql.PreparedStatement)9 Property (org.wso2.carbon.identity.application.common.model.idp.xsd.Property)9 Test (org.testng.annotations.Test)8 Claim (org.wso2.carbon.identity.application.common.model.Claim)7 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)7 LocalRole (org.wso2.carbon.identity.application.common.model.LocalRole)7 PermissionsAndRoleConfig (org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig)7 RoleMapping (org.wso2.carbon.identity.application.common.model.RoleMapping)7 ResultSet (java.sql.ResultSet)6 HashMap (java.util.HashMap)6 JustInTimeProvisioningConfig (org.wso2.carbon.identity.application.common.model.JustInTimeProvisioningConfig)6