use of org.springframework.util.LinkedMultiValueMap in project cas by apereo.
the class X509CredentialFactoryTests method createDefaultCredential.
@Test
public void createDefaultCredential() {
final MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>();
requestBody.add("username", "name");
requestBody.add("password", "passwd");
final Credential cred = factory.fromRequestBody(requestBody);
assertTrue(cred instanceof UsernamePasswordCredential);
}
use of org.springframework.util.LinkedMultiValueMap in project cas by apereo.
the class X509CredentialFactoryTests method createX509Credential.
@Test
public void createX509Credential() throws IOException {
final MultiValueMap<String, String> requestBody = new LinkedMultiValueMap<>();
final Scanner scan = new Scanner(new ClassPathResource("ldap-crl.crt").getFile());
final String certStr = scan.useDelimiter("\\Z").next();
scan.close();
requestBody.add("cert", certStr);
final Credential cred = factory.fromRequestBody(requestBody);
assertTrue(cred instanceof X509CertificateCredential);
}
use of org.springframework.util.LinkedMultiValueMap in project cas by apereo.
the class OAuth20UserProfileControllerController method handleRequestInternal.
/**
* Handle request internal response entity.
*
* @param request the request
* @param response the response
* @return the response entity
* @throws Exception the exception
*/
@GetMapping(path = OAuthConstants.BASE_OAUTH20_URL + '/' + OAuthConstants.PROFILE_URL, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
String accessToken = request.getParameter(OAuthConstants.ACCESS_TOKEN);
if (StringUtils.isBlank(accessToken)) {
final String authHeader = request.getHeader(HttpConstants.AUTHORIZATION_HEADER);
if (StringUtils.isNotBlank(authHeader) && authHeader.toLowerCase().startsWith(OAuthConstants.BEARER_TOKEN.toLowerCase() + ' ')) {
accessToken = authHeader.substring(OAuthConstants.BEARER_TOKEN.length() + 1);
}
}
LOGGER.debug("[{}]: [{}]", OAuthConstants.ACCESS_TOKEN, accessToken);
if (StringUtils.isBlank(accessToken)) {
LOGGER.error("Missing [{}]", OAuthConstants.ACCESS_TOKEN);
final LinkedMultiValueMap<String, String> map = new LinkedMultiValueMap<>(1);
map.add(OAuthConstants.ERROR, OAuthConstants.MISSING_ACCESS_TOKEN);
final String value = OAuthUtils.jsonify(map);
return new ResponseEntity<>(value, HttpStatus.UNAUTHORIZED);
}
final AccessToken accessTokenTicket = getTicketRegistry().getTicket(accessToken, AccessToken.class);
if (accessTokenTicket == null || accessTokenTicket.isExpired()) {
LOGGER.error("Expired access token: [{}]", OAuthConstants.ACCESS_TOKEN);
final LinkedMultiValueMap<String, String> map = new LinkedMultiValueMap<>(1);
map.add(OAuthConstants.ERROR, OAuthConstants.EXPIRED_ACCESS_TOKEN);
final String value = OAuthUtils.jsonify(map);
return new ResponseEntity<>(value, HttpStatus.UNAUTHORIZED);
}
final Map<String, Object> map = writeOutProfileResponse(accessTokenTicket.getAuthentication(), accessTokenTicket.getAuthentication().getPrincipal());
final String value = OAuthUtils.jsonify(map);
LOGGER.debug("Final user profile is [{}]", value);
return new ResponseEntity<>(value, HttpStatus.OK);
}
use of org.springframework.util.LinkedMultiValueMap in project spring-security-oauth by spring-projects.
the class ClientCredentialsProviderTests method testHardCodedAuthenticationWrongClient.
@Test
public void testHardCodedAuthenticationWrongClient() {
RestTemplate restTemplate = new RestTemplate();
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
params.add("grant_type", "client_credentials");
params.add("client_id", "my-trusted-client");
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
RequestEntity<MultiValueMap<String, String>> req = new RequestEntity<MultiValueMap<String, String>>(params, headers, HttpMethod.POST, tokenUri);
try {
restTemplate.exchange(req, Map.class);
fail("Expected HTTP 401");
} catch (HttpStatusCodeException e) {
assertEquals(HttpStatus.UNAUTHORIZED, e.getStatusCode());
}
}
use of org.springframework.util.LinkedMultiValueMap in project spring-security-oauth by spring-projects.
the class CustomProviderTests method invalidGrant.
@Test
public void invalidGrant() throws Exception {
LinkedMultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
form.set("grant_type", "foo");
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", "Basic " + new String(Base64.encode(("my-trusted-client:").getBytes())));
@SuppressWarnings("rawtypes") ResponseEntity<Map> response = http.postForMap("/oauth/token", headers, form);
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
}
Aggregations