use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class PrincipalBearingCredentialsToPrincipalResolverTests method verifySupports.
@Test
public void verifySupports() {
val credential = new PrincipalBearingCredential(PrincipalFactoryUtils.newPrincipalFactory().createPrincipal("test"));
assertTrue(this.resolver.supports(credential));
assertFalse(this.resolver.supports(new UsernamePasswordCredential()));
assertFalse(this.resolver.supports(null));
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class DefaultScimV2PrincipalAttributeMapper method map.
@Override
public void map(final UserResource user, final Principal principal, final Credential credential) {
user.setUserName(principal.getId());
if (credential instanceof UsernamePasswordCredential) {
user.setPassword(UsernamePasswordCredential.class.cast(credential).getPassword());
}
user.setActive(Boolean.TRUE);
user.setNickName(getPrincipalAttributeValue(principal, "nickName"));
user.setDisplayName(getPrincipalAttributeValue(principal, "displayName"));
val name = new Name();
name.setGivenName(getPrincipalAttributeValue(principal, "givenName"));
name.setFamilyName(getPrincipalAttributeValue(principal, "familyName"));
name.setMiddleName(getPrincipalAttributeValue(principal, "middleName"));
user.setName(name);
val email = new Email();
email.setPrimary(Boolean.TRUE);
email.setValue(getPrincipalAttributeValue(principal, "email"));
user.setEmails(CollectionUtils.wrap(email));
val phone = new PhoneNumber();
phone.setPrimary(Boolean.TRUE);
phone.setValue(getPrincipalAttributeValue(principal, "phoneNumber"));
user.setPhoneNumbers(CollectionUtils.wrap(phone));
user.setExternalId(getPrincipalAttributeValue(principal, "externalId", principal.getId()));
if (user.getMeta() == null) {
val meta = new Meta();
meta.setCreated(Calendar.getInstance(TimeZone.getTimeZone(ZoneOffset.UTC)));
meta.setResourceType(user.getUserType());
user.setMeta(meta);
}
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class SamlValidateEndpoint method handle.
/**
* Handle validation request and produce saml1 payload.
*
* @param username the username
* @param password the password
* @param service the service
* @return the map
*/
@ReadOperation
@Operation(summary = "Handle validation request and produce saml1 payload.", parameters = { @Parameter(name = "username", required = true), @Parameter(name = "password", required = true), @Parameter(name = "service", required = true) })
public Map<String, Object> handle(final String username, final String password, final String service) {
val credential = new UsernamePasswordCredential(username, password);
val selectedService = this.serviceFactory.createService(service);
val result = this.authenticationSystemSupport.finalizeAuthenticationTransaction(selectedService, credential);
val authentication = result.getAuthentication();
val registeredService = this.servicesManager.findServiceBy(selectedService);
val audit = AuditableContext.builder().service(selectedService).authentication(authentication).registeredService(registeredService).build();
val accessResult = registeredServiceAccessStrategyEnforcer.execute(audit);
accessResult.throwExceptionIfNeeded();
val principal = authentication.getPrincipal();
val context = RegisteredServiceAttributeReleasePolicyContext.builder().registeredService(registeredService).service(selectedService).principal(principal).build();
val attributesToRelease = registeredService.getAttributeReleasePolicy().getAttributes(context);
val principalId = registeredService.getUsernameAttributeProvider().resolveUsername(principal, selectedService, registeredService);
val modifiedPrincipal = this.principalFactory.createPrincipal(principalId, attributesToRelease);
val builder = DefaultAuthenticationBuilder.newInstance(authentication);
builder.setPrincipal(modifiedPrincipal);
val finalAuthentication = builder.build();
val samlResponse = this.samlResponseBuilder.createResponse(selectedService.getId(), selectedService);
samlResponseBuilder.prepareSuccessfulResponse(samlResponse, selectedService, finalAuthentication, principal, finalAuthentication.getAttributes(), principal.getAttributes());
val resValidation = new LinkedHashMap<String, Object>();
val encoded = SamlUtils.transformSamlObject(this.openSamlConfigBean, samlResponse).toString();
resValidation.put(CasViewConstants.MODEL_ATTRIBUTE_NAME_ASSERTION, encoded);
resValidation.put(CasViewConstants.MODEL_ATTRIBUTE_NAME_SERVICE, selectedService);
resValidation.put("registeredService", registeredService);
return resValidation;
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class ChainingCasProtocolValidationSpecificationTests method getAssertion.
private static Assertion getAssertion() {
val assertion = mock(Assertion.class);
val principal = CoreAuthenticationTestUtils.getPrincipal("casuser");
val handlers = (Map) Map.of(new UsernamePasswordCredential(), new SimpleTestUsernamePasswordAuthenticationHandler());
val authentication = CoreAuthenticationTestUtils.getAuthenticationBuilder(principal, handlers, Map.of()).build();
when(assertion.getPrimaryAuthentication()).thenReturn(authentication);
when(assertion.getChainedAuthentications()).thenReturn(List.of(authentication));
return assertion;
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class RedisAuthenticationHandlerTests method verifySuccessful.
@Test
public void verifySuccessful() throws Exception {
val result = authenticationHandler.authenticate(new UsernamePasswordCredential("casuser", "caspassword"));
assertNotNull(result);
val principal = result.getPrincipal();
assertNotNull(principal);
assertNotNull(principal.getAttributes());
assertTrue(principal.getAttributes().containsKey("name"));
assertTrue(principal.getAttributes().containsKey("group"));
}
Aggregations