use of org.springframework.http.HttpEntity in project cas by apereo.
the class RestConsentRepository method findConsentDecisions.
@Override
public Collection<ConsentDecision> findConsentDecisions(final String principal) {
try {
final HttpHeaders headers = new HttpHeaders();
headers.setAccept(CollectionUtils.wrap(MediaType.APPLICATION_JSON));
headers.put("principal", CollectionUtils.wrap(principal));
final HttpEntity<String> entity = new HttpEntity<>(headers);
final ResponseEntity<List> result = restTemplate.exchange(this.endpoint, HttpMethod.GET, entity, List.class);
if (result.getStatusCodeValue() == HttpStatus.OK.value()) {
return result.getBody();
}
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return new ArrayList<>(0);
}
use of org.springframework.http.HttpEntity in project cas by apereo.
the class RestConsentRepository method storeConsentDecision.
@Override
public boolean storeConsentDecision(final ConsentDecision decision) {
try {
final HttpHeaders headers = new HttpHeaders();
headers.setAccept(CollectionUtils.wrap(MediaType.APPLICATION_JSON));
final HttpEntity<ConsentDecision> entity = new HttpEntity<>(decision, headers);
final ResponseEntity<ConsentDecision> result = restTemplate.exchange(this.endpoint, HttpMethod.POST, entity, ConsentDecision.class);
return result.getStatusCodeValue() == HttpStatus.OK.value();
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return false;
}
use of org.springframework.http.HttpEntity in project cas by apereo.
the class RestGoogleAuthenticatorTokenCredentialRepository method get.
@Override
public OneTimeTokenAccount get(final String username) {
final GAuthMultifactorProperties.Rest rest = gauth.getRest();
final HttpHeaders headers = new HttpHeaders();
headers.setAccept(CollectionUtils.wrap(MediaType.APPLICATION_JSON));
headers.put("username", CollectionUtils.wrap(username));
final HttpEntity<String> entity = new HttpEntity<>(headers);
final ResponseEntity<OneTimeTokenAccount> result = restTemplate.exchange(rest.getEndpointUrl(), HttpMethod.GET, entity, OneTimeTokenAccount.class);
if (result.getStatusCodeValue() == HttpStatus.OK.value()) {
return decode(result.getBody());
}
return null;
}
use of org.springframework.http.HttpEntity in project cas by apereo.
the class RestGoogleAuthenticatorTokenCredentialRepository method update.
@Override
public OneTimeTokenAccount update(final OneTimeTokenAccount accountToUpdate) {
final GAuthMultifactorProperties.Rest rest = gauth.getRest();
final OneTimeTokenAccount account = encode(accountToUpdate);
final HttpHeaders headers = new HttpHeaders();
headers.setAccept(CollectionUtils.wrap(MediaType.APPLICATION_JSON));
headers.put("username", CollectionUtils.wrap(account.getUsername()));
headers.put("validationCode", CollectionUtils.wrap(String.valueOf(account.getValidationCode())));
headers.put("secretKey", CollectionUtils.wrap(account.getSecretKey()));
headers.put("scratchCodes", account.getScratchCodes().stream().map(String::valueOf).collect(Collectors.toList()));
final HttpEntity<String> entity = new HttpEntity<>(headers);
final ResponseEntity<Boolean> result = restTemplate.exchange(rest.getEndpointUrl(), HttpMethod.POST, entity, Boolean.class);
if (result.getStatusCodeValue() == HttpStatus.OK.value()) {
LOGGER.debug("Posted google authenticator account successfully");
return account;
}
LOGGER.warn("Failed to save google authenticator account successfully");
return null;
}
use of org.springframework.http.HttpEntity in project cas by apereo.
the class RestfulAuthenticationPolicy method isSatisfiedBy.
@Override
public boolean isSatisfiedBy(final Authentication authentication) throws Exception {
try {
final HttpHeaders acceptHeaders = new HttpHeaders();
acceptHeaders.setAccept(CollectionUtils.wrap(MediaType.APPLICATION_JSON));
final HttpEntity<Principal> entity = new HttpEntity<>(authentication.getPrincipal(), acceptHeaders);
LOGGER.warn("Checking authentication policy for [{}] via POST at [{}]", authentication.getPrincipal(), this.endpoint);
final ResponseEntity<String> resp = restTemplate.exchange(this.endpoint, HttpMethod.POST, entity, String.class);
if (resp == null) {
LOGGER.warn("[{}] returned no responses", this.endpoint);
throw new GeneralSecurityException("No response returned from REST endpoint to determine authentication policy");
}
if (resp.getStatusCode() != HttpStatus.OK) {
final Exception ex = handleResponseStatusCode(resp.getStatusCode(), authentication.getPrincipal());
throw new GeneralSecurityException(ex);
}
return true;
} catch (final HttpClientErrorException e) {
final Exception ex = handleResponseStatusCode(e.getStatusCode(), authentication.getPrincipal());
throw new GeneralSecurityException(ex);
}
}
Aggregations