@Test public void shouldThrowAnAuthorizationErrorIfTheCurrentAuthorizationContextDoesNotHaveTheSpecifiedAnnoationScope() throws Throwable { try { advisor.handle(authorize().withScopes("accounts:read").build()); } catch (AuthorizationException e) { List<Reportable> errors = e.getErrors(); Assertions.assertThat(errors).hasSize(1); Assertions.assertThat(errors.get(0).getCode()).isEqualTo("ATZ-0001"); Assertions.assertThat(errors.get(0).getMessage()).isEqualTo("Insufficient scope for this resource."); } }
@Before("execution(* *(..)) && @annotation(authorize)") public void handle(Authorize authorize) throws Throwable { if (!provider.isAuthenticated()) { throw new AuthenticationException(new Reportable("auth.not.authenticated")); } if (isNotBlank(authorize.scopes())) { checkScopes(authorize.scopes()); } if (isNotBlank(authorize.roles())) { checkRoles(authorize.roles()); } if (isNotBlank(authorize.authorities())) { checkAuthorities(authorize.authorities()); } }
AuthorizationAdvisor { @Before("execution(* *(..)) && @annotation(authorize)") public void handle(Authorize authorize) throws Throwable { if (!provider.isAuthenticated()) { throw new AuthenticationException(new Reportable("auth.not.authenticated")); } if (isNotBlank(authorize.scopes())) { checkScopes(authorize.scopes()); } if (isNotBlank(authorize.roles())) { checkRoles(authorize.roles()); } if (isNotBlank(authorize.authorities())) { checkAuthorities(authorize.authorities()); } } }
AuthorizationAdvisor { @Before("execution(* *(..)) && @annotation(authorize)") public void handle(Authorize authorize) throws Throwable { if (!provider.isAuthenticated()) { throw new AuthenticationException(new Reportable("auth.not.authenticated")); } if (isNotBlank(authorize.scopes())) { checkScopes(authorize.scopes()); } if (isNotBlank(authorize.roles())) { checkRoles(authorize.roles()); } if (isNotBlank(authorize.authorities())) { checkAuthorities(authorize.authorities()); } } @Autowired  AuthorizationAdvisor(AuthorizationContextProvider provider); }
AuthorizationAdvisor { @Before("execution(* *(..)) && @annotation(authorize)") public void handle(Authorize authorize) throws Throwable { if (!provider.isAuthenticated()) { throw new AuthenticationException(new Reportable("auth.not.authenticated")); } if (isNotBlank(authorize.scopes())) { checkScopes(authorize.scopes()); } if (isNotBlank(authorize.roles())) { checkRoles(authorize.roles()); } if (isNotBlank(authorize.authorities())) { checkAuthorities(authorize.authorities()); } } @Autowired  AuthorizationAdvisor(AuthorizationContextProvider provider); @Before("execution(* *(..)) && @annotation(authorize)") void handle(Authorize authorize); }
AuthorizationAdvisor { @Before("execution(* *(..)) && @annotation(authorize)") public void handle(Authorize authorize) throws Throwable { if (!provider.isAuthenticated()) { throw new AuthenticationException(new Reportable("auth.not.authenticated")); } if (isNotBlank(authorize.scopes())) { checkScopes(authorize.scopes()); } if (isNotBlank(authorize.roles())) { checkRoles(authorize.roles()); } if (isNotBlank(authorize.authorities())) { checkAuthorities(authorize.authorities()); } } @Autowired  AuthorizationAdvisor(AuthorizationContextProvider provider); @Before("execution(* *(..)) && @annotation(authorize)") void handle(Authorize authorize);  }