当前位置: 首页>>代码示例>>Java>>正文


Java CarbonContext.getThreadLocalCarbonContext方法代码示例

本文整理汇总了Java中org.wso2.carbon.context.CarbonContext.getThreadLocalCarbonContext方法的典型用法代码示例。如果您正苦于以下问题:Java CarbonContext.getThreadLocalCarbonContext方法的具体用法?Java CarbonContext.getThreadLocalCarbonContext怎么用?Java CarbonContext.getThreadLocalCarbonContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.wso2.carbon.context.CarbonContext的用法示例。


在下文中一共展示了CarbonContext.getThreadLocalCarbonContext方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: removeMySession

import org.wso2.carbon.context.CarbonContext; //导入方法依赖的package包/类
/**
 *
 * Terminates the requested session, after validating whether the session belongs to the logged in user.
 *
 * @param sessionId
 * @return
 */
public boolean removeMySession(String sessionId) {

    if (StringUtils.isBlank(sessionId)) {
        return false;
    }
    SessionContext sessionContext = FrameworkUtils.getSessionContextFromCache(sessionId);
    // Check whether the session belongs to the logged in user.
    CarbonContext carbonContext = CarbonContext.getThreadLocalCarbonContext();
    String username = carbonContext.getUsername();
    // Extract the user store domain if there is any or set to 'PRIMARY'.
    String userStoreDomain = "PRIMARY";
    String[] usernameTokens = username.split("/");
    if (usernameTokens.length > 1) {
        userStoreDomain = usernameTokens[0];
        username = usernameTokens[1];
    }

    AuthenticatedUser authenticatedUser = (AuthenticatedUser) sessionContext
            .getProperty(FrameworkConstants.AUTHENTICATED_USER);
    if (username.equals(authenticatedUser.getUserName())
            && userStoreDomain.equals(authenticatedUser.getUserStoreDomain())
            && carbonContext.getTenantDomain().equals(authenticatedUser.getTenantDomain())) {
        terminateSession(sessionContext, sessionId);
    } else { // TODO : Handle federated scenario.
        log.warn(String.format("Trying to terminate a session which does not belong to logged in user (%s). " +
                "This might be an attempt for a security breach", username));
        return false;
    }
    return true;
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:38,代码来源:SessionManagementService.java

示例2: getConnector

import org.wso2.carbon.context.CarbonContext; //导入方法依赖的package包/类
/**
 * @param identityProviderName
 * @param provisoningProperties
 * @param tenantDomain
 * @return
 * @throws IdentityProvisioningException
 */
public AbstractOutboundProvisioningConnector getConnector(String identityProviderName,
                                                          Property[] provisoningProperties, String tenantDomain)
        throws IdentityProvisioningException {

    String tenantDomainName = null;
    int tenantId = -1234;

    if (CarbonContext.getThreadLocalCarbonContext() != null) {
        tenantDomainName = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
        tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    }

    try {
        // maintain the provisioning connector cache in the super tenant.
        // at the time of provisioning there may not be an authenticated user in the system -
        // specially in the case of in-bound provisioning.
        PrivilegedCarbonContext.startTenantFlow();

        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext
                .getThreadLocalCarbonContext();
        carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
        carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);

        ProvisioningConnectorCacheKey cacheKey = new ProvisioningConnectorCacheKey(identityProviderName, tenantDomain);
        ProvisioningConnectorCacheEntry entry = ProvisioningConnectorCache.getInstance().getValueFromCache(cacheKey);

        if (entry != null) {
            if (log.isDebugEnabled()) {
                log.debug("Provisioning cache HIT for " + identityProviderName + " of "
                        + tenantDomain);
            }
            return entry.getProvisioningConnector();
        }

        AbstractOutboundProvisioningConnector connector;

        Property idpName = new Property();
        idpName.setName("identityProviderName");
        idpName.setValue(identityProviderName);

        List<Property> provisioningPropertiesList = new ArrayList<>(Arrays.asList(provisoningProperties));

        provisioningPropertiesList.add(idpName);

        Property[] provisioningProperties = new Property[provisioningPropertiesList.size()];
        provisioningProperties = provisioningPropertiesList.toArray(provisioningProperties);

        connector = buildConnector(provisioningProperties);
        entry = new ProvisioningConnectorCacheEntry();
        entry.setProvisioningConnector(connector);
        ProvisioningConnectorCache.getInstance().addToCache(cacheKey, entry);

        return connector;
    } finally {
        PrivilegedCarbonContext.endTenantFlow();

        if (tenantDomain != null) {
            PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
                    tenantDomainName);
            PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId);
        }
    }

}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:72,代码来源:AbstractProvisioningConnectorFactory.java

示例3: destroyConnector

import org.wso2.carbon.context.CarbonContext; //导入方法依赖的package包/类
/**
 * @param identityProviderName
 * @param tenantDomain
 * @throws IdentityProvisioningException
 */
public void destroyConnector(String identityProviderName, String tenantDomain)
        throws IdentityProvisioningException {

    String tenantDomainName = null;
    int tenantId = -1234;

    if (CarbonContext.getThreadLocalCarbonContext() != null) {
        tenantDomainName = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
        tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    }

    try {

        PrivilegedCarbonContext.startTenantFlow();
        PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext
                .getThreadLocalCarbonContext();
        carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
        carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);

        ProvisioningConnectorCacheKey cacheKey = new ProvisioningConnectorCacheKey(identityProviderName, tenantDomain);
        ProvisioningConnectorCacheEntry entry = ProvisioningConnectorCache.getInstance().getValueFromCache(cacheKey);

        if (entry != null) {
            ProvisioningConnectorCache.getInstance().clearCacheEntry(cacheKey);

            if (log.isDebugEnabled()) {
                log.debug("Provisioning cached entry removed for idp " + identityProviderName
                        + " from the connector " + getConnectorType());
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Provisioning cached entry not found for idp " + identityProviderName
                        + " from the connector " + getConnectorType());
            }
        }
    } finally {
        PrivilegedCarbonContext.endTenantFlow();

        if (tenantDomain != null) {
            PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
                    tenantDomainName);
            PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId);
        }
    }
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:51,代码来源:AbstractProvisioningConnectorFactory.java


注:本文中的org.wso2.carbon.context.CarbonContext.getThreadLocalCarbonContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。