use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.
the class DefaultInboundUserProvisioningListener method doPostUpdateRoleListOfUser.
@Override
public boolean doPostUpdateRoleListOfUser(String userName, String[] deletedRoles, String[] newRoles, UserStoreManager userStoreManager) throws UserStoreException {
if (!isEnable()) {
return true;
}
String[] roleList = userStoreManager.getRoleListOfUser(userName);
Map<String, String> inboundAttributes = new HashMap<>();
Map<ClaimMapping, List<String>> outboundAttributes = new HashMap<>();
if (userName != null) {
outboundAttributes.put(ClaimMapping.build(IdentityProvisioningConstants.USERNAME_CLAIM_URI, null, null, false), Arrays.asList(new String[] { userName }));
}
if (roleList != null && roleList.length > 0) {
outboundAttributes.put(ClaimMapping.build(IdentityProvisioningConstants.GROUP_CLAIM_URI, null, null, false), Arrays.asList(roleList));
}
if (newRoles != null && roleList.length > 0) {
outboundAttributes.put(ClaimMapping.build(IdentityProvisioningConstants.NEW_GROUP_CLAIM_URI, null, null, false), Arrays.asList(newRoles));
}
if (deletedRoles != null && deletedRoles.length > 0) {
outboundAttributes.put(ClaimMapping.build(IdentityProvisioningConstants.DELETED_GROUP_CLAIM_URI, null, null, false), Arrays.asList(deletedRoles));
}
String domainName = UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration());
if (log.isDebugEnabled()) {
log.debug("Adding domain name : " + domainName + " to user : " + userName);
}
String domainAwareName = UserCoreUtil.addDomainToName(userName, domainName);
ProvisioningEntity provisioningEntity = new ProvisioningEntity(ProvisioningEntityType.USER, domainAwareName, ProvisioningOperation.PUT, outboundAttributes);
Claim[] claimArray = null;
try {
claimArray = userStoreManager.getUserClaimValues(userName, null);
} catch (UserStoreException e) {
if (e.getMessage().contains("UserNotFound")) {
if (log.isDebugEnabled()) {
log.debug("User " + userName + " not found in user store");
}
} else {
throw e;
}
}
if (claimArray != null) {
for (Claim claim : claimArray) {
inboundAttributes.put(claim.getClaimUri(), claim.getValue());
}
}
provisioningEntity.setInboundAttributes(inboundAttributes);
String tenantDomainName = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
ThreadLocalProvisioningServiceProvider threadLocalServiceProvider;
threadLocalServiceProvider = IdentityApplicationManagementUtil.getThreadLocalProvisioningServiceProvider();
if (threadLocalServiceProvider != null) {
String serviceProvider = threadLocalServiceProvider.getServiceProviderName();
tenantDomainName = threadLocalServiceProvider.getTenantDomain();
if (threadLocalServiceProvider.getServiceProviderType() == ProvisioningServiceProviderType.OAUTH) {
try {
serviceProvider = ApplicationManagementService.getInstance().getServiceProviderNameByClientId(threadLocalServiceProvider.getServiceProviderName(), IdentityApplicationConstants.OAuth2.NAME, tenantDomainName);
} catch (IdentityApplicationManagementException e) {
log.error("Error while provisioning", e);
return true;
}
}
// call framework method to provision the user.
OutboundProvisioningManager.getInstance().provision(provisioningEntity, serviceProvider, threadLocalServiceProvider.getClaimDialect(), tenantDomainName, threadLocalServiceProvider.isJustInTimeProvisioning());
} else {
// call framework method to provision the user.
OutboundProvisioningManager.getInstance().provision(provisioningEntity, ApplicationConstants.LOCAL_SP, IdentityProvisioningConstants.WSO2_CARBON_DIALECT, tenantDomainName, false);
}
return true;
}
use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.
the class DefaultInboundUserProvisioningListener method doPreAddUser.
@Override
public boolean doPreAddUser(String userName, Object credential, String[] roleList, Map<String, String> inboundAttributes, String profile, UserStoreManager userStoreManager) throws UserStoreException {
if (!isEnable()) {
return true;
}
Map<ClaimMapping, List<String>> outboundAttributes = new HashMap<>();
if (credential != null) {
outboundAttributes.put(ClaimMapping.build(IdentityProvisioningConstants.PASSWORD_CLAIM_URI, null, null, false), Arrays.asList(new String[] { ((StringBuffer) credential).toString() }));
}
if (userName != null) {
outboundAttributes.put(ClaimMapping.build(IdentityProvisioningConstants.USERNAME_CLAIM_URI, null, null, false), Arrays.asList(new String[] { userName }));
}
if (roleList != null) {
outboundAttributes.put(ClaimMapping.build(IdentityProvisioningConstants.GROUP_CLAIM_URI, null, null, false), Arrays.asList(roleList));
}
String domainName = UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration());
if (log.isDebugEnabled()) {
log.debug("Adding domain name : " + domainName + " to user : " + userName);
}
String domainAwareName = UserCoreUtil.addDomainToName(userName, domainName);
ProvisioningEntity provisioningEntity = new ProvisioningEntity(ProvisioningEntityType.USER, domainAwareName, ProvisioningOperation.POST, outboundAttributes);
// set the in-bound attribute list.in this particular case this is in the wso2.org claim
// dialect.
provisioningEntity.setInboundAttributes(inboundAttributes);
String tenantDomainName = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
ThreadLocalProvisioningServiceProvider threadLocalServiceProvider;
threadLocalServiceProvider = IdentityApplicationManagementUtil.getThreadLocalProvisioningServiceProvider();
if (threadLocalServiceProvider != null) {
String serviceProvider = threadLocalServiceProvider.getServiceProviderName();
tenantDomainName = threadLocalServiceProvider.getTenantDomain();
if (threadLocalServiceProvider.getServiceProviderType() == ProvisioningServiceProviderType.OAUTH) {
try {
serviceProvider = ApplicationManagementService.getInstance().getServiceProviderNameByClientId(threadLocalServiceProvider.getServiceProviderName(), IdentityApplicationConstants.OAuth2.NAME, tenantDomainName);
} catch (IdentityApplicationManagementException e) {
log.error("Error while provisioning", e);
return true;
}
}
// call framework method to provision the user.
OutboundProvisioningManager.getInstance().provision(provisioningEntity, serviceProvider, threadLocalServiceProvider.getClaimDialect(), tenantDomainName, threadLocalServiceProvider.isJustInTimeProvisioning());
} else {
// call framework method to provision the user.
OutboundProvisioningManager.getInstance().provision(provisioningEntity, ApplicationConstants.LOCAL_SP, IdentityProvisioningConstants.WSO2_CARBON_DIALECT, tenantDomainName, false);
}
return true;
}
use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.
the class DefaultInboundUserProvisioningListener method doPostUpdateCredential.
@Override
public boolean doPostUpdateCredential(String userName, Object credential, UserStoreManager userStoreManager) throws UserStoreException {
if (!isEnable()) {
return true;
}
Map<ClaimMapping, List<String>> outboundAttributes = new HashMap<ClaimMapping, List<String>>();
if (credential != null) {
outboundAttributes.put(ClaimMapping.build(IdentityProvisioningConstants.PASSWORD_CLAIM_URI, null, null, false), Arrays.asList(credential.toString()));
}
if (userName != null) {
outboundAttributes.put(ClaimMapping.build(IdentityProvisioningConstants.USERNAME_CLAIM_URI, null, null, false), Arrays.asList(userName));
}
String domainName = UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration());
if (log.isDebugEnabled()) {
log.debug("Adding domain name : " + domainName + " to user : " + userName);
}
String domainAwareName = UserCoreUtil.addDomainToName(userName, domainName);
ProvisioningEntity provisioningEntity = new ProvisioningEntity(ProvisioningEntityType.USER, domainAwareName, ProvisioningOperation.PATCH, outboundAttributes);
String tenantDomainName = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
ThreadLocalProvisioningServiceProvider threadLocalServiceProvider;
threadLocalServiceProvider = IdentityApplicationManagementUtil.getThreadLocalProvisioningServiceProvider();
if (threadLocalServiceProvider != null) {
String serviceProvider = threadLocalServiceProvider.getServiceProviderName();
tenantDomainName = threadLocalServiceProvider.getTenantDomain();
if (threadLocalServiceProvider.getServiceProviderType() == ProvisioningServiceProviderType.OAUTH) {
try {
serviceProvider = ApplicationManagementService.getInstance().getServiceProviderNameByClientId(threadLocalServiceProvider.getServiceProviderName(), "oauth2", tenantDomainName);
} catch (IdentityApplicationManagementException e) {
log.error("Error while provisioning", e);
return true;
}
}
// call framework method to provision the user.
OutboundProvisioningManager.getInstance().provision(provisioningEntity, serviceProvider, threadLocalServiceProvider.getClaimDialect(), tenantDomainName, threadLocalServiceProvider.isJustInTimeProvisioning());
} else {
// call framework method to provision the user.
OutboundProvisioningManager.getInstance().provision(provisioningEntity, ApplicationConstants.LOCAL_SP, WSO2_CARBON_DIALECT, tenantDomainName, false);
}
return true;
}
use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.
the class DefaultInboundUserProvisioningListener method doPreDeleteUser.
@Override
public boolean doPreDeleteUser(String userName, UserStoreManager userStoreManager) throws UserStoreException {
if (!isEnable()) {
return true;
}
Map<ClaimMapping, List<String>> outboundAttributes = new HashMap<>();
outboundAttributes.put(ClaimMapping.build(IdentityProvisioningConstants.USERNAME_CLAIM_URI, null, null, false), Arrays.asList(new String[] { userName }));
String domainName = UserCoreUtil.getDomainName(userStoreManager.getRealmConfiguration());
if (log.isDebugEnabled()) {
log.debug("Adding domain name : " + domainName + " to user : " + userName);
}
String domainAwareName = UserCoreUtil.addDomainToName(userName, domainName);
ProvisioningEntity provisioningEntity = new ProvisioningEntity(ProvisioningEntityType.USER, domainAwareName, ProvisioningOperation.DELETE, outboundAttributes);
String tenantDomainName = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
ThreadLocalProvisioningServiceProvider threadLocalServiceProvider;
threadLocalServiceProvider = IdentityApplicationManagementUtil.getThreadLocalProvisioningServiceProvider();
if (threadLocalServiceProvider != null) {
String serviceProvider = threadLocalServiceProvider.getServiceProviderName();
tenantDomainName = threadLocalServiceProvider.getTenantDomain();
if (threadLocalServiceProvider.getServiceProviderType() == ProvisioningServiceProviderType.OAUTH) {
try {
serviceProvider = ApplicationManagementService.getInstance().getServiceProviderNameByClientId(threadLocalServiceProvider.getServiceProviderName(), IdentityApplicationConstants.OAuth2.NAME, tenantDomainName);
} catch (IdentityApplicationManagementException e) {
log.error("Error while provisioning", e);
return true;
}
}
// call framework method to provision the user.
OutboundProvisioningManager.getInstance().provision(provisioningEntity, serviceProvider, threadLocalServiceProvider.getClaimDialect(), tenantDomainName, threadLocalServiceProvider.isJustInTimeProvisioning());
} else {
OutboundProvisioningManager.getInstance().provision(provisioningEntity, ApplicationConstants.LOCAL_SP, IdentityProvisioningConstants.WSO2_CARBON_DIALECT, tenantDomainName, false);
}
return true;
}
use of org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider in project carbon-identity-framework by wso2.
the class ProvisioningIdentityProviderMgtListener method destroyConnector.
/**
* @param identityProviderName
* @param tenantDomain
* @throws IdentityProvisioningException
*/
public void destroyConnector(String identityProviderName, String tenantDomain) throws IdentityProvisioningException {
ProvisioningConnectorCacheKey cacheKey = new ProvisioningConnectorCacheKey(identityProviderName);
ProvisioningConnectorCacheEntry entry = ProvisioningConnectorCache.getInstance().getValueFromCache(cacheKey, tenantDomain);
if (entry != null) {
ProvisioningConnectorCache.getInstance().clearCacheEntry(cacheKey, tenantDomain);
if (log.isDebugEnabled()) {
log.debug("Provisioning cached entry removed for idp " + identityProviderName);
}
} else {
if (log.isDebugEnabled()) {
log.debug("Provisioning cached entry not found for idp " + identityProviderName);
}
}
int tenantId;
try {
RealmService realmService = ProvisioningServiceDataHolder.getInstance().getRealmService();
tenantId = realmService.getTenantManager().getTenantId(tenantDomain);
} catch (UserStoreException e) {
throw new IdentityProvisioningException("Error occurred while retrieving tenant id from tenant domain", e);
}
try {
List<String> serviceProviders = provisioningManagementDAO.getSPNamesOfProvisioningConnectorsByIDP(identityProviderName, tenantId);
for (String serviceProvider : serviceProviders) {
ServiceProviderProvisioningConnectorCacheKey key = new ServiceProviderProvisioningConnectorCacheKey(serviceProvider);
ServiceProviderProvisioningConnectorCacheEntry cacheEntry = ServiceProviderProvisioningConnectorCache.getInstance().getValueFromCache(key, tenantDomain);
if (cacheEntry != null) {
ServiceProviderProvisioningConnectorCache.getInstance().clearCacheEntry(key, tenantDomain);
if (log.isDebugEnabled()) {
log.debug("Service Provider '" + serviceProvider + "' Provisioning cached entry removed for idp " + identityProviderName);
}
} else {
if (log.isDebugEnabled()) {
log.debug("Service Provider '" + serviceProvider + "' Provisioning cached entry not found for idp " + identityProviderName);
}
}
}
} catch (IdentityApplicationManagementException e) {
throw new IdentityProvisioningException("Error occurred while removing cache entry from the " + "service provider provisioning connector cache", e);
}
}
Aggregations