本文整理汇总了Java中org.wso2.carbon.context.CarbonContext.getUsername方法的典型用法代码示例。如果您正苦于以下问题:Java CarbonContext.getUsername方法的具体用法?Java CarbonContext.getUsername怎么用?Java CarbonContext.getUsername使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.wso2.carbon.context.CarbonContext
的用法示例。
在下文中一共展示了CarbonContext.getUsername方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeMySession
import org.wso2.carbon.context.CarbonContext; //导入方法依赖的package包/类
/**
*
* Terminates the requested session, after validating whether the session belongs to the logged in user.
*
* @param sessionId
* @return
*/
public boolean removeMySession(String sessionId) {
if (StringUtils.isBlank(sessionId)) {
return false;
}
SessionContext sessionContext = FrameworkUtils.getSessionContextFromCache(sessionId);
// Check whether the session belongs to the logged in user.
CarbonContext carbonContext = CarbonContext.getThreadLocalCarbonContext();
String username = carbonContext.getUsername();
// Extract the user store domain if there is any or set to 'PRIMARY'.
String userStoreDomain = "PRIMARY";
String[] usernameTokens = username.split("/");
if (usernameTokens.length > 1) {
userStoreDomain = usernameTokens[0];
username = usernameTokens[1];
}
AuthenticatedUser authenticatedUser = (AuthenticatedUser) sessionContext
.getProperty(FrameworkConstants.AUTHENTICATED_USER);
if (username.equals(authenticatedUser.getUserName())
&& userStoreDomain.equals(authenticatedUser.getUserStoreDomain())
&& carbonContext.getTenantDomain().equals(authenticatedUser.getTenantDomain())) {
terminateSession(sessionContext, sessionId);
} else { // TODO : Handle federated scenario.
log.warn(String.format("Trying to terminate a session which does not belong to logged in user (%s). " +
"This might be an attempt for a security breach", username));
return false;
}
return true;
}