刘光辉
13 小时以前 34981c30a78e8bbd7791131059a9210f9928b62c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package jnpf.base.config;
 
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
 
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;
 
/**
 * 在线表单和流程表单的字段权限配置。
 */
@Component
@ConfigurationProperties(prefix = "jnpf.visualdev.permission")
public class VisualdevPermissionProperties {
 
    private List<String> exemptFields = Collections.emptyList();
    private Set<String> normalizedExemptFields = Collections.emptySet();
 
    public List<String> getExemptFields() {
        return exemptFields;
    }
 
    public void setExemptFields(List<String> exemptFields) {
        if (exemptFields == null) {
            this.exemptFields = Collections.emptyList();
            this.normalizedExemptFields = Collections.emptySet();
            return;
        }
        this.exemptFields = exemptFields.stream()
                .filter(field -> field != null && !field.trim().isEmpty())
                .map(String::trim)
                .distinct()
                .collect(Collectors.toList());
        this.normalizedExemptFields = this.exemptFields.stream()
                .map(field -> field.toLowerCase(Locale.ROOT))
                .collect(Collectors.collectingAndThen(Collectors.toCollection(LinkedHashSet::new), Collections::unmodifiableSet));
    }
 
    public boolean isExempt(String field) {
        return field != null && normalizedExemptFields.contains(field.trim().toLowerCase(Locale.ROOT));
    }
}