001/**
002 * Copyright (c) 2015-2022, Michael Yang 杨福海 (fuhai999@gmail.com).
003 * <p>
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * <p>
008 * http://www.apache.org/licenses/LICENSE-2.0
009 * <p>
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package io.jboot.support.shiro;
017
018import io.jboot.support.shiro.processer.AuthorizeResult;
019import io.jboot.support.shiro.processer.IShiroAuthorizeProcesser;
020
021import java.util.ArrayList;
022import java.util.List;
023
024/**
025 * Shiro 认证处理器 执行者,每个 actionKey 都有一个独立的 ShiroAuthorizeProcesserInvoker
026 * <p>
027 * 它是对 IShiroAuthorizeProcesser 的几个集合处理
028 */
029public class ShiroAuthorizeProcesserInvoker {
030
031    List<IShiroAuthorizeProcesser> processers;
032
033    public void addProcesser(IShiroAuthorizeProcesser processer) {
034        if (processers == null) {
035            processers = new ArrayList<>();
036        }
037        if (!processers.contains(processer)) {
038            processers.add(processer);
039        }
040    }
041
042    public List<IShiroAuthorizeProcesser> getProcessers() {
043        return processers;
044    }
045
046    public AuthorizeResult invoke() {
047        if (processers == null || processers.size() == 0) {
048            return AuthorizeResult.ok();
049        }
050
051        for (IShiroAuthorizeProcesser processer : processers) {
052            AuthorizeResult result = processer.authorize();
053
054            if (!result.isOk()) {
055                return result;
056            }
057        }
058
059        return AuthorizeResult.ok();
060    }
061
062
063}