use of com.mendmix.common.constants.PermissionLevel in project jeesuite-libs by vakinge.
the class SecurityDelegating method doAuthorization.
/**
* 鉴权
* @param userId
* @param uri
*/
public static UserSession doAuthorization(String method, String uri) throws UnauthorizedException, ForbiddenAccessException {
UserSession session = getCurrentSession();
// 续租
if (session != null) {
long interval = System.currentTimeMillis() - getInstance().sessionManager.getUpdateTime(session);
if (interval > SESSION_INTERVAL_MILLS) {
getInstance().sessionManager.storageLoginSession(session);
}
}
boolean isAdmin = session != null && session.getUser() != null && session.getUser().isAdmin();
if (!isAdmin && !getInstance().resourceManager.isAnonymous(uri)) {
if (session == null || session.isAnonymous()) {
throw new UnauthorizedException();
}
if (getInstance().decisionProvider.apiAuthzEnabled()) {
String permissionKey = ApiPermssionCheckHelper.buildPermissionKey(method, uri);
PermissionLevel permissionLevel = ApiPermssionCheckHelper.matchPermissionLevel(getInstance().resourceManager, permissionKey);
// 如果需鉴权
if (permissionLevel == PermissionLevel.PermissionRequired) {
List<String> permissions = getInstance().resourceManager.getUserPermissions(session);
if (!ApiPermssionCheckHelper.checkPermissions(getInstance().resourceManager, permissionKey, permissions)) {
throw new ForbiddenAccessException();
}
}
}
}
//
if (session != null) {
CurrentRuntimeContext.setAuthUser(session.getUser());
if (StringUtils.isNotBlank(session.getTenantId())) {
CurrentRuntimeContext.setTenantId(session.getTenantId());
}
}
return session;
}
Aggregations