use of org.wso2.carbon.idp.mgt.IdentityProviderManager in project carbon-identity-framework by wso2.
the class JITProvisioningPostAuthenticationHandler method setIDPData.
/**
* Set the IDP releated data in the receipt service input.
*
* @param tenantDomain Tenant domain.
* @param receiptServiceInput Relevant receipt service input which the
* @throws PostAuthenticationFailedException Post Authentication Failed Exception.
*/
private void setIDPData(String tenantDomain, ReceiptServiceInput receiptServiceInput) throws PostAuthenticationFailedException {
String resideIdpDescription = "Resident IDP";
IdentityProviderManager idpManager = IdentityProviderManager.getInstance();
IdentityProvider residentIdP = null;
try {
residentIdP = idpManager.getResidentIdP(tenantDomain);
} catch (IdentityProviderManagementException e) {
handleExceptions(String.format(ErrorMessages.ERROR_WHILE_SETTING_IDP_DATA.getMessage(), tenantDomain), ErrorMessages.ERROR_WHILE_SETTING_IDP_DATA.getCode(), e);
}
if (residentIdP == null) {
throw new PostAuthenticationFailedException(ErrorMessages.ERROR_WHILE_SETTING_IDP_DATA_IDP_IS_NULL.getCode(), String.format(ErrorMessages.ERROR_WHILE_SETTING_IDP_DATA_IDP_IS_NULL.getMessage(), tenantDomain));
}
if (StringUtils.isEmpty(receiptServiceInput.getService())) {
if (log.isDebugEnabled()) {
log.debug("No service name found. Hence adding resident IDP home realm ID");
}
receiptServiceInput.setService(residentIdP.getHomeRealmId());
}
if (StringUtils.isEmpty(receiptServiceInput.getTenantDomain())) {
receiptServiceInput.setTenantDomain(tenantDomain);
}
if (StringUtils.isEmpty(receiptServiceInput.getSpDescription())) {
if (StringUtils.isNotEmpty(residentIdP.getIdentityProviderDescription())) {
receiptServiceInput.setSpDescription(residentIdP.getIdentityProviderDescription());
} else {
receiptServiceInput.setSpDescription(resideIdpDescription);
}
}
if (StringUtils.isEmpty(receiptServiceInput.getSpDisplayName())) {
if (StringUtils.isNotEmpty(residentIdP.getDisplayName())) {
receiptServiceInput.setSpDisplayName(residentIdP.getDisplayName());
} else {
receiptServiceInput.setSpDisplayName(resideIdpDescription);
}
}
}
use of org.wso2.carbon.idp.mgt.IdentityProviderManager in project carbon-identity-framework by wso2.
the class IdentityProviderDAOImpl method getAllIdentityProviders.
@Override
public /**
*/
List<IdentityProvider> getAllIdentityProviders() throws IdentityApplicationManagementException {
IdentityProviderManager idpManager = IdentityProviderManager.getInstance();
List<IdentityProvider> idps;
try {
idps = idpManager.getIdPs(CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
} catch (IdentityProviderManagementException e) {
throw new IdentityApplicationManagementException("Error when retrieving all identity providers in " + CarbonContext.getThreadLocalCarbonContext().getTenantDomain() + " tenant domain.", e);
}
List<IdentityProvider> federatedIdentityProviders = new ArrayList<IdentityProvider>();
if (idps != null && !idps.isEmpty()) {
for (IdentityProvider idp : idps) {
federatedIdentityProviders.add(getIdentityProvider(idp.getIdentityProviderName()));
}
}
return federatedIdentityProviders;
}
use of org.wso2.carbon.idp.mgt.IdentityProviderManager in project carbon-identity-framework by wso2.
the class ApplicationIdentityProviderMgtListener method doPostUpdateIdP.
@Override
public boolean doPostUpdateIdP(String oldIdPName, IdentityProvider identityProvider, String tenantDomain) throws IdentityProviderManagementException {
try {
IdentityProviderManager identityProviderManager = IdentityProviderManager.getInstance();
ConnectedAppsResult connectedApplications;
String updatedIdpId = identityProvider.getResourceId();
ApplicationDAO applicationDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
int offset = 0;
do {
connectedApplications = identityProviderManager.getConnectedApplications(updatedIdpId, null, offset, tenantDomain);
for (String appResourceId : connectedApplications.getApps()) {
ServiceProvider serviceProvider = applicationDAO.getApplicationByResourceId(appResourceId, tenantDomain);
applicationDAO.clearApplicationFromCache(serviceProvider, tenantDomain);
}
offset = connectedApplications.getOffSet() + connectedApplications.getLimit();
} while (connectedApplications.getTotalAppCount() > offset);
} catch (IdentityApplicationManagementException e) {
throw new IdentityProviderManagementException("Error while running post IDP update tasks.", e);
}
return true;
}
use of org.wso2.carbon.idp.mgt.IdentityProviderManager in project identity-governance by wso2-extensions.
the class IdentityGovernanceServiceImpl method getConfiguration.
@Override
public Property[] getConfiguration(String tenantDomain) throws IdentityGovernanceException {
IdpManager identityProviderManager = IdentityMgtServiceDataHolder.getInstance().getIdpManager();
IdentityProvider residentIdp = null;
try {
residentIdp = identityProviderManager.getResidentIdP(tenantDomain);
} catch (IdentityProviderManagementException e) {
String errorMsg = String.format("Error while retrieving resident Idp for %s tenant.", tenantDomain);
throw new IdentityGovernanceException(errorMsg, e);
}
IdentityProviderProperty[] identityMgtProperties = residentIdp.getIdpProperties();
Property[] configMap = new Property[identityMgtProperties.length];
int index = 0;
for (IdentityProviderProperty identityMgtProperty : identityMgtProperties) {
if (IdentityEventConstants.PropertyConfig.ALREADY_WRITTEN_PROPERTY_KEY.equals(identityMgtProperty.getName())) {
continue;
}
Property property = new Property();
property.setName(identityMgtProperty.getName());
property.setValue(identityMgtProperty.getValue());
configMap[index] = property;
index++;
}
return configMap;
}
use of org.wso2.carbon.idp.mgt.IdentityProviderManager in project identity-governance by wso2-extensions.
the class IdentityGovernanceUtil method saveConnectorDefaultProperties.
@Deprecated
public static void saveConnectorDefaultProperties(IdentityConnectorConfig identityConnectorConfig, String tenantDomain) throws ConnectorException {
IdpManager identityProviderManager = IdentityMgtServiceDataHolder.getInstance().getIdpManager();
try {
IdentityProvider residentIdp = identityProviderManager.getResidentIdP(tenantDomain);
IdentityProviderProperty[] idpProperties = residentIdp.getIdpProperties();
String[] connectorPropertiesNames = identityConnectorConfig.getPropertyNames();
List<IdentityProviderProperty> propertiesToAdd = new ArrayList<>();
for (String connectorPropertyName : connectorPropertiesNames) {
boolean propertyExists = false;
for (IdentityProviderProperty property : idpProperties) {
if (connectorPropertyName.equals(property.getName())) {
propertyExists = true;
break;
}
}
if (!propertyExists) {
IdentityProviderProperty newProperty = new IdentityProviderProperty();
newProperty.setName(connectorPropertyName);
newProperty.setDisplayName(identityConnectorConfig.getPropertyNameMapping().get(connectorPropertyName));
Properties defaultPropertyValues = identityConnectorConfig.getDefaultPropertyValues(tenantDomain);
newProperty.setValue(String.valueOf(defaultPropertyValues.get(connectorPropertyName)));
propertiesToAdd.add(newProperty);
}
}
// If the property list size is greater than 0, add the new properties to the database.
if (propertiesToAdd.size() > 0) {
String alreadyWrittenPropertyName = identityConnectorConfig.getName() + "." + IdentityEventConstants.PropertyConfig.ALREADY_WRITTEN_PROPERTY_KEY;
boolean alreadyWrittenPropertyExists = false;
for (IdentityProviderProperty property : idpProperties) {
if (alreadyWrittenPropertyName.equals(property.getName())) {
alreadyWrittenPropertyExists = true;
break;
}
}
if (!alreadyWrittenPropertyExists) {
IdentityProviderProperty property = new IdentityProviderProperty();
property.setName(alreadyWrittenPropertyName);
property.setValue(IdentityEventConstants.PropertyConfig.ALREADY_WRITTEN_PROPERTY_VALUE);
propertiesToAdd.add(property);
}
propertiesToAdd.addAll(Arrays.asList(idpProperties));
residentIdp.setIdpProperties(propertiesToAdd.toArray(new IdentityProviderProperty[0]));
FederatedAuthenticatorConfig[] authenticatorConfigs = residentIdp.getFederatedAuthenticatorConfigs();
List<FederatedAuthenticatorConfig> configsToSave = new ArrayList<>();
for (FederatedAuthenticatorConfig authenticatorConfig : authenticatorConfigs) {
if (IdentityApplicationConstants.Authenticator.PassiveSTS.NAME.equals(authenticatorConfig.getName()) || IdentityApplicationConstants.Authenticator.SAML2SSO.NAME.equals(authenticatorConfig.getName())) {
configsToSave.add(authenticatorConfig);
}
}
residentIdp.setFederatedAuthenticatorConfigs(configsToSave.toArray(new FederatedAuthenticatorConfig[0]));
identityProviderManager.updateResidentIdP(residentIdp, tenantDomain);
if (log.isDebugEnabled()) {
log.debug("New resident IDP properties for tenant : " + tenantDomain + " written to database");
}
}
} catch (IdentityProviderManagementException e) {
log.error("Error while adding identity management properties to resident Idp.", e);
}
}
Aggregations