13693261870
2022-09-20 a666b5f9741ef9b21f547d3b2141752a0383c70c
src/java/org/apereo/cas/CentralAuthenticationServiceImpl.java
@@ -52,6 +52,10 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
/**
 * @author Tanbin
 * @date   2018-12-12
 */
@Transactional(readOnly = false, transactionManager = "ticketTransactionManager")
public class CentralAuthenticationServiceImpl extends AbstractCentralAuthenticationService {
  private static final long serialVersionUID = -8943828074939533986L;
@@ -64,6 +68,7 @@
  @Timed(name = "DESTROY_TICKET_GRANTING_TICKET_TIMER")
  @Metered(name = "DESTROY_TICKET_GRANTING_TICKET_METER")
  @Counted(name = "DESTROY_TICKET_GRANTING_TICKET_COUNTER", monotonic = true)
  @Override
  public List<LogoutRequest> destroyTicketGrantingTicket(String ticketGrantingTicketId) {
    try {
      this.logger.debug("Removing ticket [{}] from registry...", ticketGrantingTicketId);
@@ -84,6 +89,7 @@
  @Timed(name = "GRANT_SERVICE_TICKET_TIMER")
  @Metered(name = "GRANT_SERVICE_TICKET_METER")
  @Counted(name = "GRANT_SERVICE_TICKET_COUNTER", monotonic = true)
  @Override
  public ServiceTicket grantServiceTicket(String ticketGrantingTicketId, Service service, AuthenticationResult authenticationResult) throws AuthenticationException, AbstractTicketException {
    TicketGrantingTicket ticketGrantingTicket = (TicketGrantingTicket)getTicket(ticketGrantingTicketId, TicketGrantingTicket.class);
    RegisteredService registeredService = this.servicesManager.findServiceBy(service);
@@ -113,9 +119,9 @@
      currentAuthentication = context.getAuthentication();
      if (currentAuthentication != null) {
        Authentication original = ticketGrantingTicket.getAuthentication();
        if (!currentAuthentication.getPrincipal().equals(original.getPrincipal()))
          throw new MixedPrincipalException(currentAuthentication, currentAuthentication
              .getPrincipal(), original.getPrincipal());
        if (!currentAuthentication.getPrincipal().equals(original.getPrincipal())) {
          throw new MixedPrincipalException(currentAuthentication, currentAuthentication.getPrincipal(), original.getPrincipal());
        }
      } 
    } 
    return currentAuthentication;
@@ -125,6 +131,7 @@
  @Timed(name = "GRANT_PROXY_TICKET_TIMER")
  @Metered(name = "GRANT_PROXY_TICKET_METER")
  @Counted(name = "GRANT_PROXY_TICKET_COUNTER", monotonic = true)
  @Override
  public ProxyTicket grantProxyTicket(String proxyGrantingTicket, Service service) throws AbstractTicketException {
    ProxyGrantingTicket proxyGrantingTicketObject = (ProxyGrantingTicket)getTicket(proxyGrantingTicket, ProxyGrantingTicket.class);
    RegisteredService registeredService = this.servicesManager.findServiceBy(service);
@@ -154,6 +161,7 @@
  @Timed(name = "CREATE_PROXY_GRANTING_TICKET_TIMER")
  @Metered(name = "CREATE_PROXY_GRANTING_TICKET_METER")
  @Counted(name = "CREATE_PROXY_GRANTING_TICKET_COUNTER", monotonic = true)
  @Override
  public ProxyGrantingTicket createProxyGrantingTicket(String serviceTicketId, AuthenticationResult authenticationResult) throws AuthenticationException, AbstractTicketException {
    CurrentCredentialsAndAuthentication.bindCurrent(authenticationResult.getAuthentication());
    ServiceTicket serviceTicket = (ServiceTicket)this.ticketRegistry.getTicket(serviceTicketId, ServiceTicket.class);
@@ -180,6 +188,7 @@
  @Timed(name = "VALIDATE_SERVICE_TICKET_TIMER")
  @Metered(name = "VALIDATE_SERVICE_TICKET_METER")
  @Counted(name = "VALIDATE_SERVICE_TICKET_COUNTER", monotonic = true)
  @Override
  public Assertion validateServiceTicket(String serviceTicketId, Service service) throws AbstractTicketException {
    if (!ticketAuthenticityIsVerified(serviceTicketId)) {
      this.logger.info("Service ticket [{}] is not a valid ticket issued by CAS.", serviceTicketId);
@@ -212,7 +221,7 @@
      Principal principal = authentication.getPrincipal();
      RegisteredServiceAttributeReleasePolicy attributePolicy = registeredService.getAttributeReleasePolicy();
      this.logger.debug("Attribute policy [{}] is associated with service [{}]", attributePolicy, registeredService);
      Map<String, Object> attributesToRelease = (attributePolicy != null) ? attributePolicy.getAttributes(principal) : new HashMap();
      Map<String, Object> attributesToRelease = (attributePolicy != null) ? attributePolicy.getAttributes(principal) : new HashMap(5);
      String principalId = registeredService.getUsernameAttributeProvider().resolveUsername(principal, selectedService);
      Principal modifiedPrincipal = this.principalFactory.createPrincipal(principalId, attributesToRelease);
      AuthenticationBuilder builder = DefaultAuthenticationBuilder.newInstance(authentication);
@@ -235,6 +244,7 @@
  @Timed(name = "CREATE_TICKET_GRANTING_TICKET_TIMER")
  @Metered(name = "CREATE_TICKET_GRANTING_TICKET_METER")
  @Counted(name = "CREATE_TICKET_GRANTING_TICKET_COUNTER", monotonic = true)
  @Override
  public TicketGrantingTicket createTicketGrantingTicket(AuthenticationResult authenticationResult) throws AuthenticationException, AbstractTicketException {
    Authentication authentication = authenticationResult.getAuthentication();
    Service service = authenticationResult.getService();