use of com.mendmix.common.model.AuthUser in project jeesuite-libs by vakinge.
the class SecurityDelegating method doAuthenticationForOauth2.
public static String doAuthenticationForOauth2(String type, String name, String password) {
AuthUser userInfo = getInstance().decisionProvider.validateUser(type, name, password);
String authCode = TokenGenerator.generate();
setTemporaryCacheValue(authCode, userInfo, 60);
return authCode;
}
use of com.mendmix.common.model.AuthUser in project jeesuite-libs by vakinge.
the class RequestHeaderBuilder method getHeaders.
public static Map<String, String> getHeaders() {
Map<String, String> headers = CurrentRuntimeContext.getCustomHeaders();
//
Map<String, String> appHeaders = null;
if (headerProvider != null)
appHeaders = headerProvider.headers();
if (appHeaders != null && !appHeaders.isEmpty()) {
headers.putAll(appHeaders);
}
if (!headers.containsKey(CustomRequestHeaders.HEADER_REQUEST_ID)) {
headers.put(CustomRequestHeaders.HEADER_REQUEST_ID, TokenGenerator.generate());
}
if (!headers.containsKey(CustomRequestHeaders.HEADER_INVOKE_TOKEN)) {
headers.put(CustomRequestHeaders.HEADER_INVOKE_TOKEN, TokenGenerator.generateWithSign());
}
headers.put(CustomRequestHeaders.HEADER_INVOKER_APP_ID, GlobalRuntimeContext.APPID);
// 登录用户
AuthUser currentUser = CurrentRuntimeContext.getCurrentUser();
if (currentUser != null) {
headers.put(CustomRequestHeaders.HEADER_AUTH_USER, currentUser.toEncodeString());
}
// 租户
String tenantId = CurrentRuntimeContext.getTenantId(false);
if (tenantId != null) {
headers.put(CustomRequestHeaders.HEADER_TENANT_ID, tenantId);
}
String clientType = CurrentRuntimeContext.getClientType();
if (clientType != null) {
headers.put(CustomRequestHeaders.HEADER_CLIENT_TYPE, clientType);
}
return headers;
}
use of com.mendmix.common.model.AuthUser in project jeesuite-libs by vakinge.
the class UserMockUtils method initMockContextIfOnCondition.
public static AuthUser initMockContextIfOnCondition() {
AuthUser authUser = CurrentRuntimeContext.getCurrentUser();
if (authUser == null && isEnabled()) {
CurrentRuntimeContext.setClientType(ResourceUtils.getProperty("mendmix.mock.context.clientType"));
CurrentRuntimeContext.setTenantId(ResourceUtils.getProperty("mendmix.mock.context.tenantId"));
CurrentRuntimeContext.setSystemId(ResourceUtils.getProperty("mendmix.mock.context.systemId"));
authUser = new AuthUser();
authUser.setId(ResourceUtils.getProperty("mendmix.mock.context.user.id", "1"));
authUser.setPrincipalType(ResourceUtils.getProperty("mendmix.mock.context.user.principalType", "staff"));
authUser.setPrincipalId(ResourceUtils.getProperty("mendmix.mock.context.user.principalId", "1"));
authUser.setName(ResourceUtils.getProperty("mendmix.mock.context.user.name", "mockuser"));
authUser.setType(ResourceUtils.getProperty("mendmix.mock.context.user.type"));
authUser.setDeptId(ResourceUtils.getProperty("mendmix.mock.context.user.deptId"));
authUser.setPostId(ResourceUtils.getProperty("mendmix.mock.context.user.postId"));
authUser.setAdmin(ResourceUtils.getBoolean("mendmix.mock.context.user.isAdmin"));
CurrentRuntimeContext.setAuthUser(authUser);
}
return authUser;
}
use of com.mendmix.common.model.AuthUser in project jeesuite-libs by vakinge.
the class CurrentRuntimeContext method addContextHeaders.
public static void addContextHeaders(Map<String, String> headers) {
String headerVal;
for (String headerName : contextHeaders) {
if (!headers.containsKey(headerName))
continue;
headerVal = headers.get(headerName);
if (headerVal != null) {
setContextVal(headerName, headerVal);
}
}
//
if (headers.containsKey(CustomRequestHeaders.HEADER_AUTH_USER)) {
headerVal = headers.get(CustomRequestHeaders.HEADER_AUTH_USER);
AuthUser user = AuthUser.decode(headerVal);
if (user != null) {
ThreadLocalContext.set(CustomRequestHeaders.HEADER_AUTH_USER, user);
}
}
}
use of com.mendmix.common.model.AuthUser in project jeesuite-libs by vakinge.
the class SqlRewriteHandler method handleTableDataPermission.
private Expression handleTableDataPermission(Expression originWhere, Table table, Map<String, String[]> dataMapping, boolean sharddingTenant) {
if (!dataPermMappings.containsKey(table.getName())) {
return originWhere;
}
Set<String> fieldNames;
Expression newExpression = originWhere;
String column;
String[] values;
Map<String, String> columnMapping = dataPermMappings.get(table.getName());
fieldNames = columnMapping.keySet();
boolean withSoftDelete = false;
boolean withPermiCondition = false;
for (String fieldName : fieldNames) {
if (fieldName.equals(softDeletePropName)) {
withSoftDelete = true;
continue;
}
if (sharddingTenant && fieldName.equals(tenantPropName)) {
column = tenantColumnName;
String currentTenantId = CurrentRuntimeContext.getTenantId();
if (currentTenantId == null)
throw new JeesuiteBaseException("无法获取当前租户ID");
values = new String[] { currentTenantId };
} else {
if (dataMapping == null || !dataMapping.containsKey(fieldName))
continue;
column = columnMapping.get(fieldName);
values = dataMapping.get(fieldName);
//
if (!withPermiCondition)
withPermiCondition = true;
}
// 如果某个匹配字段为空直接返回null,不在查询数据库
if (values == null || values.length == 0) {
EqualsTo equalsTo = new EqualsTo();
equalsTo.setLeftExpression(new Column(table, column));
equalsTo.setRightExpression(new StringValue("_PERMISSION_NOT_MATCH_"));
return equalsTo;
}
newExpression = handleColumnDataPermCondition(table, newExpression, column, values);
}
// 当前创建人
if (withPermiCondition && ownerColumnName != null) {
AuthUser currentUser = CurrentRuntimeContext.getCurrentUser();
if (currentUser != null) {
EqualsTo equalsTo = new EqualsTo();
equalsTo.setLeftExpression(new Column(table, ownerColumnName));
// TODO 需要按ID匹配否则出现同名
equalsTo.setRightExpression(new StringValue(currentUser.getName()));
//
newExpression = newExpression == null ? equalsTo : new OrExpression(new Parenthesis(newExpression), equalsTo);
}
}
// 软删除
if (withSoftDelete) {
EqualsTo equalsTo = new EqualsTo();
equalsTo.setLeftExpression(new Column(table, softDeleteColumnName));
equalsTo.setRightExpression(new StringValue(softDeleteFalseValue));
newExpression = newExpression == null ? equalsTo : new AndExpression(new Parenthesis(newExpression), equalsTo);
}
return newExpression;
}
Aggregations