Search in sources :

Example 1 with ApiPermission

use of com.jeesuite.security.model.ApiPermission in project jeesuite-libs by vakinge.

the class GatewaySecurityDecisionProvider method getAllApiPermissions.

@Override
public List<ApiPermission> getAllApiPermissions() {
    List<BizSystemModule> modules = CurrentSystemHolder.getModules();
    List<ApiPermission> result = new ArrayList<>();
    Collection<ApiInfo> apis;
    ApiPermission apiPermission;
    for (BizSystemModule module : modules) {
        if (module.getApiInfos() == null)
            continue;
        apis = module.getApiInfos().values();
        for (ApiInfo apiInfo : apis) {
            apiPermission = new ApiPermission();
            apiPermission.setGrantType(apiInfo.getPermissionType().name());
            apiPermission.setHttpMethod(apiInfo.getMethod());
            apiPermission.setUri(apiInfo.getUrl());
            result.add(apiPermission);
        }
    }
    return result;
}
Also used : ApiInfo(com.jeesuite.common.model.ApiInfo) BizSystemModule(com.jeesuite.gateway.model.BizSystemModule) ApiPermission(com.jeesuite.security.model.ApiPermission) ArrayList(java.util.ArrayList)

Example 2 with ApiPermission

use of com.jeesuite.security.model.ApiPermission in project jeesuite-libs by vakinge.

the class SecurityResourceManager method loadApiPermissions.

public synchronized boolean loadApiPermissions() {
    List<ApiPermission> permissions = decisionProvider.getAllApiPermissions();
    if (permissions == null)
        return false;
    List<String> _authzUris = new ArrayList<>();
    List<Pattern> _authzPatterns = new ArrayList<>();
    List<String> _anonUris = new ArrayList<>();
    List<Pattern> _anonUriPatterns = new ArrayList<>();
    // 所有无通配符uri
    List<String> _nonWildcardUris = new ArrayList<>();
    boolean withWildcard;
    String permissionKey;
    Pattern pattern;
    for (ApiPermission permission : permissions) {
        withWildcard = permission.getUri().contains(WILDCARD_START);
        permissionKey = ApiPermssionCheckHelper.buildPermissionKey(permission.getHttpMethod(), permission.getUri());
        if (!withWildcard) {
            _nonWildcardUris.add(permissionKey);
        }
        if (PermissionLevel.PermissionRequired.name().equals(permission.getGrantType())) {
            if (withWildcard) {
                pattern = Pattern.compile(permissionKey.replaceAll("\\{[^/]+?\\}", ".+"));
                _authzPatterns.add(pattern);
            } else {
                _authzUris.add(permissionKey);
            }
        } else if (PermissionLevel.Anonymous.name().equals(permission.getGrantType())) {
            if (withWildcard) {
                pattern = Pattern.compile(permissionKey.replaceAll("\\{[^/]+?\\}", ".+"));
                _anonUriPatterns.add(pattern);
            } else {
                _anonUris.add(permissionKey);
            }
        }
    }
    nonWildcardUris.set(_nonWildcardUris);
    anonUris.set(_anonUris);
    anonUriPatterns.set(_anonUriPatterns);
    authzUris.set(_authzUris);
    authzPatterns.set(_authzPatterns);
    if (logging) {
        log.info("nonWildcardUris:         {}", getNonWildcardUris());
        log.info("anonUris:                {}", getAnonUris());
        log.info("anonUriPatterns:         {}", getAnonUriPatterns());
        log.info("authzUris:               {}", getAuthzUris());
        log.info("authzPatterns:           {}", getAuthzPatterns());
        logging = false;
    }
    return true;
}
Also used : Pattern(java.util.regex.Pattern) ApiPermission(com.jeesuite.security.model.ApiPermission) ArrayList(java.util.ArrayList)

Aggregations

ApiPermission (com.jeesuite.security.model.ApiPermission)2 ArrayList (java.util.ArrayList)2 ApiInfo (com.jeesuite.common.model.ApiInfo)1 BizSystemModule (com.jeesuite.gateway.model.BizSystemModule)1 Pattern (java.util.regex.Pattern)1