List of usage examples for org.springframework.util MultiValueMap put
V put(K key, V value);
From source file:org.cloudfoundry.identity.uaa.authentication.manager.LdapLoginAuthenticationManager.java
@Override protected MultiValueMap<String, String> getUserAttributes(UserDetails request) { MultiValueMap<String, String> result = super.getUserAttributes(request); logger.debug(String.format("Mapping custom attributes for origin:%s and zone:%s", getOrigin(), IdentityZoneHolder.get().getId())); if (getProviderProvisioning() != null) { IdentityProvider provider = getProviderProvisioning().retrieveByOrigin(getOrigin(), IdentityZoneHolder.get().getId()); if (request instanceof ExtendedLdapUserDetails) { ExtendedLdapUserDetails ldapDetails = ((ExtendedLdapUserDetails) request); LdapIdentityProviderDefinition ldapIdentityProviderDefinition = ObjectUtils .castInstance(provider.getConfig(), LdapIdentityProviderDefinition.class); Map<String, Object> providerMappings = ldapIdentityProviderDefinition.getAttributeMappings(); for (Map.Entry<String, Object> entry : providerMappings.entrySet()) { if (entry.getKey().startsWith(USER_ATTRIBUTE_PREFIX) && entry.getValue() != null) { String key = entry.getKey().substring(USER_ATTRIBUTE_PREFIX.length()); String[] values = ldapDetails.getAttribute((String) entry.getValue(), false); if (values != null && values.length > 0) { result.put(key, Arrays.asList(values)); logger.debug(String.format("Mappcustom attribute key:%s and value:%s", key, result.get(key))); }// ww w . j a v a 2 s .c o m } } } } else { logger.debug(String.format("Did not find custom attribute configuration for origin:%s and zone:%s", getOrigin(), IdentityZoneHolder.get().getId())); } return result; }
From source file:org.cloudfoundry.identity.uaa.provider.oauth.XOAuthAuthenticationManager.java
@Override protected void populateAuthenticationAttributes(UaaAuthentication authentication, Authentication request, AuthenticationData authenticationData) { Map<String, Object> claims = authenticationData.getClaims(); if (claims != null) { if (claims.get("amr") != null) { if (authentication.getAuthenticationMethods() == null) { authentication.setAuthenticationMethods(new HashSet<>((Collection<String>) claims.get("amr"))); } else { authentication.getAuthenticationMethods().addAll((Collection<String>) claims.get("amr")); }//w w w. ja va 2 s. c o m } Object acr = claims.get(ClaimConstants.ACR); if (acr != null) { if (acr instanceof Map) { Map<String, Object> acrMap = (Map) acr; Object values = acrMap.get("values"); if (values instanceof Collection) { authentication.setAuthContextClassRef(new HashSet<>((Collection) values)); } else if (values instanceof String[]) { authentication.setAuthContextClassRef(new HashSet<>(Arrays.asList((String[]) values))); } else { logger.debug(String.format("Unrecognized ACR claim[%s] for user_id: %s", values, authentication.getPrincipal().getId())); } } else if (acr instanceof String) { authentication.setAuthContextClassRef(new HashSet(Arrays.asList((String) acr))); } else { logger.debug(String.format("Unrecognized ACR claim[%s] for user_id: %s", acr, authentication.getPrincipal().getId())); } } MultiValueMap<String, String> userAttributes = new LinkedMultiValueMap<>(); logger.debug("Mapping XOauth custom attributes"); for (Map.Entry<String, Object> entry : authenticationData.getAttributeMappings().entrySet()) { if (entry.getKey().startsWith(USER_ATTRIBUTE_PREFIX) && entry.getValue() != null) { String key = entry.getKey().substring(USER_ATTRIBUTE_PREFIX.length()); Object values = claims.get(entry.getValue()); if (values != null) { logger.debug(String.format("Mapped XOauth attribute %s to %s", key, values)); if (values instanceof List) { List list = (List) values; List<String> strings = (List<String>) list.stream() .map(object -> Objects.toString(object, null)).collect(Collectors.toList()); userAttributes.put(key, strings); } else if (values instanceof String) { userAttributes.put(key, Arrays.asList((String) values)); } else { userAttributes.put(key, Arrays.asList(values.toString())); } } } } authentication.setUserAttributes(userAttributes); authentication.setExternalGroups(ofNullable(authenticationData.getAuthorities()).orElse(emptyList()) .stream().map(GrantedAuthority::getAuthority).collect(Collectors.toSet())); } super.populateAuthenticationAttributes(authentication, request, authenticationData); }
From source file:org.cloudfoundry.identity.uaa.provider.oauth.XOAuthAuthenticationManagerIT.java
@Test public void test_custom_user_attributes_are_stored() { addTheUserOnAuth();//from w w w . j ava2 s . com List<String> managers = Arrays.asList("Sue the Sloth", "Kari the AntEater"); List<String> costCenter = Collections.singletonList("Austin, TX"); claims.put("managers", managers); claims.put("employeeCostCenter", costCenter); attributeMappings.put("user.attribute.costCenter", "employeeCostCenter"); attributeMappings.put("user.attribute.terribleBosses", "managers"); config.setStoreCustomAttributes(true); config.setExternalGroupsWhitelist(Collections.singletonList("*")); List<String> scopes = SCOPES_LIST; claims.put("scope", scopes); attributeMappings.put(GROUP_ATTRIBUTE_NAME, "scope"); mockToken(); MultiValueMap<String, String> map = new LinkedMultiValueMap<>(); map.put("costCenter", costCenter); map.put("terribleBosses", managers); UaaAuthentication authentication = (UaaAuthentication) xoAuthAuthenticationManager.authenticate(xCodeToken); assertEquals(map, authentication.getUserAttributes()); assertThat(authentication.getExternalGroups(), containsInAnyOrder(scopes.toArray())); UserInfo info = new UserInfo().setUserAttributes(map).setRoles(scopes); UserInfo actualUserInfo = xoAuthAuthenticationManager.getUserDatabase() .getUserInfo(authentication.getPrincipal().getId()); assertEquals(actualUserInfo.getUserAttributes(), info.getUserAttributes()); assertThat(actualUserInfo.getRoles(), containsInAnyOrder(info.getRoles().toArray())); UaaUser actualUser = xoAuthAuthenticationManager.getUserDatabase().retrieveUserByName("12345", "the_origin"); assertThat(actualUser, is(not(nullValue()))); assertThat(actualUser.getGivenName(), is("Marissa")); }
From source file:org.cloudfoundry.identity.uaa.provider.oauth.XOAuthAuthenticationManagerTest.java
@Test public void test_custom_user_attributes_are_stored() throws Exception { addTheUserOnAuth();/* w ww . j a v a 2 s . com*/ List<String> managers = Arrays.asList("Sue the Sloth", "Kari the AntEater"); List<String> costCenter = Arrays.asList("Austin, TX"); claims.put("managers", managers); claims.put("employeeCostCenter", costCenter); attributeMappings.put("user.attribute.costCenter", "employeeCostCenter"); attributeMappings.put("user.attribute.terribleBosses", "managers"); config.setStoreCustomAttributes(true); config.setExternalGroupsWhitelist(Arrays.asList("*")); List<String> scopes = Arrays.asList("openid", "some.other.scope", "closedid"); claims.put("scope", scopes); attributeMappings.put(GROUP_ATTRIBUTE_NAME, "scope"); mockToken(); MultiValueMap<String, String> map = new LinkedMultiValueMap<>(); map.put("costCenter", costCenter); map.put("terribleBosses", managers); UaaAuthentication authentication = (UaaAuthentication) xoAuthAuthenticationManager.authenticate(xCodeToken); assertEquals(map, authentication.getUserAttributes()); assertThat(authentication.getExternalGroups(), containsInAnyOrder(scopes.toArray())); UserInfo info = new UserInfo().setUserAttributes(map).setRoles(scopes); UserInfo actualUserInfo = xoAuthAuthenticationManager.getUserDatabase() .getUserInfo(authentication.getPrincipal().getId()); assertEquals(actualUserInfo.getUserAttributes(), info.getUserAttributes()); assertThat(actualUserInfo.getRoles(), containsInAnyOrder(info.getRoles().toArray())); }
From source file:org.dspace.app.rest.utils.RestRepositoryUtils.java
public Object executeQueryMethod(DSpaceRestRepository repository, MultiValueMap<String, Object> parameters, Method method, Pageable pageable, Sort sort, PagedResourcesAssembler assembler) { MultiValueMap<String, Object> result = new LinkedMultiValueMap<String, Object>(parameters); MethodParameters methodParameters = new MethodParameters(method, new AnnotationAttribute(Param.class)); for (Entry<String, List<Object>> entry : parameters.entrySet()) { MethodParameter parameter = methodParameters.getParameter(entry.getKey()); if (parameter == null) { continue; }//from w ww .ja v a 2 s .c o m result.put(parameter.getParameterName(), entry.getValue()); } return invokeQueryMethod(repository, method, result, pageable, sort); }
From source file:org.springframework.cloud.netflix.zuul.filters.route.SimpleHostRoutingFilter.java
private MultiValueMap<String, String> revertHeaders(Header[] headers) { MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>(); for (Header header : headers) { String name = header.getName(); if (!map.containsKey(name)) { map.put(name, new ArrayList<String>()); }// w w w. j a va2s .c om map.get(name).add(header.getValue()); } return map; }
From source file:org.springframework.data.document.web.bind.annotation.support.HandlerMethodInvoker.java
private Map resolveRequestParamMap(Class<? extends Map> mapType, NativeWebRequest webRequest) { Map<String, String[]> parameterMap = webRequest.getParameterMap(); if (MultiValueMap.class.isAssignableFrom(mapType)) { MultiValueMap<String, String> result = new LinkedMultiValueMap<String, String>(parameterMap.size()); for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) { for (String value : entry.getValue()) { result.add(entry.getKey(), value); }/*from ww w .jav a 2s . co m*/ } return result; } else { Map<String, String> result = new LinkedHashMap<String, String>(parameterMap.size()); for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) { if (entry.getValue().length > 0) { result.put(entry.getKey(), entry.getValue()[0]); } } return result; } }
From source file:org.springframework.data.document.web.bind.annotation.support.HandlerMethodInvoker.java
private Map resolveRequestHeaderMap(Class<? extends Map> mapType, NativeWebRequest webRequest) { if (MultiValueMap.class.isAssignableFrom(mapType)) { MultiValueMap<String, String> result; if (HttpHeaders.class.isAssignableFrom(mapType)) { result = new HttpHeaders(); } else {/* w ww . j a va 2s .co m*/ result = new LinkedMultiValueMap<String, String>(); } for (Iterator<String> iterator = webRequest.getHeaderNames(); iterator.hasNext();) { String headerName = iterator.next(); for (String headerValue : webRequest.getHeaderValues(headerName)) { result.add(headerName, headerValue); } } return result; } else { Map<String, String> result = new LinkedHashMap<String, String>(); for (Iterator<String> iterator = webRequest.getHeaderNames(); iterator.hasNext();) { String headerName = iterator.next(); String headerValue = webRequest.getHeader(headerName); result.put(headerName, headerValue); } return result; } }
From source file:org.springframework.social.connect.web.ConnectSupport.java
private MultiValueMap<String, String> getRequestParameters(NativeWebRequest request, String... ignoredParameters) { List<String> ignoredParameterList = asList(ignoredParameters); MultiValueMap<String, String> convertedMap = new LinkedMultiValueMap<String, String>(); for (Entry<String, String[]> entry : request.getParameterMap().entrySet()) { if (!ignoredParameterList.contains(entry.getKey())) { convertedMap.put(entry.getKey(), asList(entry.getValue())); }//from w ww . j a va 2 s . c om } return convertedMap; }
From source file:org.springframework.social.oauth1.SigningSupport.java
private String normalizeParameters(MultiValueMap<String, String> collectedParameters) { // Normalizes the collected parameters for baseString calculation, per http://tools.ietf.org/html/rfc5849#section-3.4.1.3.2 MultiValueMap<String, String> sortedEncodedParameters = new TreeMultiValueMap<String, String>(); for (Iterator<Entry<String, List<String>>> entryIt = collectedParameters.entrySet().iterator(); entryIt .hasNext();) {// www .ja v a 2s . c o m Entry<String, List<String>> entry = entryIt.next(); String collectedName = entry.getKey(); List<String> collectedValues = entry.getValue(); List<String> encodedValues = new ArrayList<String>(collectedValues.size()); sortedEncodedParameters.put(oauthEncode(collectedName), encodedValues); for (Iterator<String> valueIt = collectedValues.iterator(); valueIt.hasNext();) { String value = valueIt.next(); encodedValues.add(value != null ? oauthEncode(value) : ""); } Collections.sort(encodedValues); } StringBuilder paramsBuilder = new StringBuilder(); for (Iterator<Entry<String, List<String>>> entryIt = sortedEncodedParameters.entrySet().iterator(); entryIt .hasNext();) { Entry<String, List<String>> entry = entryIt.next(); String name = entry.getKey(); List<String> values = entry.getValue(); for (Iterator<String> valueIt = values.iterator(); valueIt.hasNext();) { String value = valueIt.next(); paramsBuilder.append(name).append('=').append(value); if (valueIt.hasNext()) { paramsBuilder.append("&"); } } if (entryIt.hasNext()) { paramsBuilder.append("&"); } } return paramsBuilder.toString(); }