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


Java MultitenantUtils.getTenantAwareUsername方法代码示例

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


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

示例1: getUser

import org.wso2.carbon.utils.multitenancy.MultitenantUtils; //导入方法依赖的package包/类
/**
 * Build user object from complete username
 * @param userName
 * @return
 */
public static UserDTO getUser(String userName) {

    if (userName == null) {
        return null;
    }

    String userStoreDomain = IdentityUtil.extractDomainFromName(userName);
    String tenantDomain = MultitenantUtils.getTenantDomain(userName);
    String userNameWithoutTenantDomainAndUserStoreDomain = MultitenantUtils
            .getTenantAwareUsername(UserCoreUtil.removeDomainFromName(userName));

    UserDTO user = new UserDTO();
    user.setUsername(userNameWithoutTenantDomainAndUserStoreDomain);
    user.setRealm(userStoreDomain);
    user.setTenantDomain(tenantDomain);

    return user;
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:24,代码来源:AuthenticationEndpointUtil.java

示例2: getUserFromUserName

import org.wso2.carbon.utils.multitenancy.MultitenantUtils; //导入方法依赖的package包/类
/**
 * Returns a User object constructed from fully qualified username
 *
 * @param username Fully qualified username
 * @return User object
 * @throws IllegalArgumentException
 */
public static User getUserFromUserName(String username) {

    User user = new User();
    if (StringUtils.isNotBlank(username)) {
        String tenantDomain = MultitenantUtils.getTenantDomain(username);
        String tenantAwareUsername = MultitenantUtils.getTenantAwareUsername(username);
        String tenantAwareUsernameWithNoUserDomain = UserCoreUtil.removeDomainFromName(tenantAwareUsername);
        String userStoreDomain = IdentityUtil.extractDomainFromName(username).toUpperCase();
        user.setUserName(tenantAwareUsernameWithNoUserDomain);
        if (StringUtils.isNotEmpty(tenantDomain)) {
            user.setTenantDomain(tenantDomain);
        } else {
            user.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        }
        if (StringUtils.isNotEmpty(userStoreDomain)) {
            user.setUserStoreDomain(userStoreDomain);
        } else {
            user.setTenantDomain(UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME);
        }
    }
    return user;
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:30,代码来源:User.java

示例3: getUser

import org.wso2.carbon.utils.multitenancy.MultitenantUtils; //导入方法依赖的package包/类
/**
 * Build user object from complete username
 * @param userName
 * @return
 */
public User getUser(String userName) {

    if (userName == null) {
        return null;
    }

    String userStoreDomain = extractDomainFromName(userName);
    String tenantDomain = MultitenantUtils.getTenantDomain(userName);
    String userNameWithoutTenantDomainAndUserStoreDomain = MultitenantUtils
            .getTenantAwareUsername(UserCoreUtil.removeDomainFromName(userName));

    User user = new User();
    user.setUsername(userNameWithoutTenantDomainAndUserStoreDomain);
    user.setRealm(userStoreDomain);
    user.setTenantDomain(tenantDomain);

    return user;
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:24,代码来源:IdentityManagementServiceUtil.java

示例4: addUser

import org.wso2.carbon.utils.multitenancy.MultitenantUtils; //导入方法依赖的package包/类
public void addUser(UserDTO user) throws Exception {
    UserFieldDTO[] userFieldDTOs = null;
    Map<String, String> userClaims = null;

    userFieldDTOs = user.getUserFields();
    userClaims = new HashMap<String, String>();

    if (userFieldDTOs != null) {
        for (UserFieldDTO userFieldDTO : userFieldDTOs) {
            userClaims.put(userFieldDTO.getClaimUri(), userFieldDTO.getFieldValue());
        }
    }

    UserRealm realm = null;
    String tenantAwareUserName = MultitenantUtils.getTenantAwareUsername(user.getUserName());
    String tenantName = MultitenantUtils.getTenantDomain(user.getUserName());
    realm = IdentityTenantUtil.getRealm(tenantName, null);
    addUser(tenantAwareUserName, user.getPassword(), userClaims, null, realm);
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:20,代码来源:UserRegistrationService.java

示例5: getMobileNumberForUsername

import org.wso2.carbon.utils.multitenancy.MultitenantUtils; //导入方法依赖的package包/类
/**
 * Get the mobile number for Username.
 *
 * @param username the username
 * @return mobile number
 * @throws SMSOTPException
 */
public static String getMobileNumberForUsername(String username) throws SMSOTPException,
        AuthenticationFailedException {
    UserRealm userRealm;
    String mobile;
    try {
        String tenantDomain = MultitenantUtils.getTenantDomain(username);
        String tenantAwareUsername = MultitenantUtils.getTenantAwareUsername(username);
        userRealm = getUserRealm(tenantDomain);
        if (userRealm != null) {
            mobile = userRealm.getUserStoreManager()
                    .getUserClaimValue(tenantAwareUsername, SMSOTPConstants.MOBILE_CLAIM, null);
        } else {
            throw new SMSOTPException("Cannot find the user realm for the given tenant domain : " + tenantDomain);
        }
    } catch (UserStoreException e) {
        throw new SMSOTPException("Cannot find the user " + username + " to get the mobile number ", e);
    }
    return mobile;
}
 
开发者ID:wso2-extensions,项目名称:identity-outbound-auth-sms-otp,代码行数:27,代码来源:SMSOTPUtils.java

示例6: isUserAuthorized

import org.wso2.carbon.utils.multitenancy.MultitenantUtils; //导入方法依赖的package包/类
/**
 * Check whether the client is authorized with the given permission and action.
 * @param permission           Carbon permission that requires for the use
 * @param action               Carbon permission action that requires for the given permission.
 * @return boolean - true if user is authorized else return false.
 */
private boolean isUserAuthorized(String permission, String action) {
    PrivilegedCarbonContext context = PrivilegedCarbonContext.getThreadLocalCarbonContext();
    String username = context.getUsername();
    try {
        UserRealm userRealm = APIUtil.getRealmService().getTenantUserRealm(PrivilegedCarbonContext
                            .getThreadLocalCarbonContext().getTenantId());
        String tenantAwareUsername = MultitenantUtils.getTenantAwareUsername(username);
        boolean status =  userRealm.getAuthorizationManager()
                .isUserAuthorized(tenantAwareUsername, permission, action);
        if (!status) {
            String[] roles = userRealm.getUserStoreManager().getRoleListOfUser(tenantAwareUsername);
            for (String role : roles) {
                if (role.equals(DEFAULT_ADMIN_ROLE)) {
                    return true;
                }
            }
        }
        return status;
    } catch (UserStoreException e) {
        String errorMsg = String.format("Unable to authorize the user : %s", username);
        log.error(errorMsg, e);
        return false;
    }
}
 
开发者ID:wso2,项目名称:carbon-device-mgt,代码行数:31,代码来源:ApiPermissionFilter.java

示例7: validateToken

import org.wso2.carbon.utils.multitenancy.MultitenantUtils; //导入方法依赖的package包/类
/**
 * This method gets a string accessToken and validates it and generate the OAuth2ClientApplicationDTO
 * containing the validity and user details if valid.
 *
 * @param token which need to be validated.
 * @return OAuthValidationResponse with the validated results.
 */
public OAuthValidationResponse validateToken(String token) throws RemoteException{
    OAuth2TokenValidationRequestDTO validationRequest = new OAuth2TokenValidationRequestDTO();
    OAuth2TokenValidationRequestDTO.OAuth2AccessToken accessToken =
            validationRequest.new OAuth2AccessToken();
    accessToken.setTokenType(BEARER_TOKEN_TYPE);
    accessToken.setIdentifier(token);
    validationRequest.setAccessToken(accessToken);
    OAuth2TokenValidationResponseDTO tokenValidationResponse = OAuthAuthenticatorDataHolder.getInstance().
            getOAuth2TokenValidationService().findOAuthConsumerIfTokenIsValid(validationRequest).getAccessTokenValidationResponse();
    boolean isValid = tokenValidationResponse.isValid();
    String userName = null;
    String tenantDomain = null;
    if (isValid) {
        userName = MultitenantUtils.getTenantAwareUsername(
                tokenValidationResponse.getAuthorizedUser());
        tenantDomain =
                MultitenantUtils.getTenantDomain(tokenValidationResponse.getAuthorizedUser());
    }
    return new OAuthValidationResponse(userName, tenantDomain, isValid);
}
 
开发者ID:wso2,项目名称:carbon-device-mgt,代码行数:28,代码来源:LocalOAuthValidator.java

示例8: validateToken

import org.wso2.carbon.utils.multitenancy.MultitenantUtils; //导入方法依赖的package包/类
/**
 * This method gets a string accessToken and validates it and generate the OAuth2ClientApplicationDTO
 * containing the validity and user details if valid.
 *
 * @param token which need to be validated.
 * @return OAuthValidationResponse with the validated results.
 */
public OAuthValidationResponse validateToken(String token) {
    OAuth2TokenValidationRequestDTO validationRequest = new OAuth2TokenValidationRequestDTO();
    OAuth2TokenValidationRequestDTO.OAuth2AccessToken accessToken =
            validationRequest.new OAuth2AccessToken();
    accessToken.setTokenType(OauthAuthenticatorConstants.BEARER_TOKEN_TYPE);
    accessToken.setIdentifier(token);
    validationRequest.setAccessToken(accessToken);
    OAuth2TokenValidationResponseDTO tokenValidationResponse = OAuthAuthenticatorDataHolder.getInstance().
            getOAuth2TokenValidationService().findOAuthConsumerIfTokenIsValid(validationRequest).getAccessTokenValidationResponse();
    boolean isValid = tokenValidationResponse.isValid();
    String userName = null;
    String tenantDomain = null;
    if (isValid) {
        userName = MultitenantUtils.getTenantAwareUsername(
                tokenValidationResponse.getAuthorizedUser());
        tenantDomain =
                MultitenantUtils.getTenantDomain(tokenValidationResponse.getAuthorizedUser());
    }
    return new OAuthValidationResponse(userName, tenantDomain, isValid);
}
 
开发者ID:wso2,项目名称:carbon-device-mgt,代码行数:28,代码来源:LocalOAuthValidator.java

示例9: authorizeOauthRequestToken

import org.wso2.carbon.utils.multitenancy.MultitenantUtils; //导入方法依赖的package包/类
/**
 * Authorizes the OAuth request token for the given scope. In order for the Consumer to be able
 * to exchange the Request Token for an Access Token, the Consumer MUST obtain approval from the
 * User by directing the User to the Service Provider. The Consumer constructs an HTTP GET
 * request to the Service Provider's User Authorization URL with the following parameters.
 *
 * @param params             A container for the following attributes.
 * @param params:oauth_token (required) : Request token obtained from WSO2.
 * @param params:userName    : User who authorizes the token.
 * @param params:password    : Password of the user who authorizes the token.
 * @return oauth_token, oauth_verifier
 * @throws Exception
 */
public Parameters authorizeOauthRequestToken(Parameters params) throws IdentityException, AuthenticationException {
    String tenantUser = MultitenantUtils.getTenantAwareUsername(params.getAuthorizedbyUserName());
    String domainName = MultitenantUtils.getTenantDomain(params.getAuthorizedbyUserName());
    boolean isAuthenticated = false;
    try {
        isAuthenticated = IdentityTenantUtil
                .getRealm(domainName, params.getAuthorizedbyUserName()).getUserStoreManager()
                .authenticate(tenantUser, params.getAuthorizedbyUserPassword());
    } catch (UserStoreException e) {
        log.error("Error while authenticating the user", e);
        throw IdentityException.error("Error while authenticating the user");
    }
    if (isAuthenticated) {
        OAuthConsumerDAO dao = new OAuthConsumerDAO();
        String oauthVerifier = org.wso2.carbon.identity.oauth.OAuthUtil.getRandomNumber();
        Parameters token = dao.authorizeOAuthToken(params.getOauthToken(), tenantUser,
                oauthVerifier);
        token.setOauthToken(params.getOauthToken());
        token.setOauthTokenVerifier(oauthVerifier);
        return token;
    } else {
        throw new AuthenticationException("User Authentication Failed");
    }
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:38,代码来源:OAuthService.java

示例10: getClaims

import org.wso2.carbon.utils.multitenancy.MultitenantUtils; //导入方法依赖的package包/类
@Override
public SortedMap<String, String> getClaims(String endUserName, String[] requestedClaims) throws IdentityOAuth2Exception {

    SortedMap<String, String> claimValues;
    int tenantId = MultitenantConstants.SUPER_TENANT_ID;
    try {
        tenantId = OAuth2Util.getTenantIdFromUserName(endUserName);
        String tenantAwareUsername = MultitenantUtils.getTenantAwareUsername(endUserName);
        UserStoreManager userStoreManager = OAuthComponentServiceHolder.getRealmService().
                getTenantUserRealm(tenantId).getUserStoreManager();
        claimValues = new TreeMap(userStoreManager.getUserClaimValues(tenantAwareUsername, requestedClaims, null));
    } catch (UserStoreException e) {
        throw new IdentityOAuth2Exception("Error while reading claims for user : " + endUserName, e);
    }
    return claimValues;
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:17,代码来源:DefaultClaimsRetriever.java

示例11: addUser

import org.wso2.carbon.utils.multitenancy.MultitenantUtils; //导入方法依赖的package包/类
public void addUser(UserDTO user) throws Exception {
    UserFieldDTO[] userFieldDTOs = null;
    Map<String, String> userClaims = null;

    userFieldDTOs = user.getUserFields();
    userClaims = new HashMap<String, String>();

    if (userFieldDTOs != null) {
        for (UserFieldDTO userFieldDTO : userFieldDTOs) {
            userClaims.put(userFieldDTO.getClaimUri(), userFieldDTO.getFieldValue());
        }
    }

    UserRealm realm = null;
    String tenantAwareUserName = MultitenantUtils.getTenantAwareUsername(user.getUserName());
    String tenantName = MultitenantUtils.getTenantDomain(user.getUserName());
    realm = IdentityTenantUtil.getRealm(tenantName, null);
    Registry registry = IdentityTenantUtil.getRegistry(null, null);
    addUser(tenantAwareUserName, user.getPassword(), userClaims, null, realm);
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:21,代码来源:UserRegistrationService.java

示例12: isSMSOTPDisableForLocalUser

import org.wso2.carbon.utils.multitenancy.MultitenantUtils; //导入方法依赖的package包/类
/**
 * Check whether SMSOTP is disable by user.
 *
 * @param username the Username
 * @param context  the AuthenticationContext
 * @return true or false
 * @throws SMSOTPException
 */
public static boolean isSMSOTPDisableForLocalUser(String username, AuthenticationContext context,
                                                  String authenticatorName) throws SMSOTPException,
        AuthenticationFailedException {
    UserRealm userRealm;
    try {
        String tenantDomain = MultitenantUtils.getTenantDomain(username);
        int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
        RealmService realmService = IdentityTenantUtil.getRealmService();
        userRealm = realmService.getTenantUserRealm(tenantId);
        username = MultitenantUtils.getTenantAwareUsername(String.valueOf(username));
        boolean isEnablingControlledByUser = isSMSOTPEnableOrDisableByUser(context, authenticatorName);
        if (userRealm != null) {
            if (isEnablingControlledByUser) {
                Map<String, String> claimValues = userRealm.getUserStoreManager().getUserClaimValues(username,
                        new String[]{SMSOTPConstants.USER_SMSOTP_DISABLED_CLAIM_URI}, null);
                return Boolean.parseBoolean(claimValues.get(SMSOTPConstants.USER_SMSOTP_DISABLED_CLAIM_URI));
            }
        } else {
            throw new SMSOTPException("Cannot find the user realm for the given tenant domain : " + CarbonContext
                    .getThreadLocalCarbonContext().getTenantDomain());
        }
    } catch (UserStoreException e) {
        throw new SMSOTPException("Failed while trying to access userRealm of the user : " + username, e);
    }
    return false;
}
 
开发者ID:wso2-extensions,项目名称:identity-outbound-auth-sms-otp,代码行数:35,代码来源:SMSOTPUtils.java

示例13: checkWithBackUpCodes

import org.wso2.carbon.utils.multitenancy.MultitenantUtils; //导入方法依赖的package包/类
/**
 * If user forgets the mobile, then user can use the back up codes to authenticate the user.
 *
 * @param context           the AuthenticationContext
 * @param userToken         the userToken
 * @param authenticatedUser the name of authenticatedUser
 * @throws AuthenticationFailedException
 */
private void checkWithBackUpCodes(AuthenticationContext context, String userToken,
                                  AuthenticatedUser authenticatedUser) throws AuthenticationFailedException {
    String savedOTPString = null;
    String username = context.getProperty(SMSOTPConstants.USER_NAME).toString();
    String tenantAwareUsername = MultitenantUtils.getTenantAwareUsername(username);
    UserRealm userRealm = getUserRealm(username);
    try {
        if (userRealm != null) {
            savedOTPString = userRealm.getUserStoreManager()
                    .getUserClaimValue(tenantAwareUsername, SMSOTPConstants.SAVED_OTP_LIST, null);
        }
        if (StringUtils.isEmpty(savedOTPString)) {
            if (log.isDebugEnabled()) {
                log.debug("The claim " + SMSOTPConstants.SAVED_OTP_LIST + " does not contain any values");
            }
            throw new AuthenticationFailedException("The claim " + SMSOTPConstants.SAVED_OTP_LIST +
                    " does not contain any values");
        } else if (savedOTPString.contains(userToken)) {
            if(log.isDebugEnabled()) {
                log.debug("Found saved backup SMS OTP for user :" + authenticatedUser);
            }
            context.setSubject(authenticatedUser);
            savedOTPString = savedOTPString.replaceAll(userToken, "").replaceAll(",,", ",");
            userRealm.getUserStoreManager().setUserClaimValue(tenantAwareUsername,
                    SMSOTPConstants.SAVED_OTP_LIST, savedOTPString, null);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("User entered OTP :" + userToken + " does not match with any of the saved backup codes");
            }
            throw new AuthenticationFailedException("Verification Error due to Code " + userToken + " mismatch.");
        }
    } catch (UserStoreException e) {
        throw new AuthenticationFailedException("Cannot find the user claim for OTP list for user : " +
                authenticatedUser, e);
    }
}
 
开发者ID:wso2-extensions,项目名称:identity-outbound-auth-sms-otp,代码行数:45,代码来源:SMSOTPAuthenticator.java

示例14: createGeoAlerts

import org.wso2.carbon.utils.multitenancy.MultitenantUtils; //导入方法依赖的package包/类
@Path("alerts/{alertType}/{deviceType}/{deviceId}")
@POST
@Consumes("application/json")
@Produces("application/json")
public Response createGeoAlerts(Alert alert, @PathParam("deviceId") String deviceId,
                                @PathParam("deviceType") String deviceType,
                                @PathParam("alertType") String alertType) {
    try {
        if (!DeviceMgtAPIUtils.getDeviceAccessAuthorizationService().isUserAuthorized(
                new DeviceIdentifier(deviceId, deviceType),
                DeviceGroupConstants.Permissions.DEFAULT_STATS_MONITOR_PERMISSIONS)) {
            return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
        }

        // this is the user who initiates the request
        String authorizedUser = MultitenantUtils.getTenantAwareUsername(
                CarbonContext.getThreadLocalCarbonContext().getUsername()
        );

        DeviceIdentifier identifier = new DeviceIdentifier();
        identifier.setId(deviceId);
        identifier.setType(deviceType);

        GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService();
        geoService.createGeoAlert(alert, identifier, alertType);
        return Response.ok().build();
    } catch (DeviceAccessAuthorizationException | GeoLocationBasedServiceException e) {
        String error = "Error occurred while creating the geo alert for " + deviceType + " with id: " + deviceId;
        log.error(error, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build();
    }
}
 
开发者ID:wso2,项目名称:carbon-device-mgt,代码行数:33,代码来源:GeoLocationBasedServiceImpl.java

示例15: updateGeoAlerts

import org.wso2.carbon.utils.multitenancy.MultitenantUtils; //导入方法依赖的package包/类
@Path("alerts/{alertType}/{deviceType}/{deviceId}")
@PUT
@Consumes("application/json")
@Produces("application/json")
public Response updateGeoAlerts(Alert alert, @PathParam("deviceId") String deviceId,
                                @PathParam("deviceType") String deviceType,
                                @PathParam("alertType") String alertType) {
    try {
        if (!DeviceMgtAPIUtils.getDeviceAccessAuthorizationService().isUserAuthorized(
                new DeviceIdentifier(deviceId, deviceType),
                DeviceGroupConstants.Permissions.DEFAULT_STATS_MONITOR_PERMISSIONS)) {
            return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build();
        }

        // this is the user who initiates the request
        String authorizedUser = MultitenantUtils.getTenantAwareUsername(
                CarbonContext.getThreadLocalCarbonContext().getUsername()
        );

        DeviceIdentifier identifier = new DeviceIdentifier();
        identifier.setId(deviceId);
        identifier.setType(deviceType);

        GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService();
        geoService.updateGeoAlert(alert, identifier, alertType);
        return Response.ok().build();
    } catch (DeviceAccessAuthorizationException | GeoLocationBasedServiceException e) {
        String error = "Error occurred while creating the geo alert for " + deviceType + " with id: " + deviceId;
        log.error(error, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build();
    }
}
 
开发者ID:wso2,项目名称:carbon-device-mgt,代码行数:33,代码来源:GeoLocationBasedServiceImpl.java


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