Java Code Examples for org.wso2.carbon.identity.application.common.model.User#setTenantDomain()

The following examples show how to use org.wso2.carbon.identity.application.common.model.User#setTenantDomain() . 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: UserIdtoUser.java    From identity-api-server with Apache License 2.0 5 votes vote down vote up
private User extractUser(String userId, String tenantDomain) {

        try {
            String decodedUsername = new String(Base64.getDecoder().decode(userId), StandardCharsets.UTF_8);

            if (StringUtils.isBlank(userId)) {
                throw new WebApplicationException("UserID is empty.");
            }
            String[] strComponent = decodedUsername.split("/");

            String username;
            String realm = UserStoreConfigConstants.PRIMARY;

            if (strComponent.length == 1) {
                username = strComponent[0];
            } else if (strComponent.length == 2) {
                realm = strComponent[0];
                username = strComponent[1];
            } else {
                throw new WebApplicationException("Provided UserID is " + "not in the correct format.");
            }

            User user = new User();
            user.setUserName(username);
            user.setUserStoreDomain(realm);
            user.setTenantDomain(tenantDomain);

            return user;
        } catch (Exception e) {
            throw new APIError(Response.Status.BAD_REQUEST,
                    new ErrorResponse.Builder().withCode(Constants.ErrorMessages.ERROR_CODE_INVALID_USERNAME.getCode())
                            .withMessage(Constants.ErrorMessages.ERROR_CODE_INVALID_USERNAME.getMessage())
                            .withDescription(Constants.ErrorMessages.ERROR_CODE_INVALID_USERNAME.getDescription())
                            .build(log, e, "Invalid userId: " + userId));
        }
    }
 
Example 2
Source File: DefaultProvisioningHandler.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private User getAssociatedUser(String tenantDomain, String userStoreDomain, String username) {

        User user = new User();
        user.setTenantDomain(tenantDomain);
        user.setUserStoreDomain(userStoreDomain);
        user.setUserName(MultitenantUtils.getTenantAwareUsername(username));
        return user;
    }
 
Example 3
Source File: AbstractApplicationAuthenticator.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
protected void publishAuthenticationStepAttempt(HttpServletRequest request, AuthenticationContext context,
                                              User user, boolean success) {

    AuthenticationDataPublisher authnDataPublisherProxy = FrameworkServiceDataHolder.getInstance()
            .getAuthnDataPublisherProxy();
    if (authnDataPublisherProxy != null && authnDataPublisherProxy.isEnabled(context)) {
        boolean isFederated = this instanceof FederatedApplicationAuthenticator;
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put(FrameworkConstants.AnalyticsAttributes.USER, user);
        if (isFederated) {
            // Setting this value to authentication context in order to use in AuthenticationSuccess Event
            context.setProperty(FrameworkConstants.AnalyticsAttributes.HAS_FEDERATED_STEP, true);
            paramMap.put(FrameworkConstants.AnalyticsAttributes.IS_FEDERATED, true);
            paramMap.put(FrameworkConstants.AUTHENTICATOR, getName());
            if (user != null) {
                user.setTenantDomain(context.getTenantDomain());
            }
        } else {
            // Setting this value to authentication context in order to use in AuthenticationSuccess Event
            context.setProperty(FrameworkConstants.AnalyticsAttributes.HAS_LOCAL_STEP, true);
            paramMap.put(FrameworkConstants.AnalyticsAttributes.IS_FEDERATED, false);
        }
        Map<String, Object> unmodifiableParamMap = Collections.unmodifiableMap(paramMap);
        if (success) {
            authnDataPublisherProxy.publishAuthenticationStepSuccess(request, context,
                    unmodifiableParamMap);

        } else {
            authnDataPublisherProxy.publishAuthenticationStepFailure(request, context,
                    unmodifiableParamMap);
        }
    }
}
 
Example 4
Source File: ApplicationManagementServiceImpl.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Create user object from user name and tenantDomain.
 *
 * @param tenantDomain tenantDomain
 * @param username     username
 * @return User
 */
private User getUser(String tenantDomain, String username) {

    User user = new User();
    user.setUserName(UserCoreUtil.removeDomainFromName(username));
    user.setUserStoreDomain(UserCoreUtil.extractDomainFromName(username));
    user.setTenantDomain(tenantDomain);
    return user;
}
 
Example 5
Source File: UserProfileAdmin.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
private User getUser(String domainAwareUserName) {

        User user = new User();
        user.setTenantDomain(CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
        user.setUserStoreDomain(UserCoreUtil.extractDomainFromName(domainAwareUserName));
        user.setUserName(MultitenantUtils.getTenantAwareUsername(UserCoreUtil.removeDomainFromName(domainAwareUserName)));
        return user;
    }