本文整理汇总了Java中org.wso2.carbon.base.MultitenantConstants类的典型用法代码示例。如果您正苦于以下问题:Java MultitenantConstants类的具体用法?Java MultitenantConstants怎么用?Java MultitenantConstants使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MultitenantConstants类属于org.wso2.carbon.base包,在下文中一共展示了MultitenantConstants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTenantDomain
import org.wso2.carbon.base.MultitenantConstants; //导入依赖的package包/类
private String getTenantDomain(HttpServletRequest request) throws FrameworkException {
String tenantDomain = request.getParameter(FrameworkConstants.RequestParams.TENANT_DOMAIN);
if (tenantDomain == null || tenantDomain.isEmpty() || "null".equals(tenantDomain)) {
String tenantId = request.getParameter(FrameworkConstants.RequestParams.TENANT_ID);
if (tenantId != null && !"-1234".equals(tenantId)) {
try {
Tenant tenant = FrameworkServiceComponent.getRealmService().getTenantManager()
.getTenant(Integer.parseInt(tenantId));
if (tenant != null) {
tenantDomain = tenant.getDomain();
}
} catch (Exception e) {
throw new FrameworkException(e.getMessage(), e);
}
} else {
tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
}
}
return tenantDomain;
}
示例2: addToCache
import org.wso2.carbon.base.MultitenantConstants; //导入依赖的package包/类
/**
* Add a cache entry.
*
* @param key Key which cache entry is indexed.
* @param entry Actual object where cache entry is placed.
*/
public void addToCache(AuthenticationContextCacheKey key, AuthenticationContextCacheEntry entry) {
super.addToCache(key, entry);
if (isTemporarySessionDataPersistEnabled) {
int tenantId = MultitenantConstants.INVALID_TENANT_ID;
String tenantDomain = entry.getContext().getTenantDomain();
if (tenantDomain != null) {
tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
}
if (entry.getContext() != null && entry.getContext().getProperties() != null) {
Iterator it = entry.getContext().getProperties().entrySet().iterator();
while (it.hasNext())
{
Map.Entry<String, Object> item = (Map.Entry<String, Object>) it.next();
if (!(item.getValue() instanceof Serializable)) {
it.remove();
}
}
SessionDataStore.getInstance().storeSessionData(key.getContextId(), AUTHENTICATION_CONTEXT_CACHE_NAME,
entry, tenantId);
}
}
}
示例3: getUserFromUserName
import org.wso2.carbon.base.MultitenantConstants; //导入依赖的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;
}
示例4: isUserStoreCaseSensitive
import org.wso2.carbon.base.MultitenantConstants; //导入依赖的package包/类
/**
* Check the case sensitivity of the user store.
*
* @param userStoreDomain user store domain
* @param tenantId tenant id of the user store
* @return
*/
public static boolean isUserStoreCaseSensitive(String userStoreDomain, int tenantId) {
boolean isUsernameCaseSensitive = true;
if (tenantId == MultitenantConstants.INVALID_TENANT_ID) {
//this is to handle federated scenarios
return true;
}
try {
org.wso2.carbon.user.core.UserStoreManager userStoreManager = (org.wso2.carbon.user.core
.UserStoreManager) IdentityTenantUtil.getRealmService()
.getTenantUserRealm(tenantId).getUserStoreManager();
org.wso2.carbon.user.core.UserStoreManager userAvailableUserStoreManager = userStoreManager
.getSecondaryUserStoreManager(userStoreDomain);
return isUserStoreCaseSensitive(userAvailableUserStoreManager);
} catch (UserStoreException e) {
if (log.isDebugEnabled()) {
log.debug("Error while reading user store property CaseInsensitiveUsername. Considering as case " +
"sensitive.");
}
}
return isUsernameCaseSensitive;
}
示例5: getUserstoreUsernameCaseSensitiveData
import org.wso2.carbon.base.MultitenantConstants; //导入依赖的package包/类
@DataProvider
public Object[][] getUserstoreUsernameCaseSensitiveData() {
try {
when(mockTenantManager.getTenantId(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)).thenReturn
(MultitenantConstants.SUPER_TENANT_ID);
when(mockTenantManager.getTenantId("wso2.com")).thenReturn(1);
when(mockTenantManager.getTenantId("none.com")).thenReturn(MultitenantConstants.INVALID_TENANT_ID);
when(mockRealmService.getTenantUserRealm(anyInt())).thenReturn(mockUserRealm);
when(mockUserStoreManager.getSecondaryUserStoreManager(anyString())).thenReturn(mockUserStoreManager);
} catch (UserStoreException e) {
// Ignored, since this is a mock behaviour
}
return new Object[][]{
{"admin", "false", true},
{"[email protected]", "false", true},
{"[email protected]", "false", true},
{"foo/[email protected]", null, true},
{"[email protected]", "true", true},
{"sec/[email protected]", "true", false},
};
}
示例6: getIdentityProviderIdentifier
import org.wso2.carbon.base.MultitenantConstants; //导入依赖的package包/类
/**
* @param dbConnection
* @param idPName
* @param tenantId
* @return
* @throws SQLException
* @throws IdentityProviderManagementException
*/
private int getIdentityProviderIdentifier(Connection dbConnection, String idPName, int tenantId)
throws SQLException, IdentityProviderManagementException {
String sqlStmt = null;
PreparedStatement prepStmt = null;
ResultSet rs = null;
try {
sqlStmt = IdPManagementConstants.SQLQueries.GET_IDP_BY_NAME_SQL;
prepStmt = dbConnection.prepareStatement(sqlStmt);
prepStmt.setInt(1, tenantId);
prepStmt.setInt(2, MultitenantConstants.SUPER_TENANT_ID);
prepStmt.setString(3, idPName);
rs = prepStmt.executeQuery();
if (rs.next()) {
return rs.getInt("ID");
} else {
throw new IdentityProviderManagementException("Invalid Identity Provider Name "
+ idPName);
}
} finally {
IdentityDatabaseUtil.closeAllConnections(null, rs, prepStmt);
}
}
示例7: getConfiguration
import org.wso2.carbon.base.MultitenantConstants; //导入依赖的package包/类
/**
* Read configurations from application-authentication.xml for given authenticator.
*
* @param context Authentication Context.
* @param authenticatorName Name of the Authenticator.
* @param configName Name of the config.
* @return Config value.
* @throws AuthenticationFailedException
*/
public static String getConfiguration(AuthenticationContext context, String authenticatorName, String configName)
throws AuthenticationFailedException {
String configValue = null;
Object propertiesFromLocal = context.getProperty(IdentityHelperConstants.GET_PROPERTY_FROM_REGISTRY);
String tenantDomain = context.getTenantDomain();
if ((propertiesFromLocal != null || MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) &&
getSMSParameters().containsKey(configName)) {
configValue = getSMSParameters().get(configName);
} else if ((context.getProperty(configName)) != null) {
configValue = String.valueOf(context.getProperty(configName));
}
if (log.isDebugEnabled()) {
log.debug("Config value for key " + configName + " for tenant " + tenantDomain + " : " +
configValue);
}
return configValue;
}
示例8: initializeCarbonContext
import org.wso2.carbon.base.MultitenantConstants; //导入依赖的package包/类
private void initializeCarbonContext() {
if (System.getProperty("carbon.home") == null) {
File file = new File("src/test/resources/carbon-home");
if (file.exists()) {
System.setProperty("carbon.home", file.getAbsolutePath());
}
file = new File("../resources/carbon-home");
if (file.exists()) {
System.setProperty("carbon.home", file.getAbsolutePath());
}
file = new File("../../resources/carbon-home");
if (file.exists()) {
System.setProperty("carbon.home", file.getAbsolutePath());
}
file = new File("../../../resources/carbon-home");
if (file.exists()) {
System.setProperty("carbon.home", file.getAbsolutePath());
}
}
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants
.SUPER_TENANT_DOMAIN_NAME);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
}
示例9: init
import org.wso2.carbon.base.MultitenantConstants; //导入依赖的package包/类
@BeforeClass
public void init() throws NoSuchFieldException {
bstAuthenticator = new BSTAuthenticator();
properties = new Properties();
headersField = org.apache.coyote.Request.class.getDeclaredField("headers");
headersField.setAccessible(true);
oAuth2TokenValidationService = Mockito
.mock(OAuth2TokenValidationService.class, Mockito.CALLS_REAL_METHODS);
oAuth2ClientApplicationDTO = Mockito
.mock(OAuth2ClientApplicationDTO.class, Mockito.CALLS_REAL_METHODS);
OAuth2TokenValidationResponseDTO authorizedValidationResponse = new OAuth2TokenValidationResponseDTO();
authorizedValidationResponse.setValid(true);
authorizedValidationResponse.setAuthorizedUser("[email protected]" + MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
Mockito.doReturn(oAuth2ClientApplicationDTO).when(oAuth2TokenValidationService)
.findOAuthConsumerIfTokenIsValid(Mockito.any());
oAuth2ClientApplicationDTO.setAccessTokenValidationResponse(authorizedValidationResponse);
AuthenticatorFrameworkDataHolder.getInstance().setOAuth2TokenValidationService(oAuth2TokenValidationService);
}
示例10: testRequestCertificateVerificationHeader
import org.wso2.carbon.base.MultitenantConstants; //导入依赖的package包/类
@Test(description = "This test case tests the behaviour of the CertificateAuthenticator for Certification "
+ "Verification Header requests")
public void testRequestCertificateVerificationHeader()
throws CertificateEncodingException, IOException, CMSException, NoSuchFieldException,
IllegalAccessException {
Assert.assertTrue(certificateAuthenticator.canHandle(certificationVerificationRequest),
"canHandle method returned false for a request with all the required header");
AuthenticationInfo authenticationInfo = certificateAuthenticator
.authenticate(certificationVerificationRequest, null);
Assert.assertNotNull(authenticationInfo, "Authentication Info from Certificate Authenticator is null");
Assert.assertNull(authenticationInfo.getTenantDomain(), "Authentication got passed without proper certificate");
authenticationInfo = certificateAuthenticator.authenticate(certificationVerificationRequest, null);
Assert.assertNotNull(authenticationInfo, "Authentication Info from Certificate Authenticator is null");
Assert.assertEquals(authenticationInfo.getTenantDomain(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME,
"Authentication failed for a valid request with " + CERTIFICATE_VERIFICATION_HEADER + " header");
}
示例11: testMutalAuthHeaderRequest
import org.wso2.carbon.base.MultitenantConstants; //导入依赖的package包/类
@Test(description = "This test case tests the behaviour of the Certificate Authenticator for the requests with "
+ "Mutal Auth Header")
public void testMutalAuthHeaderRequest() {
Assert.assertTrue(certificateAuthenticator.canHandle(mutalAuthHeaderRequest),
"canHandle method returned false for a request with all the required header");
AuthenticationInfo authenticationInfo = certificateAuthenticator.authenticate(mutalAuthHeaderRequest, null);
Assert.assertNotNull(authenticationInfo, "Authentication Info from Certificate Authenticator is null");
Assert.assertEquals(authenticationInfo.getMessage(), "No client certificate is present",
"Authentication got passed without proper certificate");
X509Certificate[] x509Certificates = new X509Certificate[1];
x509Certificates[0] = X509certificate;
mutalAuthHeaderRequest.setAttribute(CLIENT_CERTIFICATE_ATTRIBUTE, x509Certificates);
authenticationInfo = certificateAuthenticator.authenticate(mutalAuthHeaderRequest, null);
Assert.assertNotNull(authenticationInfo, "Authentication Info from Certificate Authenticator is null");
Assert.assertEquals(authenticationInfo.getTenantDomain(), MultitenantConstants.SUPER_TENANT_DOMAIN_NAME,
"Authentication failed even with proper certificate");
}
示例12: testPublishEventsWithNullPayload
import org.wso2.carbon.base.MultitenantConstants; //导入依赖的package包/类
@Test(description = "Test publish events with null payload.")
public void testPublishEventsWithNullPayload() {
PowerMockito.stub(PowerMockito.method(PrivilegedCarbonContext.class, "getThreadLocalCarbonContext"))
.toReturn(this.privilegedCarbonContext);
Mockito.when(this.privilegedCarbonContext.getTenantDomain())
.thenReturn(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
Map<String, Object> payload = null;
Response response = this.deviceAgentService.publishEvents(payload, TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
"The response status should be 400");
List<Object> payloadList = null;
Response response2 = this.deviceAgentService.publishEvents(payloadList, TEST_DEVICE_TYPE,
TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response2, "Response should not be null");
Assert.assertEquals(response2.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
"The response status should be 400");
}
示例13: testPublishEventsWithoutAuthorization
import org.wso2.carbon.base.MultitenantConstants; //导入依赖的package包/类
@Test(description = "Test publish events with no device access authorization.")
public void testPublishEventsWithoutAuthorization() throws DeviceAccessAuthorizationException {
PowerMockito.stub(PowerMockito.method(PrivilegedCarbonContext.class, "getThreadLocalCarbonContext"))
.toReturn(this.privilegedCarbonContext);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class,
"getDeviceAccessAuthorizationService")).toReturn(this.deviceAccessAuthorizationService);
Mockito.when(this.deviceAccessAuthorizationService.isUserAuthorized(Mockito.any(DeviceIdentifier.class)))
.thenReturn(false);
Mockito.when(this.privilegedCarbonContext.getTenantDomain())
.thenReturn(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
Map<String, Object> payload = new HashMap<>();
Response response = this.deviceAgentService.publishEvents(payload, TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(),
"The response status should be 401");
List<Object> payloadList = new ArrayList<>();
Response response2 = this.deviceAgentService.publishEvents(payloadList, TEST_DEVICE_TYPE,
TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response2, "Response should not be null");
Assert.assertEquals(response2.getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(),
"The response status should be 401");
Mockito.reset(this.deviceAccessAuthorizationService);
}
示例14: testPublishEventsWithDeviceAccessAuthorizationException
import org.wso2.carbon.base.MultitenantConstants; //导入依赖的package包/类
@Test(description = "Test publish events when device access authorization exception is thrown.")
public void testPublishEventsWithDeviceAccessAuthorizationException() throws DeviceAccessAuthorizationException {
PowerMockito.stub(PowerMockito.method(PrivilegedCarbonContext.class, "getThreadLocalCarbonContext"))
.toReturn(this.privilegedCarbonContext);
PowerMockito.stub(PowerMockito.method(DeviceMgtAPIUtils.class,
"getDeviceAccessAuthorizationService")).toReturn(this.deviceAccessAuthorizationService);
Mockito.when(this.deviceAccessAuthorizationService.isUserAuthorized(Mockito.any(DeviceIdentifier.class)))
.thenThrow(new DeviceAccessAuthorizationException());
Mockito.when(this.privilegedCarbonContext.getTenantDomain())
.thenReturn(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
Map<String, Object> payload = new HashMap<>();
Response response = this.deviceAgentService.publishEvents(payload, TEST_DEVICE_TYPE, TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response, "Response should not be null");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500");
List<Object> payloadList = new ArrayList<>();
Response response2 = this.deviceAgentService.publishEvents(payloadList, TEST_DEVICE_TYPE,
TEST_DEVICE_IDENTIFIER);
Assert.assertNotNull(response2, "Response should not be null");
Assert.assertEquals(response2.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500");
Mockito.reset(this.deviceAccessAuthorizationService);
}
示例15: setUpCarbonHome
import org.wso2.carbon.base.MultitenantConstants; //导入依赖的package包/类
private void setUpCarbonHome() {
if (System.getProperty("carbon.home") == null) {
File file = new File("src/test/resources/carbon-home");
if (file.exists()) {
System.setProperty("carbon.home", file.getAbsolutePath());
}
file = new File("carbon-home");
if (file.exists()) {
System.setProperty("carbon.home", file.getAbsolutePath());
}
file = new File("../../resources/carbon-home");
if (file.exists()) {
System.setProperty("carbon.home", file.getAbsolutePath());
}
file = new File("../../../resources/carbon-home");
if (file.exists()) {
System.setProperty("carbon.home", file.getAbsolutePath());
}
}
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants
.SUPER_TENANT_DOMAIN_NAME);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
}