use of org.wso2.carbon.user.api.Property in project carbon-identity-framework by wso2.
the class IdentityProviderManager method buildSAMLProperties.
private FederatedAuthenticatorConfig buildSAMLProperties(IdentityProvider identityProvider, String tenantDomain) throws IdentityProviderManagementException {
String samlSSOUrl = buildSAMLUrl(IdentityUtil.getProperty(IdentityConstants.ServerConfig.SSO_IDP_URL), tenantDomain, IdPManagementConstants.SAMLSSO, true);
String samlLogoutUrl = buildSAMLUrl(IdentityUtil.getProperty(IdentityConstants.ServerConfig.SSO_IDP_URL), tenantDomain, IdPManagementConstants.SAMLSSO, true);
String samlECPUrl = buildSAMLUrl(IdentityUtil.getProperty(IdentityConstants.ServerConfig.SAML_ECP_URL), tenantDomain, IdPManagementConstants.SAML_ECP_URL, true);
String samlArtifactUrl = buildSAMLUrl(IdentityUtil.getProperty(IdentityConstants.ServerConfig.SSO_ARTIFACT_URL), tenantDomain, IdPManagementConstants.SSO_ARTIFACT_URL, false);
FederatedAuthenticatorConfig samlFederatedAuthConfig = IdentityApplicationManagementUtil.getFederatedAuthenticator(identityProvider.getFederatedAuthenticatorConfigs(), IdentityApplicationConstants.Authenticator.SAML2SSO.NAME);
if (samlFederatedAuthConfig == null) {
samlFederatedAuthConfig = new FederatedAuthenticatorConfig();
samlFederatedAuthConfig.setName(IdentityApplicationConstants.Authenticator.SAML2SSO.NAME);
}
List<Property> propertiesList = new ArrayList<>();
Property samlSSOUrlProperty = resolveFedAuthnProperty(samlSSOUrl, samlFederatedAuthConfig, IdentityApplicationConstants.Authenticator.SAML2SSO.SSO_URL);
propertiesList.add(samlSSOUrlProperty);
Property samlLogoutUrlProperty = resolveFedAuthnProperty(samlLogoutUrl, samlFederatedAuthConfig, IdentityApplicationConstants.Authenticator.SAML2SSO.LOGOUT_REQ_URL);
propertiesList.add(samlLogoutUrlProperty);
Property samlECPUrlProperty = resolveFedAuthnProperty(samlECPUrl, samlFederatedAuthConfig, IdentityApplicationConstants.Authenticator.SAML2SSO.ECP_URL);
propertiesList.add(samlECPUrlProperty);
Property samlArtifactUrlProperty = resolveFedAuthnProperty(samlArtifactUrl, samlFederatedAuthConfig, IdentityApplicationConstants.Authenticator.SAML2SSO.ARTIFACT_RESOLVE_URL);
propertiesList.add(samlArtifactUrlProperty);
Property idPEntityIdProperty = IdentityApplicationManagementUtil.getProperty(samlFederatedAuthConfig.getProperties(), IdentityApplicationConstants.Authenticator.SAML2SSO.IDP_ENTITY_ID);
if (idPEntityIdProperty == null) {
idPEntityIdProperty = new Property();
idPEntityIdProperty.setName(IdentityApplicationConstants.Authenticator.SAML2SSO.IDP_ENTITY_ID);
idPEntityIdProperty.setValue(IdPManagementUtil.getResidentIdPEntityId());
}
propertiesList.add(idPEntityIdProperty);
if (IdentityTenantUtil.isTenantQualifiedUrlsEnabled()) {
// Add SSO URL as a destination URL if not already available.
addSSOUrlAsDestinationUrl(samlFederatedAuthConfig, samlSSOUrl, propertiesList);
}
for (Property property : samlFederatedAuthConfig.getProperties()) {
if (property != null && !IdentityApplicationConstants.Authenticator.SAML2SSO.SSO_URL.equals(property.getName()) && !IdentityApplicationConstants.Authenticator.SAML2SSO.LOGOUT_REQ_URL.equals(property.getName()) && !IdentityApplicationConstants.Authenticator.SAML2SSO.ECP_URL.equals(property.getName()) && !IdentityApplicationConstants.Authenticator.SAML2SSO.IDP_ENTITY_ID.equals(property.getName())) {
propertiesList.add(property);
}
}
Property samlMetadataValidityPeriodProperty = IdentityApplicationManagementUtil.getProperty(samlFederatedAuthConfig.getProperties(), IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_VALIDITY_PERIOD);
if (samlMetadataValidityPeriodProperty == null) {
samlMetadataValidityPeriodProperty = new Property();
samlMetadataValidityPeriodProperty.setName(IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_VALIDITY_PERIOD);
samlMetadataValidityPeriodProperty.setValue(IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_VALIDITY_PERIOD_DEFAULT);
}
propertiesList.add(samlMetadataValidityPeriodProperty);
Property samlMetadataSigningEnabledProperty = IdentityApplicationManagementUtil.getProperty(samlFederatedAuthConfig.getProperties(), IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_SIGNING_ENABLED);
if (samlMetadataSigningEnabledProperty == null) {
samlMetadataSigningEnabledProperty = new Property();
samlMetadataSigningEnabledProperty.setName(IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_SIGNING_ENABLED);
samlMetadataSigningEnabledProperty.setValue(IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_SIGNING_ENABLED_DEFAULT);
}
propertiesList.add(samlMetadataSigningEnabledProperty);
Property samlAuthnRequestSigningProperty = IdentityApplicationManagementUtil.getProperty(samlFederatedAuthConfig.getProperties(), IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_AUTHN_REQUESTS_SIGNING_ENABLED);
if (samlAuthnRequestSigningProperty == null) {
samlAuthnRequestSigningProperty = new Property();
samlAuthnRequestSigningProperty.setName(IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_AUTHN_REQUESTS_SIGNING_ENABLED);
samlAuthnRequestSigningProperty.setValue(IdentityApplicationConstants.Authenticator.SAML2SSO.SAML_METADATA_AUTHN_REQUESTS_SIGNING_DEFAULT);
}
propertiesList.add(samlAuthnRequestSigningProperty);
samlFederatedAuthConfig.setProperties(propertiesList.toArray(new Property[propertiesList.size()]));
return samlFederatedAuthConfig;
}
use of org.wso2.carbon.user.api.Property in project carbon-identity-framework by wso2.
the class IdentityProviderManager method handleMetadata.
/**
* If metadata file is available, creates a new FederatedAuthenticatorConfig from that
*
* @param identityProvider
* @throws IdentityProviderManagementException
*/
private void handleMetadata(int tenantId, IdentityProvider identityProvider) throws IdentityProviderManagementException {
if (IdpMgtServiceComponentHolder.getInstance().getMetadataConverters().isEmpty()) {
throw new IdentityProviderManagementException("Metadata Converter is not set");
}
FederatedAuthenticatorConfig[] federatedAuthenticatorConfigs = identityProvider.getFederatedAuthenticatorConfigs();
for (FederatedAuthenticatorConfig federatedAuthenticatorConfig : federatedAuthenticatorConfigs) {
Property[] properties = federatedAuthenticatorConfig.getProperties();
if (ArrayUtils.isNotEmpty(properties)) {
for (Property property : properties) {
if (property != null) {
if (StringUtils.isNotBlank(property.getName()) && property.getName().contains(IdPManagementConstants.META_DATA)) {
for (MetadataConverter metadataConverter : IdpMgtServiceComponentHolder.getInstance().getMetadataConverters()) {
if (metadataConverter.canHandle(property)) {
try {
if (isMetadataFileExist(identityProvider.getIdentityProviderName(), property.getValue())) {
try {
metadataConverter.saveMetadataString(tenantId, identityProvider.getIdentityProviderName(), federatedAuthenticatorConfig.getName(), property.getValue());
} catch (IdentityProviderManagementException e) {
String data = "Couldn't save metadata in registry.SAML2SSOMetadataConverter" + " is not set. ";
throw IdPManagementUtil.handleServerException(IdPManagementConstants.ErrorMessage.ERROR_CODE_ADD_IDP, data);
}
}
StringBuilder certificate = new StringBuilder();
try {
FederatedAuthenticatorConfig metaFederated = metadataConverter.getFederatedAuthenticatorConfig(properties, certificate);
String spName = "";
for (Property value : properties) {
if (value != null && IdentityApplicationConstants.Authenticator.SAML2SSO.SP_ENTITY_ID.equals(value.getName())) {
spName = value.getValue();
}
}
if (spName.equals("")) {
throw new IdentityProviderManagementException("SP name can't be empty");
}
if (metaFederated != null && ArrayUtils.isNotEmpty(metaFederated.getProperties())) {
for (int y = 0; y < metaFederated.getProperties().length; y++) {
if (metaFederated.getProperties()[y] != null && IdentityApplicationConstants.Authenticator.SAML2SSO.SP_ENTITY_ID.equals(metaFederated.getProperties()[y].getName())) {
metaFederated.getProperties()[y].setValue(spName);
break;
}
}
}
if (metaFederated != null && ArrayUtils.isNotEmpty(metaFederated.getProperties())) {
federatedAuthenticatorConfig.setProperties(metaFederated.getProperties());
} else {
throw new IdentityProviderManagementException("Error setting metadata using file");
}
} catch (IdentityProviderManagementException ex) {
throw new IdentityProviderManagementException("Error converting metadata", ex);
}
if (certificate.toString().length() > 0) {
identityProvider.setCertificate(certificate.toString());
}
} catch (XMLStreamException e) {
throw new IdentityProviderManagementException("Error while configuring metadata", e);
}
break;
}
}
}
}
}
}
}
}
use of org.wso2.carbon.user.api.Property in project carbon-identity-framework by wso2.
the class FileBasedIdPMgtDAO method getIdPByAuthenticatorPropertyValue.
public IdentityProvider getIdPByAuthenticatorPropertyValue(String property, String value, String tenantDomain, String authenticatorName) {
Map<String, IdentityProvider> identityProviders = IdPManagementServiceComponent.getFileBasedIdPs();
for (Entry<String, IdentityProvider> entry : identityProviders.entrySet()) {
FederatedAuthenticatorConfig[] federatedAuthenticatorConfigs = entry.getValue().getFederatedAuthenticatorConfigs();
// Get SAML2 Web SSO authenticator
FederatedAuthenticatorConfig samlAuthenticatorConfig = IdentityApplicationManagementUtil.getFederatedAuthenticator(federatedAuthenticatorConfigs, authenticatorName);
if (samlAuthenticatorConfig != null) {
Property samlProperty = IdentityApplicationManagementUtil.getProperty(samlAuthenticatorConfig.getProperties(), property);
if (samlProperty != null) {
if (value.equalsIgnoreCase(samlProperty.getValue())) {
return entry.getValue();
}
}
}
}
return null;
}
use of org.wso2.carbon.user.api.Property in project carbon-identity-framework by wso2.
the class IdPManagementDAO method buildTemplateIdProperty.
/**
* Build templateId property for the IDP.
*
* @param identityProvider Identity provider.
* @return templateId IdentityProviderProperty.
*/
private IdentityProviderProperty buildTemplateIdProperty(IdentityProvider identityProvider) {
IdentityProviderProperty templateIdProperty = new IdentityProviderProperty();
templateIdProperty.setName(TEMPLATE_ID_IDP_PROPERTY_NAME);
templateIdProperty.setDisplayName(TEMPLATE_ID_IDP_PROPERTY_DISPLAY_NAME);
templateIdProperty.setValue(StringUtils.isNotBlank(identityProvider.getTemplateId()) ? identityProvider.getTemplateId() : StringUtils.EMPTY);
return templateIdProperty;
}
use of org.wso2.carbon.user.api.Property in project carbon-identity-framework by wso2.
the class IdPManagementDAO method updateProvisioningConfigProperty.
private void updateProvisioningConfigProperty(ProvisioningConnectorConfig[] provisioningConnectors, Connection dbConnection, int idpId, int tenantId) throws IdentityProviderManagementException, SQLException {
String sqlStmt = IdPManagementConstants.SQLQueries.UPDATE_IDP_PROVISIONING_CONFIG_PROPERTY_SQL;
try (PreparedStatement prepStmt = dbConnection.prepareStatement(sqlStmt)) {
for (ProvisioningConnectorConfig connector : provisioningConnectors) {
if (isProvisioningConfigAvailableToUpdate(connector, dbConnection, idpId, tenantId)) {
updateProvisioningConfig(connector, dbConnection, idpId, tenantId);
Property[] connectorProperties = connector.getProvisioningProperties();
if (connectorProperties != null && connectorProperties.length > 0) {
for (Property config : connectorProperties) {
if (config == null) {
continue;
}
prepStmt.setString(1, config.getName());
if (IdentityApplicationConstants.ConfigElements.PROPERTY_TYPE_BLOB.equals(config.getType())) {
prepStmt.setString(2, null);
setBlobValue(config.getValue(), prepStmt, 3);
prepStmt.setString(4, config.getType());
} else {
prepStmt.setString(2, config.getValue());
setBlobValue(null, prepStmt, 3);
prepStmt.setString(4, IdentityApplicationConstants.ConfigElements.PROPERTY_TYPE_STRING);
}
if (config.isConfidential()) {
prepStmt.setString(5, IdPManagementConstants.IS_TRUE_VALUE);
} else {
prepStmt.setString(5, IdPManagementConstants.IS_FALSE_VALUE);
}
prepStmt.setInt(6, idpId);
prepStmt.setInt(7, tenantId);
prepStmt.setString(8, connector.getName());
prepStmt.setInt(9, tenantId);
prepStmt.setString(10, config.getName());
prepStmt.executeUpdate();
}
}
} else {
addProvisioningConnectorConfigs(new ProvisioningConnectorConfig[] { connector }, dbConnection, idpId, tenantId);
}
}
} catch (IOException e) {
throw new IdentityProviderManagementException("An error occurred when processing content stream while " + "updating provisioning config properties of Identity Provider : " + idpId, e);
}
}
Aggregations