/** * Creates a {@link GrantedAuthority} collection from the given {@link KeycloakSecurityContext}. * * @param context the current <code>RefreshableKeycloakSecurityContext</code> (required) * @param mapper an optional {@link GrantedAuthoritiesMapper} to convert the * authorities loaded the given <code>context</code> which will be used in the * {@code Authentication} object * * @return a {@link GrantedAuthority} collection if any; an empty list otherwise */ public static Collection<? extends GrantedAuthority> createGrantedAuthorities(RefreshableKeycloakSecurityContext context, GrantedAuthoritiesMapper mapper) { Assert.notNull(context, "RefreshableKeycloakSecurityContext cannot be null"); List<KeycloakRole> grantedAuthorities = new ArrayList<>(); for (String role : AdapterUtils.getRolesFromSecurityContext(context)) { grantedAuthorities.add(new KeycloakRole(role)); } return mapper != null ? mapper.mapAuthorities(grantedAuthorities) : Collections.unmodifiableList(grantedAuthorities); }
@Autowired public ReverseProxyIdolSecurityCustomizer( final UserService userService, final GrantedAuthoritiesMapper grantedAuthoritiesMapper, @Value("${find.reverse-proxy.pre-authenticated-roles}") final String preAuthenticatedRoles ) { this.userService = userService; this.grantedAuthoritiesMapper = grantedAuthoritiesMapper; this.preAuthenticatedRoles = preAuthenticatedRoles; }
@Bean public GrantedAuthoritiesMapper grantedAuthoritiesMapper() { final Map<String, String> rolesMap = new CaseInsensitiveMap<>(); rolesMap.put(FindCommunityRole.USER.value(), FindRole.USER.toString()); rolesMap.put(FindCommunityRole.ADMIN.value(), FindRole.ADMIN.toString()); if (enableBi) { rolesMap.put(FindCommunityRole.BI.value(), FindRole.BI.toString()); } return new OneToOneOrZeroSimpleAuthorityMapper(Collections.unmodifiableMap(rolesMap)); }
@BeforeMethod public void setUp() { DataService dataService = mock(DataService.class); User adminUser = when(mock(User.class).isSuperuser()).thenReturn(Boolean.TRUE).getMock(); when(adminUser.getUsername()).thenReturn("admin"); when(adminUser.getPassword()).thenReturn("password"); User userUser = when(mock(User.class).isSuperuser()).thenReturn(Boolean.FALSE).getMock(); when(userUser.getUsername()).thenReturn("user"); when(userUser.getPassword()).thenReturn("password"); Query<User> qAdmin = new QueryImpl<User>().eq(UserMetaData.USERNAME, "admin"); when(dataService.findOne(USER, qAdmin, User.class)).thenReturn(adminUser); Query<User> qUser = new QueryImpl<User>().eq(UserMetaData.USERNAME, "user"); when(dataService.findOne(USER, qUser, User.class)).thenReturn(userUser); GrantedAuthoritiesMapper authoritiesMapper = authorities -> authorities; when(dataService.findAll(USER_AUTHORITY, new QueryImpl<UserAuthority>().eq(UserAuthorityMetaData.USER, userUser), UserAuthority.class)).thenAnswer(invocation -> Stream.empty()); when(dataService.findAll(USER_AUTHORITY, new QueryImpl<UserAuthority>().eq(UserAuthorityMetaData.USER, adminUser), UserAuthority.class)).thenAnswer(invocation -> Stream.empty()); when(dataService.findAll(GroupMemberMetaData.GROUP_MEMBER, new QueryImpl<GroupMember>().eq(GroupMemberMetaData.USER, userUser), GroupMember.class)).thenAnswer( invocation -> Stream.empty()); when(dataService.findAll(GroupMemberMetaData.GROUP_MEMBER, new QueryImpl<GroupMember>().eq(GroupMemberMetaData.USER, adminUser), GroupMember.class)).thenAnswer( invocation -> Stream.empty()); userDetailsService = new UserDetailsService(dataService, authoritiesMapper); }
@Autowired public ImportWizardController(UploadWizardPage uploadWizardPage, OptionsWizardPage optionsWizardPage, PackageWizardPage packageWizardPage, ValidationResultWizardPage validationResultWizardPage, ImportResultsWizardPage importResultsWizardPage, DataService dataService, GrantedAuthoritiesMapper grantedAuthoritiesMapper, UserAccountService userAccountService, ImportServiceFactory importServiceFactory, FileStore fileStore, FileRepositoryCollectionFactory fileRepositoryCollectionFactory, ImportRunService importRunService, GroupAuthorityFactory groupAuthorityFactory) { super(URI, "importWizard"); if (uploadWizardPage == null) throw new IllegalArgumentException("UploadWizardPage is null"); if (optionsWizardPage == null) throw new IllegalArgumentException("OptionsWizardPage is null"); if (validationResultWizardPage == null) { throw new IllegalArgumentException("ValidationResultWizardPage is null"); } if (importResultsWizardPage == null) throw new IllegalArgumentException("ImportResultsWizardPage is null"); this.uploadWizardPage = uploadWizardPage; this.optionsWizardPage = optionsWizardPage; this.validationResultWizardPage = validationResultWizardPage; this.importResultsWizardPage = importResultsWizardPage; this.packageWizardPage = packageWizardPage; this.userAccountService = userAccountService; this.dataService = dataService; this.grantedAuthoritiesMapper = grantedAuthoritiesMapper; this.importServiceFactory = importServiceFactory; this.fileStore = fileStore; this.fileRepositoryCollectionFactory = fileRepositoryCollectionFactory; this.importRunService = importRunService; this.groupAuthorityFactory = requireNonNull(groupAuthorityFactory); this.dataService = dataService; this.asyncImportJobs = Executors.newSingleThreadExecutor(); }
public ImportWizardController(UploadWizardPage uploadWizardPage, OptionsWizardPage optionsWizardPage, PackageWizardPage packageWizardPage, ValidationResultWizardPage validationResultWizardPage, ImportResultsWizardPage importResultsWizardPage, DataService dataService, GrantedAuthoritiesMapper grantedAuthoritiesMapper, UserAccountService userAccountService, ImportServiceFactory importServiceFactory, FileStore fileStore, FileRepositoryCollectionFactory fileRepositoryCollectionFactory, ImportRunService importRunService, ExecutorService executorService, GroupAuthorityFactory groupAuthorityFactory) { super(URI, "importWizard"); if (uploadWizardPage == null) throw new IllegalArgumentException("UploadWizardPage is null"); if (optionsWizardPage == null) throw new IllegalArgumentException("OptionsWizardPage is null"); if (validationResultWizardPage == null) throw new IllegalArgumentException("ValidationResultWizardPage is null"); if (importResultsWizardPage == null) throw new IllegalArgumentException("ImportResultsWizardPage is null"); this.uploadWizardPage = uploadWizardPage; this.optionsWizardPage = optionsWizardPage; this.validationResultWizardPage = validationResultWizardPage; this.importResultsWizardPage = importResultsWizardPage; this.packageWizardPage = packageWizardPage; this.userAccountService = userAccountService; this.dataService = dataService; this.grantedAuthoritiesMapper = grantedAuthoritiesMapper; this.importServiceFactory = importServiceFactory; this.fileStore = fileStore; this.fileRepositoryCollectionFactory = fileRepositoryCollectionFactory; this.importRunService = importRunService; this.dataService = dataService; this.asyncImportJobs = executorService; this.groupAuthorityFactory = groupAuthorityFactory; }
public void setAuthoritiesMapper(GrantedAuthoritiesMapper authoritiesMapper) { this.authoritiesMapper = authoritiesMapper; }
@Override public void setGrantedAuthoritiesMapper(GrantedAuthoritiesMapper grantedAuthoritiesMapper) { this.grantedAuthoritiesMapper = grantedAuthoritiesMapper; }
public PermissionManagerServiceImpl(DataService dataService, GrantedAuthoritiesMapper grantedAuthoritiesMapper) { this.dataService = requireNonNull(dataService); this.grantedAuthoritiesMapper = requireNonNull(grantedAuthoritiesMapper); }
public UserDetailsService(DataService dataService, GrantedAuthoritiesMapper grantedAuthoritiesMapper) { this.dataService = requireNonNull(dataService, "DataService is null"); this.grantedAuthoritiesMapper = requireNonNull(grantedAuthoritiesMapper, "Granted authorities mapper is null"); }
@Bean public GrantedAuthoritiesMapper roleHierarchyAuthoritiesMapper() { return new RoleHierarchyAuthoritiesMapper(roleHierarchy()); }
@Bean public GrantedAuthoritiesMapper grantedAuthoritiesMapper() { return mock(GrantedAuthoritiesMapper.class); }
/** * Set the optional {@link GrantedAuthoritiesMapper} for this {@link AuthenticationProvider}. * * @param grantedAuthoritiesMapper the <code>GrantedAuthoritiesMapper</code> to use */ public void setGrantedAuthoritiesMapper(GrantedAuthoritiesMapper grantedAuthoritiesMapper) { this.grantedAuthoritiesMapper = grantedAuthoritiesMapper; }