Skip to content

Commit

Permalink
按照xdef:order-attr排序时增加类型转换
Browse files Browse the repository at this point in the history
  • Loading branch information
entropy-cloud committed Dec 27, 2023
1 parent fd942e5 commit bacfb5c
Show file tree
Hide file tree
Showing 9 changed files with 1,272 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import io.nop.auth.core.model._gen._DataAuthModel;

public class DataAuthModel extends _DataAuthModel{
public DataAuthModel(){
public class DataAuthModel extends _DataAuthModel {
public DataAuthModel() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import io.nop.api.core.auth.ISecurityContext;
import io.nop.api.core.auth.IUserContext;
import io.nop.api.core.beans.FilterBeanConstants;
import io.nop.api.core.beans.TreeBean;
import io.nop.api.core.exceptions.NopException;
import io.nop.auth.core.AuthCoreConstants;
import io.nop.auth.core.model._gen._ObjDataAuthModel;
Expand Down Expand Up @@ -38,24 +37,19 @@ public boolean isPermitted(String action, Object entity, ISecurityContext contex

IUserContext userContext = context.getUserContext();

int priority = Integer.MAX_VALUE;
boolean hasRoleAuth = false;
for (RoleDataAuthModel roleAuth : this.getRoleAuths()) {
String roleId = roleAuth.getRoleId();
if (!userContext.isUserInRole(roleId)) {
continue;
}

if (roleAuth.getCheck() != null && !roleAuth.getCheck().passConditions(scope)) {
return false;
}

if (roleAuth.getPriority() > priority)
if (userContext.isUserInRole(roleId)) {
hasRoleAuth = true;
if (roleAuth.getCheck() != null && !roleAuth.getCheck().passConditions(scope)) {
return false;
}
break;

priority = roleAuth.getPriority();
}
}

return priority != Integer.MAX_VALUE;
return hasRoleAuth;
}

public XNode getFilter(String action, ISecurityContext context) {
Expand All @@ -71,30 +65,24 @@ public XNode getFilter(String action, ISecurityContext context) {

boolean hasRoleAuth = false;

int priority = Integer.MAX_VALUE;
for (RoleDataAuthModel roleAuth : this.getRoleAuths()) {
String roleId = roleAuth.getRoleId();
if (!userContext.isUserInRole(roleId)) {
continue;
}

hasRoleAuth = true;

if (roleAuth.getFilter() != null) {
XNode node = roleAuth.getFilter().generateNode(scope);
if (node != null) {
if (node.isDummyNode()) {
filter.appendChildren(node.detachChildren());
} else {
filter.appendChild(node);
String roleId = roleAuth.getRoleId();
if (userContext.isUserInRole(roleId)) {
hasRoleAuth = true;

if (roleAuth.getFilter() != null) {
XNode node = roleAuth.getFilter().generateNode(scope);
if (node != null) {
if (node.isDummyNode()) {
filter.appendChildren(node.detachChildren());
} else {
filter.appendChild(node);
}
}
}
}

if (roleAuth.getPriority() > priority)
break;

priority = roleAuth.getPriority();
}
}

if (!hasRoleAuth)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,32 @@
package io.nop.core.lang.utils;

import io.nop.commons.collections.SafeOrderedComparator;
import io.nop.commons.type.StdDataType;
import io.nop.core.lang.xml.XNode;

import java.util.Comparator;

public class XNodeAttrComparator implements Comparator<XNode> {
private final String attrName;
private final StdDataType dataType;

public XNodeAttrComparator(String attrName) {
public XNodeAttrComparator(String attrName, StdDataType dataType) {
this.attrName = attrName;
this.dataType = dataType;
}

public XNodeAttrComparator(String attrName) {
this(attrName, null);
}

@Override
public int compare(XNode o1, XNode o2) {
Object v1 = o1.getAttr(attrName);
Object v2 = o2.getAttr(attrName);
if (dataType != null) {
v1 = dataType.convert(v1);
v2 = dataType.convert(v2);
}
return SafeOrderedComparator.DEFAULT.compare(v1, v2);
}

Expand Down
Loading

0 comments on commit bacfb5c

Please sign in to comment.