@Test public void shouldAbstainOnMissingAuthStrategiesAnn() throws Exception { assertEquals(0, authorizationStrategy.isAuthorized(principal, mock(Object.class), entity)); }
@Override @SuppressWarnings("rawtypes") public int isAuthorized(Object principal, Object dto, Object entity) { List<AuthorizeDto> authStrategiesAnns = HierarchicalAnnotationUtils.getAllHierarchicalAnnotations(dto.getClass(), AuthorizeDto.class); List<DtoAuthorizationStrategy> strategies = new ArrayList<>(); for (AuthorizeDto authStrategiesAnn : authStrategiesAnns) { for (Class<? extends DtoAuthorizationStrategy> strategyType : authStrategiesAnn.value()) { DtoAuthorizationStrategy strategy = strategyFactory.getAuthorizationStrategy(strategyType); if (strategy == null) throw new IllegalArgumentException(String.format("There is no strategy of type: %s", strategyType)); strategies.add(strategy); } } return accessDecisionManager.isAuthorized(principal, dto, entity, strategies); }
AuthorizeDtoAnnotationAuthorizationStrategy implements DtoAuthorizationStrategy<Object, Object, Object> { @Override @SuppressWarnings("rawtypes") public int isAuthorized(Object principal, Object dto, Object entity) { List<AuthorizeDto> authStrategiesAnns = HierarchicalAnnotationUtils.getAllHierarchicalAnnotations(dto.getClass(), AuthorizeDto.class); List<DtoAuthorizationStrategy> strategies = new ArrayList<>(); for (AuthorizeDto authStrategiesAnn : authStrategiesAnns) { for (Class<? extends DtoAuthorizationStrategy> strategyType : authStrategiesAnn.value()) { DtoAuthorizationStrategy strategy = strategyFactory.getAuthorizationStrategy(strategyType); if (strategy == null) throw new IllegalArgumentException(String.format("There is no strategy of type: %s", strategyType)); strategies.add(strategy); } } return accessDecisionManager.isAuthorized(principal, dto, entity, strategies); } }
AuthorizeDtoAnnotationAuthorizationStrategy implements DtoAuthorizationStrategy<Object, Object, Object> { @Override @SuppressWarnings("rawtypes") public int isAuthorized(Object principal, Object dto, Object entity) { List<AuthorizeDto> authStrategiesAnns = HierarchicalAnnotationUtils.getAllHierarchicalAnnotations(dto.getClass(), AuthorizeDto.class); List<DtoAuthorizationStrategy> strategies = new ArrayList<>(); for (AuthorizeDto authStrategiesAnn : authStrategiesAnns) { for (Class<? extends DtoAuthorizationStrategy> strategyType : authStrategiesAnn.value()) { DtoAuthorizationStrategy strategy = strategyFactory.getAuthorizationStrategy(strategyType); if (strategy == null) throw new IllegalArgumentException(String.format("There is no strategy of type: %s", strategyType)); strategies.add(strategy); } } return accessDecisionManager.isAuthorized(principal, dto, entity, strategies); } AuthorizeDtoAnnotationAuthorizationStrategy(@NonNull DtoAuthorizationStrategyFactory strategyFactory,
            @NonNull AccessDecisionManager accessDecisionManager);  AuthorizeDtoAnnotationAuthorizationStrategy(@NonNull DtoAuthorizationStrategyFactory strategyFactory); }
AuthorizeDtoAnnotationAuthorizationStrategy implements DtoAuthorizationStrategy<Object, Object, Object> { @Override @SuppressWarnings("rawtypes") public int isAuthorized(Object principal, Object dto, Object entity) { List<AuthorizeDto> authStrategiesAnns = HierarchicalAnnotationUtils.getAllHierarchicalAnnotations(dto.getClass(), AuthorizeDto.class); List<DtoAuthorizationStrategy> strategies = new ArrayList<>(); for (AuthorizeDto authStrategiesAnn : authStrategiesAnns) { for (Class<? extends DtoAuthorizationStrategy> strategyType : authStrategiesAnn.value()) { DtoAuthorizationStrategy strategy = strategyFactory.getAuthorizationStrategy(strategyType); if (strategy == null) throw new IllegalArgumentException(String.format("There is no strategy of type: %s", strategyType)); strategies.add(strategy); } } return accessDecisionManager.isAuthorized(principal, dto, entity, strategies); } AuthorizeDtoAnnotationAuthorizationStrategy(@NonNull DtoAuthorizationStrategyFactory strategyFactory,
            @NonNull AccessDecisionManager accessDecisionManager);  AuthorizeDtoAnnotationAuthorizationStrategy(@NonNull DtoAuthorizationStrategyFactory strategyFactory); @Override @SuppressWarnings("rawtypes") int isAuthorized(Object principal, Object dto, Object entity); }
AuthorizeDtoAnnotationAuthorizationStrategy implements DtoAuthorizationStrategy<Object, Object, Object> { @Override @SuppressWarnings("rawtypes") public int isAuthorized(Object principal, Object dto, Object entity) { List<AuthorizeDto> authStrategiesAnns = HierarchicalAnnotationUtils.getAllHierarchicalAnnotations(dto.getClass(), AuthorizeDto.class); List<DtoAuthorizationStrategy> strategies = new ArrayList<>(); for (AuthorizeDto authStrategiesAnn : authStrategiesAnns) { for (Class<? extends DtoAuthorizationStrategy> strategyType : authStrategiesAnn.value()) { DtoAuthorizationStrategy strategy = strategyFactory.getAuthorizationStrategy(strategyType); if (strategy == null) throw new IllegalArgumentException(String.format("There is no strategy of type: %s", strategyType)); strategies.add(strategy); } } return accessDecisionManager.isAuthorized(principal, dto, entity, strategies); } AuthorizeDtoAnnotationAuthorizationStrategy(@NonNull DtoAuthorizationStrategyFactory strategyFactory,
            @NonNull AccessDecisionManager accessDecisionManager);  AuthorizeDtoAnnotationAuthorizationStrategy(@NonNull DtoAuthorizationStrategyFactory strategyFactory); @Override @SuppressWarnings("rawtypes") int isAuthorized(Object principal, Object dto, Object entity);  }