Search in sources :

Example 46 with UsernamePasswordCredential

use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.

the class CasKryoTranscoderTests method verifyEncodeDecodeTGTWithUnmodifiableSet.

@Test
public void verifyEncodeDecodeTGTWithUnmodifiableSet() {
    val newAttributes = new HashMap<String, List<Object>>();
    newAttributes.put(NICKNAME_KEY, List.of(CollectionUtils.wrapSet(NICKNAME_VALUE)));
    val userPassCredential = new UsernamePasswordCredential(USERNAME, PASSWORD);
    val expectedTGT = new MockTicketGrantingTicket(TGT_ID, userPassCredential, newAttributes);
    expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
    val result = transcoder.encode(expectedTGT);
    assertEquals(expectedTGT, transcoder.decode(result));
    assertEquals(expectedTGT, transcoder.decode(result));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 47 with UsernamePasswordCredential

use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.

the class LdapPasswordManagementServiceTests method verifyPasswordChangedFails.

@Test
public void verifyPasswordChangedFails() {
    val credential = new UsernamePasswordCredential("caspm", "123456");
    val bean = new PasswordChangeRequest();
    bean.setConfirmedPassword("Mellon");
    bean.setPassword("Mellon");
    bean.setUsername(credential.getUsername());
    assertFalse(passwordChangeService.change(credential, bean));
}
Also used : lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Test(org.junit.jupiter.api.Test)

Example 48 with UsernamePasswordCredential

use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.

the class RestPasswordManagementService method changeInternal.

@Override
public boolean changeInternal(final Credential c, final PasswordChangeRequest bean) {
    val rest = properties.getRest();
    if (StringUtils.isBlank(rest.getEndpointUrlChange())) {
        return false;
    }
    val upc = (UsernamePasswordCredential) c;
    val headers = new HttpHeaders();
    headers.setAccept(CollectionUtils.wrap(MediaType.APPLICATION_JSON));
    headers.put("username", CollectionUtils.wrap(upc.getUsername()));
    headers.put("password", CollectionUtils.wrap(bean.getPassword()));
    headers.put("oldPassword", CollectionUtils.wrap(upc.getPassword()));
    val entity = new HttpEntity<>(headers);
    val result = restTemplate.exchange(rest.getEndpointUrlChange(), HttpMethod.POST, entity, Boolean.class);
    return result.getStatusCodeValue() == HttpStatus.OK.value() && result.hasBody() && Objects.requireNonNull(result.getBody()).booleanValue();
}
Also used : lombok.val(lombok.val) HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential)

Example 49 with UsernamePasswordCredential

use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.

the class ScimV1PrincipalAttributeMapper method map.

/**
 * Map.
 *
 * @param user       the user
 * @param p          the p
 * @param credential the credential
 */
public void map(final UserResource user, final Principal p, final Credential credential) {
    user.setUserName(p.getId());
    if (credential instanceof UsernamePasswordCredential) {
        user.setPassword(UsernamePasswordCredential.class.cast(credential).getPassword());
    }
    user.setActive(Boolean.TRUE);
    user.setNickName(getPrincipalAttributeValue(p, "nickName"));
    user.setDisplayName(getPrincipalAttributeValue(p, "displayName"));
    val name = new Name(getPrincipalAttributeValue(p, "formattedName"), getPrincipalAttributeValue(p, "familyName"), getPrincipalAttributeValue(p, "middleName"), getPrincipalAttributeValue(p, "givenName"), getPrincipalAttributeValue(p, "honorificPrefix"), getPrincipalAttributeValue(p, "honorificSuffix"));
    user.setName(name);
    val entry = new Entry(getPrincipalAttributeValue(p, "mail"), "primary");
    user.setEmails(CollectionUtils.wrap(entry));
    val entry2 = new Entry(getPrincipalAttributeValue(p, "phoneNumber"), "primary");
    user.setPhoneNumbers(CollectionUtils.wrap(entry2));
}
Also used : lombok.val(lombok.val) Entry(com.unboundid.scim.data.Entry) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) Name(com.unboundid.scim.data.Name)

Example 50 with UsernamePasswordCredential

use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.

the class SamlAuthenticationMetaDataPopulatorTests method verifyAuthenticationTypeFound.

@Test
public void verifyAuthenticationTypeFound() {
    val credentials = new UsernamePasswordCredential();
    val builder = CoreAuthenticationTestUtils.getAuthenticationBuilder();
    this.populator.populateAttributes(builder, new DefaultAuthenticationTransactionFactory().newTransaction(credentials));
    val auth = builder.build();
    assertEquals(SamlAuthenticationMetaDataPopulator.AUTHN_METHOD_PASSWORD, auth.getAttributes().get(SamlAuthenticationMetaDataPopulator.ATTRIBUTE_AUTHENTICATION_METHOD).get(0));
}
Also used : lombok.val(lombok.val) UsernamePasswordCredential(org.apereo.cas.authentication.credential.UsernamePasswordCredential) DefaultAuthenticationTransactionFactory(org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)111 UsernamePasswordCredential (org.apereo.cas.authentication.credential.UsernamePasswordCredential)111 Test (org.junit.jupiter.api.Test)74 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)30 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)14 SimpleTestUsernamePasswordAuthenticationHandler (org.apereo.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler)12 HashMap (java.util.HashMap)8 Map (java.util.Map)8 BasicCredentialMetaData (org.apereo.cas.authentication.metadata.BasicCredentialMetaData)8 LinkedHashMap (java.util.LinkedHashMap)7 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)7 Executable (org.junit.jupiter.api.function.Executable)7 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)6 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)6 MockRequestContext (org.springframework.webflow.test.MockRequestContext)6 ArrayList (java.util.ArrayList)5 ClassPathResource (org.springframework.core.io.ClassPathResource)5 MockServletContext (org.springframework.mock.web.MockServletContext)5 FailedLoginException (javax.security.auth.login.FailedLoginException)4 SurrogateUsernamePasswordCredential (org.apereo.cas.authentication.SurrogateUsernamePasswordCredential)4