本文整理汇总了Java中org.wso2.carbon.utils.multitenancy.MultitenantConstants.INVALID_TENANT_ID属性的典型用法代码示例。如果您正苦于以下问题:Java MultitenantConstants.INVALID_TENANT_ID属性的具体用法?Java MultitenantConstants.INVALID_TENANT_ID怎么用?Java MultitenantConstants.INVALID_TENANT_ID使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.wso2.carbon.utils.multitenancy.MultitenantConstants
的用法示例。
在下文中一共展示了MultitenantConstants.INVALID_TENANT_ID属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTenantId
public static int getTenantId(String tenantDomain) throws IdentityRuntimeException {
int tenantId = MultitenantConstants.INVALID_TENANT_ID;
try {
tenantId = realmService.getTenantManager().getTenantId(tenantDomain);
} catch (UserStoreException e) {
// Ideally user.core should be throwing an unchecked exception, in which case no need to wrap at this
// level once more without adding any valuable contextual information. Because we don't have exception
// enrichment properly implemented, we are appending the error message from the UserStoreException to the
// new message
throw IdentityRuntimeException.error("Error occurred while retrieving tenantId for tenantDomain: " +
tenantDomain + e.getMessage(), e);
}
if(tenantId == MultitenantConstants.INVALID_TENANT_ID){
throw IdentityRuntimeException.error("Invalid tenant domain " + tenantDomain);
} else {
return tenantId;
}
}
示例2: getTenantIdOfUser
/**
* 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;
}
}
示例3: search
public ResourceData[] search(Map<String, String> query) throws RegistryException {
int tenantId;
try {
tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
} catch (Exception ignored) {
tenantId = MultitenantConstants.SUPER_TENANT_ID;
}
if (tenantId == MultitenantConstants.INVALID_TENANT_ID) {
tenantId = MultitenantConstants.SUPER_TENANT_ID;
}
return search(tenantId, query);
}
示例4: append
protected synchronized void append(LoggingEvent loggingEvent) {
int tenantId = AccessController.doPrivileged(new PrivilegedAction<Integer>() {
public Integer run() {
return PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
}
});
if (tenantId == MultitenantConstants.INVALID_TENANT_ID) {
String tenantDomain = TenantDomainSetter.getTenantDomain();
if (tenantDomain != null && !tenantDomain.equals("")) {
try {
tenantId = getTenantIdForDomain(tenantDomain);
} catch (UserStoreException e) {
log.warn("Cannot find tenant id for the given tenant domain.", e);
//Ignore this exception.
}
}
}
String appName = CarbonContext.getThreadLocalCarbonContext().getApplicationName();
if (appName == null) {
appName = TenantDomainSetter.getServiceName();
}
Logger logger = Logger.getLogger(loggingEvent.getLoggerName());
TenantAwareLoggingEvent tenantEvent;
if (loggingEvent.getThrowableInformation() != null) {
tenantEvent = new TenantAwareLoggingEvent(loggingEvent.fqnOfCategoryClass, logger,
loggingEvent.timeStamp, loggingEvent.getLevel(), loggingEvent.getMessage(),
loggingEvent.getThrowableInformation().getThrowable());
} else {
tenantEvent = new TenantAwareLoggingEvent(loggingEvent.fqnOfCategoryClass, logger,
loggingEvent.timeStamp, loggingEvent.getLevel(), loggingEvent.getMessage(),
null);
}
tenantEvent.setTenantId(Integer.toString(tenantId));
tenantEvent.setServiceName(appName);
if (circularBuffer != null) {
circularBuffer.append(tenantEvent);
}
}
示例5: getLoggedInUserName
/**
* Return current user name
*
* @return username
*/
private String getLoggedInUserName() {
String userName = "";
if (CarbonContext.getThreadLocalCarbonContext().getTenantId() > MultitenantConstants.INVALID_TENANT_ID) {
userName = CarbonContext.getThreadLocalCarbonContext().getUsername() + "!"
+ CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
} else {
userName = CarbonContext.getThreadLocalCarbonContext().getUsername();
}
return userName;
}
示例6: getTenantIdOfUser
/**
* Returns tenant Id given the user name or returns
* {@link MultitenantConstants#INVALID_TENANT_ID} if none can be found.
*
* @param username The username of the user.
* @return The tenant ID.
* @throws UserStoreException
*/
private int getTenantIdOfUser(String username) throws UserStoreException {
int tenantId = MultitenantConstants.INVALID_TENANT_ID;
String domainName = MultitenantUtils.getTenantDomain(username);
if (domainName != null) {
TenantManager tenantManager =
AuthenticationServiceDataHolder.getInstance().getRealmService()
.getTenantManager();
tenantId = tenantManager.getTenantId(domainName);
}
return tenantId;
}
示例7: getCurrentUser
/**
* Get current user's username.
* @return The user name.
*/
private String getCurrentUser() {
String userName;
if (CarbonContext.getThreadLocalCarbonContext().getTenantId() > MultitenantConstants.INVALID_TENANT_ID) {
userName = CarbonContext.getThreadLocalCarbonContext().getUsername() + "!"
+ CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
} else {
userName = CarbonContext.getThreadLocalCarbonContext().getUsername();
}
return userName.trim();
}
示例8: updateApplication
@Override
public void updateApplication(ServiceProvider serviceProvider, String tenantDomain)
throws IdentityApplicationManagementException {
Connection connection = IdentityDatabaseUtil.getDBConnection();
int applicationId = serviceProvider.getApplicationID();
int tenantID = MultitenantConstants.INVALID_TENANT_ID;
if (tenantDomain != null) {
tenantID = IdentityTenantUtil.getTenantId(tenantDomain);
}
try {
if (ApplicationManagementServiceComponent.getFileBasedSPs().containsKey(
serviceProvider.getApplicationName())) {
throw new IdentityApplicationManagementException(
"Application with the same name laoded from the file system.");
}
// update basic information of the application.
// you can change application name, description, isSasApp...
updateBasicApplicationData(serviceProvider, connection);
updateInboundProvisioningConfiguration(applicationId,
serviceProvider.getInboundProvisioningConfig(), connection);
// delete all in-bound authentication requests.
deleteInboundAuthRequestConfiguration(serviceProvider.getApplicationID(), connection);
// update all in-bound authentication requests.
updateInboundAuthRequestConfiguration(serviceProvider.getApplicationID(),
serviceProvider.getInboundAuthenticationConfig(), connection);
// delete local and out-bound authentication configuration.
deleteLocalAndOutboundAuthenticationConfiguration(applicationId, connection);
// update local and out-bound authentication configuration.
updateLocalAndOutboundAuthenticationConfiguration(serviceProvider.getApplicationID(),
serviceProvider.getLocalAndOutBoundAuthenticationConfig(), connection);
deleteRequestPathAuthenticators(applicationId, connection);
updateRequestPathAuthenticators(applicationId,
serviceProvider.getRequestPathAuthenticatorConfigs(), connection);
deteClaimConfiguration(applicationId, connection);
updateClaimConfiguration(serviceProvider.getApplicationID(),
serviceProvider.getClaimConfig(), applicationId, connection);
deleteOutboundProvisioningConfiguration(applicationId, connection);
updateOutboundProvisioningConfiguration(applicationId,
serviceProvider.getOutboundProvisioningConfig(), connection);
deletePermissionAndRoleConfiguration(applicationId, connection);
updatePermissionAndRoleConfiguration(serviceProvider.getApplicationID(),
serviceProvider.getPermissionAndRoleConfig(), connection);
deleteAssignedPermissions(connection, serviceProvider.getApplicationName(),
serviceProvider.getPermissionAndRoleConfig().getPermissions());
if (serviceProvider.getSpProperties() != null) {
updateServiceProviderProperties(connection, applicationId,
Arrays.asList(serviceProvider.getSpProperties()), tenantID);
}
if (!connection.getAutoCommit()) {
connection.commit();
}
} catch (SQLException | UserStoreException e) {
try {
if (connection != null) {
connection.rollback();
}
} catch (SQLException e1) {
throw new IdentityApplicationManagementException(
"Failed to update service provider " + applicationId, e);
}
throw new IdentityApplicationManagementException("Failed to update service provider "
+ applicationId, e);
} finally {
IdentityApplicationManagementUtil.closeConnection(connection);
}
}
示例9: buildLogoutRequest
public LogoutRequest buildLogoutRequest(String subject, String sessionId, String reason, String destination,
String nameIDFormat, String tenantDomain, String
requestsigningAlgorithmUri, String requestDigestAlgoUri) throws
IdentityException {
LogoutRequest logoutReq = new LogoutRequestBuilder().buildObject();
logoutReq.setID(SAMLSSOUtil.createID());
DateTime issueInstant = new DateTime();
logoutReq.setIssueInstant(issueInstant);
logoutReq.setIssuer(SAMLSSOUtil.getIssuerFromTenantDomain(tenantDomain));
logoutReq.setNotOnOrAfter(new DateTime(issueInstant.getMillis() + 5 * 60 * 1000));
NameID nameId = new NameIDBuilder().buildObject();
nameId.setFormat(nameIDFormat);
nameId.setValue(subject);
logoutReq.setNameID(nameId);
SessionIndex sessionIndex = new SessionIndexBuilder().buildObject();
sessionIndex.setSessionIndex(sessionId);
logoutReq.getSessionIndexes().add(sessionIndex);
if (destination != null) {
logoutReq.setDestination(destination);
}
logoutReq.setReason(reason);
int tenantId;
if (StringUtils.isEmpty(tenantDomain) || "null".equals(tenantDomain)) {
tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
tenantId = MultitenantConstants.SUPER_TENANT_ID;
} else {
try {
tenantId = SAMLSSOUtil.getRealmService().getTenantManager().getTenantId(tenantDomain);
} catch (UserStoreException e) {
throw IdentityException.error("Error occurred while retrieving tenant id from tenant domain", e);
}
if(MultitenantConstants.INVALID_TENANT_ID == tenantId) {
throw IdentityException.error("Invalid tenant domain - '" + tenantDomain + "'" );
}
}
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId);
SAMLSSOUtil.setSignature(logoutReq, requestsigningAlgorithmUri, requestDigestAlgoUri, new
SignKeyDataHolder(null));
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
return logoutReq;
}
示例10: buildLogoutResponse
public LogoutResponse buildLogoutResponse(String id, String status, String statMsg, String destination, boolean
isSignResponse, String tenantDomain, String responseSigningAlgorithmUri, String responseDigestAlgoUri)
throws IdentityException {
LogoutResponse logoutResp = new LogoutResponseBuilder().buildObject();
logoutResp.setID(SAMLSSOUtil.createID());
logoutResp.setInResponseTo(id);
logoutResp.setIssuer(SAMLSSOUtil.getIssuer());
logoutResp.setStatus(buildStatus(status, statMsg));
logoutResp.setIssueInstant(new DateTime());
logoutResp.setDestination(destination);
// Currently, does not sign the error response since this message pass through a url to the error page
if (isSignResponse && SAMLSSOConstants.StatusCodes.SUCCESS_CODE.equals(status)) {
int tenantId;
if (StringUtils.isEmpty(tenantDomain)) {
tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
tenantId = MultitenantConstants.SUPER_TENANT_ID;
} else {
try {
tenantId = SAMLSSOUtil.getRealmService().getTenantManager().getTenantId(tenantDomain);
} catch (UserStoreException e) {
throw IdentityException.error("Error occurred while retrieving tenant id from tenant domain", e);
}
if(MultitenantConstants.INVALID_TENANT_ID == tenantId) {
throw IdentityException.error("Invalid tenant domain - '" + tenantDomain + "'" );
}
}
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId);
SAMLSSOUtil.setSignature(logoutResp, responseSigningAlgorithmUri, responseDigestAlgoUri, new
SignKeyDataHolder(null));
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
return logoutResp;
}
示例11: checkValid
/**
* {@inheritDoc} Authenticates the user against carbon user store.
*/
@Override
public AuthenticationInfo checkValid(String username, String password) {
boolean isAuthenticated = false;
// Carbon kernel uses '@' to separate domain while MB uses '!'
String carbonCompliantUsername = username.replace(DOMAIN_NAME_SEPARATOR, "@");
AuthenticationInfo authenticationInfo = new AuthenticationInfo();
try {
PrivilegedCarbonContext.startTenantFlow();
int tenantId = getTenantIdOfUser(carbonCompliantUsername);
if (MultitenantConstants.INVALID_TENANT_ID != tenantId) {
if (username.contains(DOMAIN_NAME_SEPARATOR)) {
String tenantDomain = username.substring(username.indexOf(DOMAIN_NAME_SEPARATOR) + 1);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain);
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
} else {
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants
.SUPER_TENANT_DOMAIN_NAME);
}
UserRealm userRealm = AuthenticationServiceDataHolder.getInstance().getRealmService()
.getTenantUserRealm(tenantId);
UserStoreManager userStoreManager = userRealm.getUserStoreManager();
username = MultitenantUtils.getTenantAwareUsername(carbonCompliantUsername);
isAuthenticated = userStoreManager.authenticate(username, password);
authenticationInfo.setUsername(carbonCompliantUsername);
authenticationInfo.setTenantDomain(MultitenantUtils.getTenantDomain(carbonCompliantUsername));
} else {
logger.error(String.format("Access denied, unable to find a tenant for user name : %s", username));
}
} catch (UserStoreException e) {
String errorMsg = String.format("Unable to authenticate user : %s", username);
logger.error(errorMsg, e);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
authenticationInfo.setAuthenticated(isAuthenticated);
return authenticationInfo;
}