public Set<String> getAcceptVersion() { String rawValue = getFirstNativeHeader(STOMP_ACCEPT_VERSION_HEADER); return (rawValue != null ? StringUtils.commaDelimitedListToSet(rawValue) : Collections.emptySet()); }
private Set<String> getStatusCheckerNames(ProviderConfig providerConfig) { String status = providerConfig.getStatus(); return StringUtils.commaDelimitedListToSet(status); }
private Set<String> getStatusCheckerNames(ProtocolConfig protocolConfig) { String status = protocolConfig.getStatus(); return StringUtils.commaDelimitedListToSet(status); }
public ScimGroupsTypeResolvingFactoryBean(Object o) { if (o instanceof String) { groups = StringUtils.commaDelimitedListToSet((String) o).stream() .map(g -> g.split("\\|")) .collect(new MapCollector<>( gd -> gd[0], gd -> gd.length > 1 ? gd[1] : null) ); } else { groups = new HashMap<>((Map<String, String>) o); } }
@RequestMapping(value = "/check_token") @ResponseBody public Claims checkToken(HttpServletRequest request) throws HttpRequestMethodNotSupportedException { if (isAllowQueryString()) { String token = request.getParameter("token"); String scope = request.getParameter("scope"); return checkToken( token, hasText(scope) ? new LinkedList<>(commaDelimitedListToSet(scope)) : emptyList(), request ); } else { throw new HttpRequestMethodNotSupportedException(request.getMethod()); } }
@Override public Collection<? extends GrantedAuthority> mapAuthorities(Collection<? extends GrantedAuthority> authorities) { ArrayList<GrantedAuthority> result = new ArrayList<>(); for (GrantedAuthority authority : authorities) { LdapAuthority ldapAuthority = (LdapAuthority)authority; for (String scope : StringUtils.commaDelimitedListToSet(authority.getAuthority())) { LdapAuthority a = new LdapAuthority(scope, ldapAuthority.getDn(), ldapAuthority.getAttributes()); result.add(a); } } return result; } }
public ClientDetails mapRow(ResultSet rs, int rowNum) throws SQLException { BaseClientDetails details = new BaseClientDetails(rs.getString(1), rs.getString(3), rs.getString(4), rs.getString(5), rs.getString(7), rs.getString(6)); details.setClientSecret(rs.getString(2)); if (rs.getObject(8) != null) { details.setAccessTokenValiditySeconds(rs.getInt(8)); } if (rs.getObject(9) != null) { details.setRefreshTokenValiditySeconds(rs.getInt(9)); } String json = rs.getString(10); if (json != null) { try { @SuppressWarnings("unchecked") Map<String, Object> additionalInformation = mapper.read(json, Map.class); details.setAdditionalInformation(additionalInformation); } catch (Exception e) { logger.warn("Could not decode JSON for additional information: " + details, e); } } String scopes = rs.getString(11); if (scopes != null) { details.setAutoApproveScopes(StringUtils.commaDelimitedListToSet(scopes)); } return details; } }
public void validateRequiredGroups(String clientId, String... expectedGroups) { String requiredUserGroups = jdbcTemplate.queryForObject("select required_user_groups from oauth_client_details where client_id = ?", String.class, clientId); assertNotNull(requiredUserGroups); Collection<String> savedGroups = StringUtils.commaDelimitedListToSet(requiredUserGroups); assertThat(savedGroups, containsInAnyOrder(expectedGroups)); String additionalInformation = jdbcTemplate.queryForObject("select additional_information from oauth_client_details where client_id = ?", String.class, clientId); for (String s : expectedGroups) { assertThat(additionalInformation, not(containsString(s))); } }
private void assertSet(String expectedValue, Collection defaultValueIfNull, Collection actualValue, Class<?> type) { Collection assertScopes = defaultValueIfNull; if (expectedValue!=null) { if (String.class.equals(type)) { assertScopes = StringUtils.commaDelimitedListToSet(expectedValue); } else { assertScopes = AuthorityUtils.commaSeparatedStringToAuthorityList(expectedValue); } } assertEquals(assertScopes, actualValue); }
@Test public final void testGetSetMappableRoles() { Set<String> roles = StringUtils.commaDelimitedListToSet("Role1,Role2"); SimpleMappableAttributesRetriever r = new SimpleMappableAttributesRetriever(); r.setMappableAttributes(roles); Set<String> result = r.getMappableAttributes(); assertThat( roles.containsAll(result) && result.containsAll(roles)).withFailMessage( "Role collections do not match; result: " + result + ", expected: " + roles).isTrue(); }
private static boolean isTestEnabledInThisEnvironment(ProfileValueSource profileValueSource, IfProfileActive ifProfileActive, UnlessProfileActive unlessProfileActive) { if (ifProfileActive == null && unlessProfileActive == null) { return true; } List<String> blacklist = getBlacklist(unlessProfileActive); Set<String> activeProfiles = StringUtils.commaDelimitedListToSet(profileValueSource.get("spring.profiles.active")); boolean enabled = true; if (ifProfileActive != null && StringUtils.hasText(ifProfileActive.value())) { enabled = activeProfiles.contains(ifProfileActive.value()); } for (String profile : blacklist) { if (activeProfiles.contains(profile)) { enabled = false; continue; } } return enabled; }
@Test public void allowsBootstrapFromOtherInstance() throws Exception { //original bootstrap bootstrap.setGroups(StringUtils.commaDelimitedListToSet("multiple_bootstrap_group").stream().collect(new MapCollector<>(s -> s, s -> null))); bootstrap.afterPropertiesSet(); //mock external bootstrap in between getOrCreate and update calls ScimGroup multipleBootstrapGroupBefore = bootstrap.getGroup("multiple_bootstrap_group"); ScimGroup multipleBootstrapGroupAfter= bootstrap.getGroup("multiple_bootstrap_group"); multipleBootstrapGroupAfter.setVersion(multipleBootstrapGroupAfter.getVersion() + 1); gDB = mock(JdbcScimGroupProvisioning.class); when(gDB.create(any(), anyString())).thenReturn(multipleBootstrapGroupBefore); when(gDB.createOrGet(any(), anyString())).thenReturn(multipleBootstrapGroupBefore); when(gDB.update(anyString(), any(), anyString())).thenThrow(new IncorrectResultSizeDataAccessException(1, 0)); when(gDB.getByName(anyString(), anyString())).thenReturn(multipleBootstrapGroupAfter); //second bootstrap bootstrap = new ScimGroupBootstrap(gDB, uDB, mDB); bootstrap.setGroups(StringUtils.commaDelimitedListToSet("multiple_bootstrap_group").stream().collect(new MapCollector<>(s -> s, s -> s))); bootstrap.afterPropertiesSet(); assertNotNull(bootstrap.getGroup("multiple_bootstrap_group")); }
@Test public void testEmptyScopeOkForClientWithNoScopes() { SecurityContextAccessor securityContextAccessor = new StubSecurityContextAccessor() { @Override public boolean isUser() { return true; } @Override public Collection<? extends GrantedAuthority> getAuthorities() { return AuthorityUtils.commaSeparatedStringToAuthorityList("foo.bar,spam.baz"); } }; factory.setSecurityContextAccessor(securityContextAccessor); client.setScope(StringUtils.commaDelimitedListToSet("")); // empty AuthorizationRequest request = factory.createAuthorizationRequest(parameters); assertEquals(StringUtils.commaDelimitedListToSet(""), new TreeSet<String>(request.getScope())); }
@Test public void test_getAccessToken() { Collection me = AuthorityUtils.commaSeparatedStringToAuthorityList("openid,foo.bar,uaa.user,one.read"); OAuth2Request myReq = new OAuth2Request(requestParameters, receivingClient.getClientId(), receivingClient.getAuthorities(), true, receivingClient.getScope(), receivingClient.getResourceIds(), null, null, null); requestingClient.setScope(StringUtils.commaDelimitedListToSet("openid,foo.bar")); when(userAuthentication.getAuthorities()).thenReturn(me); tokenRequest.setClientId(receivingClient.getClientId()); when(authentication.isAuthenticated()).thenReturn(true); when(authentication.getUserAuthentication()).thenReturn(null); when(authentication.getUserAuthentication()).thenReturn(userAuthentication); when(userAuthentication.isAuthenticated()).thenReturn(true); when(requestFactory.createOAuth2Request(receivingClient, tokenRequest)).thenReturn(myReq); ReflectionTestUtils.setField(granter, "requestFactory", requestFactory); granter.getAccessToken(receivingClient, tokenRequest); }
@Test public void testEmptyScopeFailsClientWithScopes() { factory.setSecurityContextAccessor(securityContextAccessor); client.setScope(StringUtils.commaDelimitedListToSet("one,two")); // not empty expectedException.expect(InvalidScopeException.class); expectedException.expectMessage("[one, two] is invalid. This user is not allowed any of the requested scopes"); factory.createAuthorizationRequest(parameters); throw new AssertionError(); }
@Test public void testScopeIncludesAuthoritiesForUser() { SecurityContextAccessor securityContextAccessor = new StubSecurityContextAccessor() { @Override public boolean isUser() { return true; } @Override public Collection<? extends GrantedAuthority> getAuthorities() { return AuthorityUtils.commaSeparatedStringToAuthorityList("foo.bar,spam.baz"); } }; factory.setSecurityContextAccessor(securityContextAccessor); client.setScope(StringUtils.commaDelimitedListToSet("one,two,foo.bar")); AuthorizationRequest request = factory.createAuthorizationRequest(parameters); assertEquals(StringUtils.commaDelimitedListToSet("foo.bar"), new TreeSet<String>(request.getScope())); factory.validateParameters(request.getRequestParameters(), client); }
@Test void testCreateClientsTxClientCredentialsWithoutSecret() throws Exception { BaseClientDetails[] details = createBaseClients(5, null, null); details[details.length - 1].setAuthorizedGrantTypes(StringUtils.commaDelimitedListToSet("client_credentials")); details[details.length - 1].setClientSecret(null); MockHttpServletRequestBuilder createClientPost = post("/oauth/clients/tx") .header("Authorization", "Bearer " + adminToken) .accept(APPLICATION_JSON) .contentType(APPLICATION_JSON) .content(JsonUtils.writeValueAsString(details)); mockMvc.perform(createClientPost).andExpect(status().isBadRequest()); for (ClientDetails client : details) { assertNull(getClient(client.getClientId())); } verify(mockApplicationEventPublisher, times(0)).publishEvent(abstractUaaEventCaptor.capture()); }
@Test public void canAddGroups() throws Exception { bootstrap.setGroups(StringUtils.commaDelimitedListToSet("org1.dev,org1.qa,org1.engg,org1.mgr,org1.hr").stream().collect(new MapCollector<>(s -> s, s -> null))); bootstrap.afterPropertiesSet(); assertEquals(5, gDB.retrieveAll(IdentityZoneHolder.get().getId()).size()); assertNotNull(bootstrap.getGroup("org1.dev")); assertNotNull(bootstrap.getGroup("org1.qa")); assertNotNull(bootstrap.getGroup("org1.engg")); assertNotNull(bootstrap.getGroup("org1.mgr")); assertNotNull(bootstrap.getGroup("org1.hr")); }
@SuppressWarnings({"unchecked", "rawtypes"}) private GenericMessage<ChunkRequest> getSimpleMessage(String string, Long jobId) { StepContribution stepContribution = new JobExecution(new JobInstance(0L, "job"), new JobParameters()) .createStepExecution("step").createStepContribution(); ChunkRequest chunk = new ChunkRequest(0, StringUtils.commaDelimitedListToSet(string), jobId, stepContribution); GenericMessage<ChunkRequest> message = new GenericMessage<>(chunk); return message; }
@Test public void testVanillaHandleChunk() throws Exception { handler.setChunkProcessor(new ChunkProcessor<Object>() { public void process(StepContribution contribution, Chunk<Object> chunk) throws Exception { count += chunk.size(); } }); StepContribution stepContribution = MetaDataInstanceFactory.createStepExecution().createStepContribution(); ChunkResponse response = handler.handleChunk(new ChunkRequest<>(0, StringUtils .commaDelimitedListToSet("foo,bar"), 12L, stepContribution)); assertEquals(stepContribution, response.getStepContribution()); assertEquals(12, response.getJobId().longValue()); assertTrue(response.isSuccessful()); assertEquals(2, count); }