Search in sources :

Example 1 with ApiPermission

use of com.mendmix.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(ApiPermssionCheckHelper.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(ApiPermssionCheckHelper.pathVariableToPattern(permissionKey));
                _authzPatterns.add(pattern);
            } else {
                _authzUris.add(permissionKey);
            }
        } else if (PermissionLevel.Anonymous.name().equals(permission.getGrantType())) {
            if (withWildcard) {
                pattern = Pattern.compile(ApiPermssionCheckHelper.pathVariableToPattern(permissionKey));
                _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.mendmix.security.model.ApiPermission) ArrayList(java.util.ArrayList)

Example 2 with ApiPermission

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

the class GatewaySecurityDecisionProvider method getAllApiPermissions.

@Override
public List<ApiPermission> getAllApiPermissions() {
    Collection<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.mendmix.common.model.ApiInfo) BizSystemModule(com.mendmix.gateway.model.BizSystemModule) ApiPermission(com.mendmix.security.model.ApiPermission) ArrayList(java.util.ArrayList)

Aggregations

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