use of org.apereo.cas.authentication.UsernamePasswordCredential in project cas by apereo.
the class KryoTranscoderTests method verifyEncodeDecodeTGTWithLinkedHashMap.
@Test
public void verifyEncodeDecodeTGTWithLinkedHashMap() throws Exception {
final Credential userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
final TicketGrantingTicket expectedTGT = new MockTicketGrantingTicket(TGT_ID, userPassCredential, new LinkedHashMap<>(this.principalAttributes));
expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
assertEquals(expectedTGT, transcoder.decode(transcoder.encode(expectedTGT)));
}
use of org.apereo.cas.authentication.UsernamePasswordCredential in project cas by apereo.
the class KryoTranscoderTests method verifyEncodeDecodeTGTWithUnmodifiableList.
@Test
public void verifyEncodeDecodeTGTWithUnmodifiableList() throws Exception {
final Credential userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
final List<String> values = new ArrayList<>();
values.add(NICKNAME_VALUE);
final Map<String, Object> newAttributes = new HashMap<>();
newAttributes.put(NICKNAME_KEY, Collections.unmodifiableList(values));
final TicketGrantingTicket expectedTGT = new MockTicketGrantingTicket(TGT_ID, userPassCredential, newAttributes);
expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
assertEquals(expectedTGT, transcoder.decode(transcoder.encode(expectedTGT)));
}
use of org.apereo.cas.authentication.UsernamePasswordCredential in project cas by apereo.
the class KryoTranscoderTests method verifyEncodeDecodeTGTWithUnmodifiableMap.
@Test
public void verifyEncodeDecodeTGTWithUnmodifiableMap() throws Exception {
final Credential userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
final TicketGrantingTicket expectedTGT = new MockTicketGrantingTicket(TGT_ID, userPassCredential, new HashMap<>(this.principalAttributes));
expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
assertEquals(expectedTGT, transcoder.decode(transcoder.encode(expectedTGT)));
}
use of org.apereo.cas.authentication.UsernamePasswordCredential in project cas by apereo.
the class RestPasswordManagementService method change.
@Override
public boolean change(final Credential c, final PasswordChangeBean bean) {
final PasswordManagementProperties.Rest rest = passwordManagementProperties.getRest();
if (StringUtils.isBlank(rest.getEndpointUrlChange())) {
return false;
}
final UsernamePasswordCredential upc = (UsernamePasswordCredential) c;
final HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
headers.put("username", Arrays.asList(upc.getUsername()));
headers.put("password", Arrays.asList(bean.getPassword()));
headers.put("oldPassword", Arrays.asList(upc.getPassword()));
final HttpEntity<String> entity = new HttpEntity<>(headers);
final ResponseEntity<Boolean> result = restTemplate.exchange(rest.getEndpointUrlEmail(), HttpMethod.POST, entity, Boolean.class);
if (result.getStatusCodeValue() == HttpStatus.OK.value()) {
return result.getBody();
}
return false;
}
use of org.apereo.cas.authentication.UsernamePasswordCredential in project cas by apereo.
the class InitPasswordResetAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) throws Exception {
final String token = requestContext.getFlowScope().getString("token");
if (StringUtils.isBlank(token)) {
LOGGER.error("Password reset token is missing");
return error();
}
final String username = passwordManagementService.parseToken(token);
if (StringUtils.isBlank(username)) {
LOGGER.error("Password reset token could not be verified");
return error();
}
final UsernamePasswordCredential c = new UsernamePasswordCredential();
c.setUsername(username);
WebUtils.putCredential(requestContext, c);
return success();
}
Aggregations