@Test public void shouldRetrieveAuthorities() { MotechUser user = mock(MotechUser.class); RoleDto role = mock(RoleDto.class); List<String> roles = Arrays.asList("role1"); when(user.getRoles()).thenReturn(roles); when(motechRoleService.getRole("role1")).thenReturn(role); List<String> permissions = Arrays.asList("permission1"); when(role.getPermissionNames()).thenReturn(permissions); List<GrantedAuthority> authorities = authoritiesService.authoritiesFor(user); assertThat(authorities.size(), Is.is(1)); assertThat(authorities.get(0).getAuthority(), Is.is("permission1")); }
@Override @Transactional public List<GrantedAuthority> authoritiesFor(MotechUser user) { List<GrantedAuthority> authorities = new ArrayList<>(); for (String role : user.getRoles()) { RoleDto motechRole = motechRoleService.getRole(role); if (motechRole != null) { for (String permission : motechRole.getPermissionNames()) { authorities.add(new SimpleGrantedAuthority(permission)); } } } return authorities; }
AuthoritiesServiceImpl implements AuthoritiesService { @Override @Transactional public List<GrantedAuthority> authoritiesFor(MotechUser user) { List<GrantedAuthority> authorities = new ArrayList<>(); for (String role : user.getRoles()) { RoleDto motechRole = motechRoleService.getRole(role); if (motechRole != null) { for (String permission : motechRole.getPermissionNames()) { authorities.add(new SimpleGrantedAuthority(permission)); } } } return authorities; } }
AuthoritiesServiceImpl implements AuthoritiesService { @Override @Transactional public List<GrantedAuthority> authoritiesFor(MotechUser user) { List<GrantedAuthority> authorities = new ArrayList<>(); for (String role : user.getRoles()) { RoleDto motechRole = motechRoleService.getRole(role); if (motechRole != null) { for (String permission : motechRole.getPermissionNames()) { authorities.add(new SimpleGrantedAuthority(permission)); } } } return authorities; }  }
AuthoritiesServiceImpl implements AuthoritiesService { @Override @Transactional public List<GrantedAuthority> authoritiesFor(MotechUser user) { List<GrantedAuthority> authorities = new ArrayList<>(); for (String role : user.getRoles()) { RoleDto motechRole = motechRoleService.getRole(role); if (motechRole != null) { for (String permission : motechRole.getPermissionNames()) { authorities.add(new SimpleGrantedAuthority(permission)); } } } return authorities; }  @Override @Transactional List<GrantedAuthority> authoritiesFor(MotechUser user); @Autowired void setMotechRoleService(MotechRoleService motechRoleService); }
AuthoritiesServiceImpl implements AuthoritiesService { @Override @Transactional public List<GrantedAuthority> authoritiesFor(MotechUser user) { List<GrantedAuthority> authorities = new ArrayList<>(); for (String role : user.getRoles()) { RoleDto motechRole = motechRoleService.getRole(role); if (motechRole != null) { for (String permission : motechRole.getPermissionNames()) { authorities.add(new SimpleGrantedAuthority(permission)); } } } return authorities; }  @Override @Transactional List<GrantedAuthority> authoritiesFor(MotechUser user); @Autowired void setMotechRoleService(MotechRoleService motechRoleService);  }