use of org.wso2.carbon.identity.application.common.model.xsd.ProvisioningConnectorConfig in project carbon-identity-framework by wso2.
the class IdPManagementDAO method addProvisioningConnectorConfigs.
/**
* @param provisioningConnectors
* @param dbConnection
* @param idpId
* @throws IdentityProviderManagementException
* @throws SQLException
*/
private void addProvisioningConnectorConfigs(ProvisioningConnectorConfig[] provisioningConnectors, Connection dbConnection, int idpId, int tenantId) throws IdentityProviderManagementException, SQLException {
PreparedStatement prepStmt = null;
PreparedStatement prepBaseStmt = null;
ResultSet rs = null;
try {
// SP_IDP_ID,SP_IDP_PROV_CONNECTOR_TYPE, SP_IDP_PROV_CONFIG_KEY,
// SP_IDP_PROV_CONFIG_VALUE, SP_IDP_PROV_CONFIG_IS_SECRET
// SP_IDP_PROV_CONFIG_PROPERTY
// TENANT_ID, PROVISIONING_CONFIG_ID, PROPERTY_KEY, PROPERTY_VALUE, PROPERTY_TYPE,
// IS_SECRET
String sqlStmt = IdPManagementConstants.SQLQueries.ADD_IDP_PROVISIONING_PROPERTY_SQL;
prepStmt = dbConnection.prepareStatement(sqlStmt);
String sqlBaseStmt = IdPManagementConstants.SQLQueries.ADD_IDP_PROVISIONING_CONFIG_SQL;
String dbProductName = dbConnection.getMetaData().getDatabaseProductName();
prepBaseStmt = dbConnection.prepareStatement(sqlBaseStmt, new String[] { DBUtils.getConvertedAutoGeneratedColumnName(dbProductName, "ID") });
if (provisioningConnectors != null) {
for (ProvisioningConnectorConfig connector : provisioningConnectors) {
Property[] connctorProperties = connector.getProvisioningProperties();
if (connctorProperties != null) {
// SP_IDP_PROVISIONING_CONFIG
// TENANT_ID, IDP_ID, PROVISIONING_CONNECTOR_TYPE, IS_ENABLED, IS_DEFAULT
prepBaseStmt.setInt(1, tenantId);
prepBaseStmt.setInt(2, idpId);
prepBaseStmt.setString(3, connector.getName());
if (connector.isEnabled()) {
prepBaseStmt.setString(4, IdPManagementConstants.IS_TRUE_VALUE);
} else {
prepBaseStmt.setString(4, IdPManagementConstants.IS_FALSE_VALUE);
}
if (connector.isBlocking()) {
prepBaseStmt.setString(5, IdPManagementConstants.IS_TRUE_VALUE);
} else {
prepBaseStmt.setString(5, IdPManagementConstants.IS_FALSE_VALUE);
}
prepBaseStmt.executeUpdate();
rs = prepBaseStmt.getGeneratedKeys();
if (rs.next()) {
int provisioningConfigID = rs.getInt(1);
if (connctorProperties.length > 0) {
for (Property config : connctorProperties) {
if (config == null) {
continue;
}
// SP_IDP_PROV_CONFIG_PROPERTY
// TENANT_ID, PROVISIONING_CONFIG_ID, PROPERTY_KEY,
// PROPERTY_VALUE, PROPERTY_BLOB_VALUE, PROPERTY_TYPE, IS_SECRET
prepStmt.setInt(1, tenantId);
prepStmt.setInt(2, provisioningConfigID);
prepStmt.setString(3, config.getName());
// TODO : Sect property type accordingly
if (IdentityApplicationConstants.ConfigElements.PROPERTY_TYPE_BLOB.equals(config.getType())) {
prepStmt.setString(4, null);
setBlobValue(config.getValue(), prepStmt, 5);
prepStmt.setString(6, config.getType());
} else {
prepStmt.setString(4, config.getValue());
setBlobValue(null, prepStmt, 5);
prepStmt.setString(6, IdentityApplicationConstants.ConfigElements.PROPERTY_TYPE_STRING);
}
if (config.isConfidential()) {
prepStmt.setString(7, IdPManagementConstants.IS_TRUE_VALUE);
} else {
prepStmt.setString(7, IdPManagementConstants.IS_FALSE_VALUE);
}
prepStmt.addBatch();
}
}
}
// Adding properties for base config
prepStmt.executeBatch();
}
}
}
} catch (IOException e) {
throw new IdentityProviderManagementException("An error occurred while processing content stream.", e);
} finally {
IdentityDatabaseUtil.closeAllConnections(null, rs, prepStmt);
IdentityDatabaseUtil.closeStatement(prepBaseStmt);
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.ProvisioningConnectorConfig in project carbon-identity-framework by wso2.
the class IdentityProviderManagementServiceTest method testGetAllProvisioningConnectors.
@Test
public void testGetAllProvisioningConnectors() throws Exception {
ProvisioningConnectorConfig[] allProvisioningConnectors = identityProviderManagementService.getAllProvisioningConnectors();
Assert.assertNull(allProvisioningConnectors);
ProvisioningConnectorConfig provisioningConnectorConfig1 = mock(ProvisioningConnectorConfig.class);
provisioningConnectorConfig1.setName("ProvisiningConfig1");
ProvisioningConnectorConfig provisioningConnectorConfig2 = mock(ProvisioningConnectorConfig.class);
provisioningConnectorConfig2.setName("ProvisiningConfig2");
provisioningConnectorConfig2.setEnabled(true);
provisioningConnectorConfig2.setBlocking(true);
ProvisioningConnectorService.getInstance().addProvisioningConnectorConfigs(provisioningConnectorConfig1);
allProvisioningConnectors = identityProviderManagementService.getAllProvisioningConnectors();
Assert.assertEquals(allProvisioningConnectors.length, 1);
ProvisioningConnectorService.getInstance().addProvisioningConnectorConfigs(provisioningConnectorConfig2);
allProvisioningConnectors = identityProviderManagementService.getAllProvisioningConnectors();
Assert.assertEquals(allProvisioningConnectors.length, 2);
// Clear after the test.
ProvisioningConnectorService.getInstance().removeProvisioningConnectorConfigs(provisioningConnectorConfig1);
ProvisioningConnectorService.getInstance().removeProvisioningConnectorConfigs(provisioningConnectorConfig2);
allProvisioningConnectors = identityProviderManagementService.getAllProvisioningConnectors();
Assert.assertNull(allProvisioningConnectors);
}
use of org.wso2.carbon.identity.application.common.model.xsd.ProvisioningConnectorConfig in project carbon-identity-framework by wso2.
the class IdentityProviderManagementServiceTest method updateIdPData.
@DataProvider
public Object[][] updateIdPData() {
// Initialize New Test Identity Provider 1.
IdentityProvider idp1New = new IdentityProvider();
idp1New.setIdentityProviderName("testIdP1New");
idp1New.setEnable(true);
idp1New.setPrimary(true);
idp1New.setFederationHub(true);
idp1New.setCertificate("");
RoleMapping newRoleMapping1 = new RoleMapping();
newRoleMapping1.setRemoteRole("Role1New");
newRoleMapping1.setLocalRole(new LocalRole("1", "LocalRole1"));
RoleMapping newRoleMapping2 = new RoleMapping();
newRoleMapping2.setRemoteRole("Role2New");
newRoleMapping2.setLocalRole(new LocalRole("2", "LocalRole2"));
PermissionsAndRoleConfig newPermissionsAndRoleConfig = new PermissionsAndRoleConfig();
newPermissionsAndRoleConfig.setIdpRoles(new String[] { "Role1New", "Role2New" });
newPermissionsAndRoleConfig.setRoleMappings(new RoleMapping[] { newRoleMapping1, newRoleMapping2 });
idp1New.setPermissionAndRoleConfig(newPermissionsAndRoleConfig);
FederatedAuthenticatorConfig newFederatedAuthenticatorConfig = new FederatedAuthenticatorConfig();
newFederatedAuthenticatorConfig.setDisplayName("DisplayName1New");
newFederatedAuthenticatorConfig.setName("Name");
newFederatedAuthenticatorConfig.setEnabled(true);
Property newProperty1 = new Property();
newProperty1.setName("Property1New");
newProperty1.setValue("value1New");
newProperty1.setConfidential(false);
Property newProperty2 = new Property();
newProperty2.setName("Property2New");
newProperty2.setValue("value2New");
newProperty2.setConfidential(false);
newFederatedAuthenticatorConfig.setProperties(new Property[] { newProperty1, newProperty2 });
idp1New.setFederatedAuthenticatorConfigs(new FederatedAuthenticatorConfig[] { newFederatedAuthenticatorConfig });
ProvisioningConnectorConfig newProvisioningConnectorConfig1 = new ProvisioningConnectorConfig();
newProvisioningConnectorConfig1.setName("ProvisiningConfig1");
newProvisioningConnectorConfig1.setProvisioningProperties(new Property[] { newProperty1 });
ProvisioningConnectorConfig newProvisioningConnectorConfig2 = new ProvisioningConnectorConfig();
newProvisioningConnectorConfig2.setName("ProvisiningConfig2");
newProvisioningConnectorConfig2.setProvisioningProperties(new Property[] { newProperty2 });
newProvisioningConnectorConfig2.setEnabled(true);
newProvisioningConnectorConfig2.setBlocking(true);
idp1New.setProvisioningConnectorConfigs(new ProvisioningConnectorConfig[] { newProvisioningConnectorConfig1, newProvisioningConnectorConfig2 });
ClaimConfig newClaimConfig = new ClaimConfig();
newClaimConfig.setLocalClaimDialect(false);
newClaimConfig.setRoleClaimURI("Country");
newClaimConfig.setUserClaimURI("Country");
ClaimMapping claimMapping = ClaimMapping.build("http://wso2.org/claims/country", "Country", "", true);
Claim remoteClaim = new Claim();
remoteClaim.setClaimId(0);
remoteClaim.setClaimUri("Country");
newClaimConfig.setClaimMappings(new ClaimMapping[] { claimMapping });
newClaimConfig.setIdpClaims(new Claim[] { remoteClaim });
idp1New.setClaimConfig(newClaimConfig);
// Initialize New Test Identity Provider 2.
IdentityProvider idp2New = new IdentityProvider();
idp2New.setIdentityProviderName("testIdP2New");
// Initialize New Test Identity Provider 3.
IdentityProvider idp3New = new IdentityProvider();
idp3New.setIdentityProviderName("testIdP3New");
return new Object[][] { // IDP with PermissionsAndRoleConfig,FederatedAuthenticatorConfig,ProvisioningConnectorConfig,ClaimConf.
{ "testIdP1", idp1New }, // New IDP with Only name.
{ "testIdP2", idp2New }, // New IDP with Only name.
{ "testIdP3", idp3New } };
}
use of org.wso2.carbon.identity.application.common.model.xsd.ProvisioningConnectorConfig in project carbon-identity-framework by wso2.
the class IdentityProviderDAOImpl method getIdentityProvider.
@Override
public /**
*/
IdentityProvider getIdentityProvider(String idpName) throws IdentityApplicationManagementException {
IdentityProviderManager idpManager = IdentityProviderManager.getInstance();
try {
IdentityProvider idp = idpManager.getIdPByName(idpName, CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
IdentityProvider identityProvider = new IdentityProvider();
identityProvider.setIdentityProviderName(idp.getIdentityProviderName());
FederatedAuthenticatorConfig defaultAuthenticator = new FederatedAuthenticatorConfig();
defaultAuthenticator.setName(getDefaultAuthenticator(idp.getIdentityProviderName()));
List<FederatedAuthenticatorConfig> federatedAuthenticators = new ArrayList<FederatedAuthenticatorConfig>();
FederatedAuthenticatorConfig[] federatedAuthenticatorConfigs = idp.getFederatedAuthenticatorConfigs();
if (federatedAuthenticatorConfigs != null && federatedAuthenticatorConfigs.length > 0) {
for (FederatedAuthenticatorConfig config : federatedAuthenticatorConfigs) {
if (config.isEnabled()) {
federatedAuthenticators.add(config);
}
}
}
if (CollectionUtils.isNotEmpty(federatedAuthenticators)) {
identityProvider.setFederatedAuthenticatorConfigs(federatedAuthenticators.toArray(new FederatedAuthenticatorConfig[federatedAuthenticators.size()]));
}
List<ProvisioningConnectorConfig> provisioningConnectors = new ArrayList<ProvisioningConnectorConfig>();
ProvisioningConnectorConfig[] provisioningConnectorConfigs = idp.getProvisioningConnectorConfigs();
if (provisioningConnectorConfigs != null && provisioningConnectorConfigs.length > 0) {
for (ProvisioningConnectorConfig config : provisioningConnectorConfigs) {
if (config.isEnabled()) {
provisioningConnectors.add(config);
}
}
}
if (CollectionUtils.isNotEmpty(provisioningConnectors)) {
identityProvider.setProvisioningConnectorConfigs(provisioningConnectors.toArray(new ProvisioningConnectorConfig[provisioningConnectors.size()]));
}
identityProvider.setEnable(idp.isEnable());
return identityProvider;
} catch (IdentityProviderManagementException e) {
throw new IdentityApplicationManagementException("Error when retrieving identity provider " + idpName, e);
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.ProvisioningConnectorConfig in project carbon-identity-framework by wso2.
the class IdPManagementUIUtil method buildSCIMProvisioningConfiguration.
/**
* @param fedIdp
* @param paramMap
* @throws IdentityApplicationManagementException
*/
private static void buildSCIMProvisioningConfiguration(IdentityProvider fedIdp, Map<String, String> paramMap) throws IdentityApplicationManagementException {
ProvisioningConnectorConfig proConnector = new ProvisioningConnectorConfig();
proConnector.setName("scim");
Property userNameProp = null;
Property passwordProp = null;
Property userEpProp = null;
Property groupEpProp = null;
Property scimUserStoreDomain = null;
Property scimEnablePwdProvisioning = null;
Property defaultPwdProp = null;
Property uniqueID = null;
if (paramMap.get("scimProvEnabled") != null && "on".equals(paramMap.get("scimProvEnabled"))) {
proConnector.setEnabled(true);
} else {
proConnector.setEnabled(false);
}
if (paramMap.get("scimProvDefault") != null && "on".equals(paramMap.get("scimProvDefault"))) {
fedIdp.setDefaultProvisioningConnectorConfig(proConnector);
}
if (paramMap.get("scim-username") != null) {
userNameProp = new Property();
userNameProp.setName("scim-username");
userNameProp.setValue(paramMap.get("scim-username"));
}
if (paramMap.get("scim-password") != null) {
passwordProp = new Property();
passwordProp.setConfidential(true);
passwordProp.setName("scim-password");
passwordProp.setValue(paramMap.get("scim-password"));
}
if (paramMap.get("scim-user-ep") != null) {
userEpProp = new Property();
userEpProp.setName("scim-user-ep");
userEpProp.setValue(paramMap.get("scim-user-ep"));
}
if (paramMap.get("scim-group-ep") != null) {
groupEpProp = new Property();
groupEpProp.setName("scim-group-ep");
groupEpProp.setValue(paramMap.get("scim-group-ep"));
}
if (paramMap.get("scim-user-store-domain") != null) {
scimUserStoreDomain = new Property();
scimUserStoreDomain.setName("scim-user-store-domain");
scimUserStoreDomain.setValue(paramMap.get("scim-user-store-domain"));
}
if (paramMap.get("scimPwdProvEnabled") != null && "on".equals(paramMap.get("scimPwdProvEnabled"))) {
scimEnablePwdProvisioning = new Property();
scimEnablePwdProvisioning.setName("scim-enable-pwd-provisioning");
scimEnablePwdProvisioning.setDefaultValue("false");
scimEnablePwdProvisioning.setValue("true");
}
if (paramMap.get("scim-default-pwd") != null) {
defaultPwdProp = new Property();
defaultPwdProp.setName("scim-default-pwd");
defaultPwdProp.setValue(paramMap.get("scim-default-pwd"));
}
if (paramMap.get("scim-unique-id") != null) {
uniqueID = new Property();
uniqueID.setName("UniqueID");
uniqueID.setValue(paramMap.get("scim-unique-id"));
}
Property[] proProperties = new Property[] { userNameProp, passwordProp, userEpProp, groupEpProp, scimUserStoreDomain, scimEnablePwdProvisioning, defaultPwdProp, uniqueID };
proConnector.setProvisioningProperties(proProperties);
ProvisioningConnectorConfig[] proConnectors = fedIdp.getProvisioningConnectorConfigs();
if (proConnector.getName() != null) {
if (proConnectors == null || proConnectors.length == 0) {
fedIdp.setProvisioningConnectorConfigs(new ProvisioningConnectorConfig[] { proConnector });
} else {
fedIdp.setProvisioningConnectorConfigs(concatArrays(new ProvisioningConnectorConfig[] { proConnector }, proConnectors));
}
}
}
Aggregations