|
@@ -4,14 +4,18 @@ import com.alibaba.fastjson.JSON;
|
|
|
import org.hswebframework.web.authorization.access.DataAccessConfig;
|
|
|
import org.hswebframework.web.authorization.builder.DataAccessConfigBuilder;
|
|
|
import org.hswebframework.web.authorization.builder.DataAccessConfigBuilderFactory;
|
|
|
-import org.hswebframework.web.authorization.simple.SimpleCustomDataAccessConfig;
|
|
|
-import org.hswebframework.web.authorization.simple.SimpleOwnCreatedDataAccessConfig;
|
|
|
+import org.hswebframework.web.authorization.simple.*;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
+import java.util.function.BiFunction;
|
|
|
+
|
|
|
+import static org.hswebframework.web.authorization.access.DataAccessConfig.DefaultType.*;
|
|
|
+import static org.hswebframework.web.authorization.access.DataAccessConfig.DefaultType.CUSTOM;
|
|
|
+import static org.hswebframework.web.authorization.access.DataAccessConfig.DefaultType.OWN_CREATED;
|
|
|
|
|
|
/**
|
|
|
* TODO 完成注释
|
|
@@ -21,9 +25,12 @@ import java.util.Objects;
|
|
|
public class SimpleDataAccessConfigBuilderFactory implements DataAccessConfigBuilderFactory {
|
|
|
|
|
|
private List<String> defaultSupportConvert = Arrays.asList(
|
|
|
- DataAccessConfig.DefaultType.CUSTOM
|
|
|
+ CUSTOM
|
|
|
// DataAccessConfig.DefaultType.SCRIPT
|
|
|
- , DataAccessConfig.DefaultType.OWN_CREATED);
|
|
|
+ , OWN_CREATED,
|
|
|
+ FIELD_SCOPE,
|
|
|
+ DENY_FIELDS,
|
|
|
+ ALLOW_FIELDS);
|
|
|
|
|
|
private List<DataAccessConfigConvert> converts = new LinkedList<>();
|
|
|
|
|
@@ -41,48 +48,48 @@ public class SimpleDataAccessConfigBuilderFactory implements DataAccessConfigBui
|
|
|
return defaultSupportConvert;
|
|
|
}
|
|
|
|
|
|
+ protected DataAccessConfigConvert createJsonConfig(String supportType, Class<? extends AbstractDataAccessConfig> clazz) {
|
|
|
+ return createConfig(supportType, (action, config) -> JSON.parseObject(config, clazz));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ protected DataAccessConfigConvert createConfig(String supportType, BiFunction<String, String, ? extends DataAccessConfig> function) {
|
|
|
+ return new DataAccessConfigConvert() {
|
|
|
+ @Override
|
|
|
+ public boolean isSupport(String type, String action, String config) {
|
|
|
+ return supportType.equals(type);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public DataAccessConfig convert(String type, String action, String config) {
|
|
|
+ DataAccessConfig conf = function.apply(action, config);
|
|
|
+ if (conf instanceof AbstractDataAccessConfig) {
|
|
|
+ ((AbstractDataAccessConfig) conf).setAction(action);
|
|
|
+ }
|
|
|
+ return conf;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
@PostConstruct
|
|
|
public void init() {
|
|
|
- if (defaultSupportConvert.contains(DataAccessConfig.DefaultType.OWN_CREATED))
|
|
|
- converts.add(new DataAccessConfigConvert() {
|
|
|
- @Override
|
|
|
- public boolean isSupport(String type, String action, String config) {
|
|
|
- return DataAccessConfig.DefaultType.OWN_CREATED.equals(type);
|
|
|
- }
|
|
|
+ if (defaultSupportConvert.contains(FIELD_SCOPE))
|
|
|
+ converts.add(createJsonConfig(FIELD_SCOPE, SimpleFiledScopeDataAccessConfig.class));
|
|
|
|
|
|
- @Override
|
|
|
- public DataAccessConfig convert(String type, String action, String config) {
|
|
|
- return new SimpleOwnCreatedDataAccessConfig(action);
|
|
|
- }
|
|
|
- });
|
|
|
- if (defaultSupportConvert.contains(DataAccessConfig.DefaultType.SCRIPT))
|
|
|
- converts.add(new DataAccessConfigConvert() {
|
|
|
- @Override
|
|
|
- public boolean isSupport(String type, String action, String config) {
|
|
|
- return DataAccessConfig.DefaultType.SCRIPT.equals(type);
|
|
|
- }
|
|
|
+ if (defaultSupportConvert.contains(DENY_FIELDS))
|
|
|
+ converts.add(createJsonConfig(DENY_FIELDS, SimpleFieldFilterDataAccessConfig.class));
|
|
|
|
|
|
- @Override
|
|
|
- public DataAccessConfig convert(String type, String action, String config) {
|
|
|
- SimpleOwnCreatedDataAccessConfig access = JSON.parseObject(config, SimpleOwnCreatedDataAccessConfig.class);
|
|
|
- access.setAction(config);
|
|
|
- return access;
|
|
|
- }
|
|
|
- });
|
|
|
- if (defaultSupportConvert.contains(DataAccessConfig.DefaultType.CUSTOM))
|
|
|
- converts.add(new DataAccessConfigConvert() {
|
|
|
- @Override
|
|
|
- public boolean isSupport(String type, String action, String config) {
|
|
|
- return DataAccessConfig.DefaultType.CUSTOM.equals(type);
|
|
|
- }
|
|
|
+ if (defaultSupportConvert.contains(ALLOW_FIELDS))
|
|
|
+ converts.add(createJsonConfig(ALLOW_FIELDS, SimpleFieldFilterDataAccessConfig.class));
|
|
|
|
|
|
- @Override
|
|
|
- public DataAccessConfig convert(String type, String action, String config) {
|
|
|
- SimpleCustomDataAccessConfig access = new SimpleCustomDataAccessConfig(config);
|
|
|
- access.setAction(action);
|
|
|
- return access;
|
|
|
- }
|
|
|
- });
|
|
|
+ if (defaultSupportConvert.contains(OWN_CREATED))
|
|
|
+ converts.add(createConfig(OWN_CREATED, (action, config) -> new SimpleOwnCreatedDataAccessConfig(action)));
|
|
|
+
|
|
|
+ if (defaultSupportConvert.contains(SCRIPT))
|
|
|
+ converts.add(createJsonConfig(SCRIPT, SimpleScriptDataAccessConfig.class));
|
|
|
+
|
|
|
+ if (defaultSupportConvert.contains(CUSTOM))
|
|
|
+ converts.add(createConfig(CUSTOM, (action, config) -> new SimpleCustomDataAccessConfigConfig(config)));
|
|
|
}
|
|
|
|
|
|
@Override
|