Java Code Examples for org.jasig.cas.authentication.principal.Principal#getId()
The following examples show how to use
org.jasig.cas.authentication.principal.Principal#getId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrincipalAttributeRegisteredServiceUsernameProvider.java From springboot-shiro-cas-mybatis with MIT License | 6 votes |
@Override public String resolveUsername(final Principal principal, final Service service) { String principalId = principal.getId(); if (principal.getAttributes().containsKey(this.usernameAttribute)) { principalId = principal.getAttributes().get(this.usernameAttribute).toString(); } else { logger.warn("Principal [{}] did not have attribute [{}] among attributes [{}] so CAS cannot " + "provide the user attribute the service expects. " + "CAS will instead return the default principal id [{}]", principalId, this.usernameAttribute, principal.getAttributes(), principalId); } logger.debug("Principal id to return is [{}]. The default principal id is [{}].", principalId, principal.getId()); return principalId; }
Example 2
Source File: CentralAuthenticationServiceImpl.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
/** * Determines the principal id to use for a {@link RegisteredService} using the following rules: * * <ul> * <li> If the service is marked to allow anonymous access, a persistent id is returned. </li> * <li> If the {@link org.jasig.cas.services.RegisteredService#getUsernameAttribute()} is blank, then the default * principal id is returned.</li> * <li>If the username attribute is available as part of the principal's attributes, * the corresponding attribute value will be returned. * </li> * <li>Otherwise, the default principal's id is returned as the username attribute * with an additional warning.</li> * </ul> * * @param principal The principal object to be validated and constructed * @param registeredService Requesting service for which a principal is being validated. * @param serviceTicket An instance of the service ticket used for validation * * @return The principal id to use for the requesting registered service */ private String determinePrincipalIdForRegisteredService(final Principal principal, final RegisteredService registeredService, final ServiceTicket serviceTicket) { String principalId = null; final String serviceUsernameAttribute = registeredService.getUsernameAttribute(); if (registeredService.isAnonymousAccess()) { principalId = this.persistentIdGenerator.generate(principal, serviceTicket.getService()); } else if (StringUtils.isBlank(serviceUsernameAttribute)) { principalId = principal.getId(); } else { if (principal.getAttributes().containsKey(serviceUsernameAttribute)) { principalId = principal.getAttributes().get(serviceUsernameAttribute).toString(); } else { principalId = principal.getId(); final Object[] errorLogParameters = new Object[] { principalId, registeredService.getUsernameAttribute(), principal.getAttributes(), registeredService.getServiceId(), principalId }; logger.warn("Principal [{}] did not have attribute [{}] among attributes [{}] so CAS cannot " + "provide on the validation response the user attribute the registered service [{}] expects. " + "CAS will instead return the default username attribute [{}]", errorLogParameters); } } logger.debug("Principal id to return for service [{}] is [{}]. The default principal id is [{}].", new Object[]{registeredService.getName(), principal.getId(), principalId}); return principalId; }
Example 3
Source File: MultifactorLoginViewPrincipalAttributeGreeter.java From cas-mfa with Apache License 2.0 | 5 votes |
@Override public String getPersonToGreet(final Principal p, final MessageContext messageContext) { String personId = p.getId(); final Object attrValue = p.getAttributes().get(this.greetingAttributeName); if (attrValue == null) { LOGGER.warn("No attribute value could be found for [{}]", this.greetingAttributeName); return p.getId(); } String greetingPersonId = attrValue.toString(); if (attrValue instanceof Collection) { final Collection col =((Collection) attrValue); if (!col.isEmpty()) { greetingPersonId = col.iterator().next().toString(); LOGGER.warn("Found multiple attribute values [{}] for [{}] to greet. Picked [{}]", attrValue, this.greetingAttributeName, greetingPersonId); } } if (!StringUtils.isBlank(greetingPersonId)) { personId = greetingPersonId; } final MessageResolver resolver = new MessageBuilder().source(CODE).info().code(CODE).arg(personId).build(); messageContext.addMessage(resolver); final Message[] messages = messageContext.getMessagesBySource(CODE); if (messages == null || messages.length == 0) { LOGGER.warn("The greeting message for principal [{}] could not be resolved by the " + "code [{}] in any of the configured message resource bundles. Falling back to principal id [{}]", p, CODE, p.getId()); return p.getId(); } return messages[0].getText(); }
Example 4
Source File: DefaultRegisteredServiceUsernameProvider.java From springboot-shiro-cas-mybatis with MIT License | 4 votes |
@Override public String resolveUsername(final Principal principal, final Service service) { logger.debug("Returning the default principal id [{}] for username.", principal.getId()); return principal.getId(); }