ElPermissionConfig.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Copyright 2019-2020 Zheng Jie
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package me.zhengjie.config;
  17. import me.zhengjie.utils.SecurityUtils;
  18. import org.springframework.security.core.GrantedAuthority;
  19. import org.springframework.stereotype.Service;
  20. import java.util.Arrays;
  21. import java.util.List;
  22. import java.util.stream.Collectors;
  23. /**
  24. * @author Zheng Jie
  25. */
  26. @Service(value = "el")
  27. public class ElPermissionConfig {
  28. public Boolean check(String ...permissions){
  29. // 获取当前用户的所有权限
  30. List<String> elPermissions = SecurityUtils.getCurrentUser().getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList());
  31. // 判断当前用户的所有权限是否包含接口上定义的权限
  32. return elPermissions.contains("admin") || Arrays.stream(permissions).anyMatch(elPermissions::contains);
  33. }
  34. }