本文整理汇总了Java中org.wso2.carbon.utils.multitenancy.MultitenantUtils类的典型用法代码示例。如果您正苦于以下问题:Java MultitenantUtils类的具体用法?Java MultitenantUtils怎么用?Java MultitenantUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MultitenantUtils类属于org.wso2.carbon.utils.multitenancy包,在下文中一共展示了MultitenantUtils类的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;
}
示例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;
}
示例3: isUserStoreInUsernameCaseSensitive
import org.wso2.carbon.utils.multitenancy.MultitenantUtils; //导入依赖的package包/类
/**
* Check the case sensitivity of the user store in which the user is in.
*
* @param username Full qualified username
* @return
*/
public static boolean isUserStoreInUsernameCaseSensitive(String username) {
boolean isUsernameCaseSensitive = true;
try {
String tenantDomain = MultitenantUtils.getTenantDomain(username);
int tenantId = IdentityTenantUtil.getRealmService().getTenantManager().getTenantId(tenantDomain);
return isUserStoreInUsernameCaseSensitive(username, tenantId);
} catch (UserStoreException e) {
if (log.isDebugEnabled()) {
log.debug("Error while reading user store property CaseInsensitiveUsername. Considering as case " +
"sensitive.");
}
}
return isUsernameCaseSensitive;
}
示例4: getTenantIdOfUser
import org.wso2.carbon.utils.multitenancy.MultitenantUtils; //导入依赖的package包/类
/**
* Get the tenant id of the given user.
*
* @param username Username
* @return Tenant Id of domain user belongs to.
* @throws IdentityRuntimeException Error when getting the tenant Id from tenant domain
*/
public static int getTenantIdOfUser(String username) throws IdentityRuntimeException {
int tenantId = MultitenantConstants.INVALID_TENANT_ID;
String domainName = MultitenantUtils.getTenantDomain(username);
if (domainName != null) {
try {
TenantManager tenantManager = IdentityTenantUtil.getRealmService().getTenantManager();
tenantId = tenantManager.getTenantId(domainName);
} catch (UserStoreException e) {
String errorMsg = "Error when getting the tenant id from the tenant domain : " + domainName;
throw IdentityRuntimeException.error(errorMsg, e);
}
}
if(tenantId == MultitenantConstants.INVALID_TENANT_ID){
throw IdentityRuntimeException.error("Invalid tenant domain of user " + username);
} else {
return tenantId;
}
}
示例5: 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;
}
示例6: 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);
}
示例7: 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;
}
示例8: testCheckWithBackUpCodes
import org.wso2.carbon.utils.multitenancy.MultitenantUtils; //导入依赖的package包/类
@Test
public void testCheckWithBackUpCodes() throws Exception {
mockStatic(IdentityTenantUtil.class);
context.setProperty(SMSOTPConstants.USER_NAME,"admin");
when(IdentityTenantUtil.getTenantId("carbon.super")).thenReturn(-1234);
when(IdentityTenantUtil.getRealmService()).thenReturn(realmService);
when(realmService.getTenantUserRealm(-1234)).thenReturn(userRealm);
when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
when((AuthenticatedUser) context.getProperty(SMSOTPConstants.AUTHENTICATED_USER)).
thenReturn(AuthenticatedUser.createLocalAuthenticatedUserFromSubjectIdentifier("admin"));
when(userRealm.getUserStoreManager()
.getUserClaimValue(MultitenantUtils.getTenantAwareUsername("admin"),
SMSOTPConstants.SAVED_OTP_LIST, null)).thenReturn("12345,4568,1234,7896");
AuthenticatedUser user = (AuthenticatedUser) context.getProperty(SMSOTPConstants.AUTHENTICATED_USER);
Whitebox.invokeMethod(smsotpAuthenticator, "checkWithBackUpCodes",
context,"1234",user);
}
示例9: testCheckWithInvalidBackUpCodes
import org.wso2.carbon.utils.multitenancy.MultitenantUtils; //导入依赖的package包/类
@Test(expectedExceptions = {AuthenticationFailedException.class})
public void testCheckWithInvalidBackUpCodes() throws Exception {
mockStatic(IdentityTenantUtil.class);
context.setProperty(SMSOTPConstants.USER_NAME,"admin");
when(IdentityTenantUtil.getTenantId("carbon.super")).thenReturn(-1234);
when(IdentityTenantUtil.getRealmService()).thenReturn(realmService);
when(realmService.getTenantUserRealm(-1234)).thenReturn(userRealm);
when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
when((AuthenticatedUser) context.getProperty(SMSOTPConstants.AUTHENTICATED_USER)).
thenReturn(AuthenticatedUser.createLocalAuthenticatedUserFromSubjectIdentifier("admin"));
when(userRealm.getUserStoreManager()
.getUserClaimValue(MultitenantUtils.getTenantAwareUsername("admin"),
SMSOTPConstants.SAVED_OTP_LIST, null)).thenReturn("12345,4568,1234,7896");
AuthenticatedUser user = (AuthenticatedUser) context.getProperty(SMSOTPConstants.AUTHENTICATED_USER);
Whitebox.invokeMethod(smsotpAuthenticator, "checkWithBackUpCodes",
context,"45698789",user);
}
示例10: testIsSMSOTPDisableForLocalUser
import org.wso2.carbon.utils.multitenancy.MultitenantUtils; //导入依赖的package包/类
@Test
public void testIsSMSOTPDisableForLocalUser() throws UserStoreException, AuthenticationFailedException,
SMSOTPException {
mockStatic(IdentityTenantUtil.class);
String username = "admin";
when(IdentityTenantUtil.getTenantId("carbon.super")).thenReturn(-1234);
when(IdentityTenantUtil.getRealmService()).thenReturn(realmService);
when(realmService.getTenantUserRealm(-1234)).thenReturn(userRealm);
when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
when(SMSOTPUtils.isSMSOTPEnableOrDisableByUser(context, SMSOTPConstants.AUTHENTICATOR_NAME)).thenReturn(true);
Map<String, String> claims = new HashMap<>();
claims.put(SMSOTPConstants.USER_SMSOTP_DISABLED_CLAIM_URI, "false");
userStoreManager.setUserClaimValues(MultitenantUtils.getTenantAwareUsername(username), claims, null);
Assert.assertEquals(SMSOTPUtils.isSMSOTPDisableForLocalUser(anyString(), context, SMSOTPConstants
.AUTHENTICATOR_NAME), false);
}
示例11: isExistsInUserStore
import org.wso2.carbon.utils.multitenancy.MultitenantUtils; //导入依赖的package包/类
/**
* Check whether the authenticated user exists in any user store that belongs to the realm the user belongs to.
*
* @param authenticatedUserName
* @param tenantDomain
* @return
*/
private boolean isExistsInUserStore(String authenticatedUserName, String tenantDomain,
String realm) throws AuthenticationFailedException {
UserStoreManager userStoreManager;
try {
userStoreManager = getPrimaryUserStoreManager(tenantDomain).getSecondaryUserStoreManager();
String userStoreDomain = IdentityUtil.getPrimaryDomainName();
authenticatedUserName = IdentityUtil.addDomainToName(authenticatedUserName, userStoreDomain);
// Check whether the authenticated user is in primary user store. This is a limitation and will be improved
// to support ADs mounted as secondary user stores
return userStoreManager.isExistingUser(MultitenantUtils.getTenantAwareUsername(authenticatedUserName));
} catch (UserStoreException e) {
throw new
AuthenticationFailedException("IWALocalAuthenticator failed to find the user in the userstore", e);
}
}
示例12: getTenantIdOFUser
import org.wso2.carbon.utils.multitenancy.MultitenantUtils; //导入依赖的package包/类
public static int getTenantIdOFUser(String username) throws AuthenticationException {
int tenantId = 0;
String domainName = MultitenantUtils.getTenantDomain(username);
if (domainName != null) {
try {
TenantManager tenantManager = AuthenticatorFrameworkDataHolder.getInstance().getRealmService()
.getTenantManager();
tenantId = tenantManager.getTenantId(domainName);
} catch (UserStoreException e) {
String errorMsg = "Error when getting the tenant id from the tenant domain : " +
domainName;
log.error(errorMsg, e);
throw new AuthenticationException(errorMsg, e);
}
}
return tenantId;
}
示例13: testGetDevicesWhenUserIsAdmin
import org.wso2.carbon.utils.multitenancy.MultitenantUtils; //导入依赖的package包/类
@Test(description = "Testing get devices when user is the device admin")
public void testGetDevicesWhenUserIsAdmin() throws DeviceAccessAuthorizationException {
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceAccessAuthorizationService"))
.toReturn(this.deviceAccessAuthorizationService);
PowerMockito.stub(PowerMockito.method(MultitenantUtils.class, "getTenantAwareUsername"))
.toReturn(TENANT_AWARE_USERNAME);
PowerMockito.stub(PowerMockito.method(CarbonContext.class, "getThreadLocalCarbonContext"))
.toReturn(Mockito.mock(CarbonContext.class, Mockito.RETURNS_MOCKS));
Mockito.when(deviceAccessAuthorizationService.isDeviceAdminUser()).thenReturn(true);
Response response = this.deviceManagementService
.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
DEFAULT_STATUS, 1, null, null, 10, 5);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
response = this.deviceManagementService
.getDevices(null, TEST_DEVICE_TYPE, null, DEFAULT_USERNAME, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
DEFAULT_STATUS, 1, null, null, 10, 5);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
}
示例14: testGetDevicesWhenUserIsUnauthorized
import org.wso2.carbon.utils.multitenancy.MultitenantUtils; //导入依赖的package包/类
@Test(description = "Testing get devices when user is unauthorized.")
public void testGetDevicesWhenUserIsUnauthorized() throws Exception {
PowerMockito.spy(MultitenantUtils.class);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceAccessAuthorizationService"))
.toReturn(this.deviceAccessAuthorizationService);
PowerMockito.stub(PowerMockito.method(CarbonContext.class, "getThreadLocalCarbonContext"))
.toReturn(Mockito.mock(CarbonContext.class, Mockito.RETURNS_MOCKS));
PowerMockito.doReturn(TENANT_AWARE_USERNAME)
.when(MultitenantUtils.class, "getTenantAwareUsername", DEFAULT_USERNAME);
PowerMockito.doReturn("[email protected]").when(MultitenantUtils.class, "getTenantAwareUsername", "newuser");
Mockito.when(this.deviceAccessAuthorizationService.isDeviceAdminUser()).thenReturn(false);
Response response = this.deviceManagementService
.getDevices(null, TEST_DEVICE_TYPE, "newuser", null, DEFAULT_ROLE, DEFAULT_OWNERSHIP, DEFAULT_STATUS, 1,
null, null, 10, 5);
Assert.assertEquals(response.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode());
Mockito.reset(this.deviceAccessAuthorizationService);
}
示例15: testGetDevicesWithModifiedSince
import org.wso2.carbon.utils.multitenancy.MultitenantUtils; //导入依赖的package包/类
@Test(description = "Testing get devices with IF-Modified-Since")
public void testGetDevicesWithModifiedSince() {
String ifModifiedSince = new SimpleDateFormat(DEFAULT_DATE_FORMAT).format(new Date());
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceManagementService"))
.toReturn(this.deviceManagementProviderService);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class, "getDeviceAccessAuthorizationService"))
.toReturn(this.deviceAccessAuthorizationService);
PowerMockito.stub(PowerMockito.method(MultitenantUtils.class, "getTenantAwareUsername"))
.toReturn(TENANT_AWARE_USERNAME);
PowerMockito.stub(PowerMockito.method(CarbonContext.class, "getThreadLocalCarbonContext"))
.toReturn(Mockito.mock(CarbonContext.class, Mockito.RETURNS_MOCKS));
Response response = this.deviceManagementService
.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
DEFAULT_STATUS, 1, null, ifModifiedSince, 10, 5);
Assert.assertEquals(response.getStatus(), Response.Status.NOT_MODIFIED.getStatusCode());
response = this.deviceManagementService
.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
DEFAULT_STATUS, 1, null, ifModifiedSince, 10, 5);
Assert.assertEquals(response.getStatus(), Response.Status.NOT_MODIFIED.getStatusCode());
response = this.deviceManagementService
.getDevices(null, TEST_DEVICE_TYPE, DEFAULT_USERNAME, null, DEFAULT_ROLE, DEFAULT_OWNERSHIP,
DEFAULT_STATUS, 1, null, "ErrorModifiedSince", 10, 5);
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
}