Java Code Examples for org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils#startTenantFlow()
The following examples show how to use
org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils#startTenantFlow() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CORSManagementServiceImpl.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
@Override public List<CORSOrigin> getCORSOrigins(String tenantDomain) throws CORSManagementServiceException { validateTenantDomain(tenantDomain); try { FrameworkUtils.startTenantFlow(tenantDomain); Resource resource = getConfigurationManager().getResource(CORS_ORIGIN_RESOURCE_TYPE_NAME, CORS_ORIGIN_RESOURCE_NAME); List<CORSOrigin> corsOrigins; if (resource == null) { corsOrigins = new ArrayList<>(); } else { corsOrigins = new ResourceToCORSOrigin().apply(resource); } return Collections.unmodifiableList(corsOrigins); } catch (ConfigurationManagementException | IOException e) { throw handleServerException(ERROR_CODE_CORS_RETRIEVE, e, tenantDomain); } finally { FrameworkUtils.endTenantFlow(); } }
Example 2
Source File: CORSManagementServiceImpl.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
@Override public void setCORSOrigins(String tenantDomain, List<CORSOrigin> corsOrigins) throws CORSManagementServiceException { validateTenantDomain(tenantDomain); validateOrigins(corsOrigins); try { FrameworkUtils.startTenantFlow(tenantDomain); ResourceAdd resourceAdd = new CORSOriginToResourceAdd().apply(corsOrigins); getConfigurationManager().replaceResource(CORS_ORIGIN_RESOURCE_TYPE_NAME, resourceAdd); } catch (ConfigurationManagementException | JsonProcessingException e) { throw handleServerException(ERROR_CODE_CORS_SET, e, tenantDomain); } finally { FrameworkUtils.endTenantFlow(); } }
Example 3
Source File: TenantConsentMgtListener.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
protected void addDefaultPurposeCategory(TenantInfoBean tenantInfoBean) throws StratosException { FrameworkUtils.startTenantFlow(tenantInfoBean.getTenantDomain()); try { PurposeCategory purposeCategory; PurposeCategory defaultPurposeCategory = new PurposeCategory(DEFAULT_PURPOSE_CATEGORY, "Core " + "functionality"); try { purposeCategory = IdentityConsentDataHolder.getInstance().getConsentManager().addPurposeCategory (defaultPurposeCategory); if (log.isDebugEnabled()) { log.debug(String.format("Added default purpose category for tenant: %s. Default purpose category " + "id: %d", tenantInfoBean.getTenantDomain(), purposeCategory.getId())); } } catch (ConsentManagementException e) { throw new StratosException("Error while adding default purpose category for tenant:" + tenantInfoBean .getTenantDomain(), e); } } finally { FrameworkUtils.endTenantFlow(); } }
Example 4
Source File: PostAuthAssociationHandler.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
/** * To get the local user name associated with the given federated IDP and the subject identifier. * * @param context Authentication context. * @param stepConfig Step config. * @return user name associated with. * @throws PostAuthenticationFailedException Post Authentication Failed Exception. */ private String getUserNameAssociatedWith(AuthenticationContext context, StepConfig stepConfig) throws PostAuthenticationFailedException { String associatesUserName; String originalExternalIdpSubjectValueForThisStep = stepConfig.getAuthenticatedUser() .getAuthenticatedSubjectIdentifier(); try { FrameworkUtils.startTenantFlow(context.getTenantDomain()); FederatedAssociationManager federatedAssociationManager = FrameworkUtils.getFederatedAssociationManager(); associatesUserName = federatedAssociationManager.getUserForFederatedAssociation(context.getTenantDomain() , stepConfig.getAuthenticatedIdP(), originalExternalIdpSubjectValueForThisStep); if (StringUtils.isNotBlank(associatesUserName)) { if (log.isDebugEnabled()) { log.debug("User : " + stepConfig.getAuthenticatedUser() + " has an associated account as " + associatesUserName + ". Hence continuing as " + associatesUserName); } stepConfig.getAuthenticatedUser().setUserName(associatesUserName); stepConfig.getAuthenticatedUser().setTenantDomain(context.getTenantDomain()); stepConfig.setAuthenticatedUser(stepConfig.getAuthenticatedUser()); } else { if (log.isDebugEnabled()) { log.debug("User " + stepConfig.getAuthenticatedUser() + " doesn't have an associated" + " account. Hence continuing as the same user."); } } } catch (FederatedAssociationManagerException | FrameworkException e) { throw new PostAuthenticationFailedException( FrameworkErrorConstants.ErrorMessages.ERROR_WHILE_GETTING_LOCAL_USER_ID.getCode(), String.format(FrameworkErrorConstants.ErrorMessages.ERROR_WHILE_GETTING_IDP_BY_NAME.getMessage(), originalExternalIdpSubjectValueForThisStep), e); } finally { FrameworkUtils.endTenantFlow(); } return associatesUserName; }
Example 5
Source File: DefaultProvisioningHandler.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
protected void associateUser(String username, String userStoreDomain, String tenantDomain, String subject, String idp) throws FrameworkException { String usernameWithUserstoreDomain = UserCoreUtil.addDomainToName(username, userStoreDomain); try { // start tenant flow FrameworkUtils.startTenantFlow(tenantDomain); PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(usernameWithUserstoreDomain); if (!StringUtils.isEmpty(idp) && !StringUtils.isEmpty(subject)) { FederatedAssociationManager federatedAssociationManager = FrameworkUtils .getFederatedAssociationManager(); User user = getAssociatedUser(tenantDomain, userStoreDomain, username); federatedAssociationManager.createFederatedAssociation(user, idp, subject); if (log.isDebugEnabled()) { log.debug("Associated local user: " + usernameWithUserstoreDomain + " in tenant: " + tenantDomain + " to the federated subject : " + subject + " in IdP: " + idp); } } else { throw new FrameworkException("Error while associating local user: " + usernameWithUserstoreDomain + " in tenant: " + tenantDomain + " to the federated subject : " + subject + " in IdP: " + idp); } } catch (FederatedAssociationManagerException e) { if (isUserAlreadyAssociated(e)) { log.info("An association already exists for user: " + subject + ". Skip association while JIT " + "provisioning"); } else { throw new FrameworkException("Error while associating local user: " + usernameWithUserstoreDomain + " in tenant: " + tenantDomain + " to the federated subject : " + subject + " in IdP: " + idp, e); } } finally { // end tenant flow FrameworkUtils.endTenantFlow(); } }