// Path: spring-security-cas-extension/src/main/java/com/kakawait/spring/security/cas/authentication/DynamicProxyCallbackUrlCasAuthenticationProvider.java
// public class DynamicProxyCallbackUrlCasAuthenticationProvider extends CasAuthenticationProvider {
//     @Override
//     public Authentication authenticate(Authentication authentication) {
//         if (authentication.getDetails() instanceof ProxyCallbackAndServiceAuthenticationDetails) {
//             if (getTicketValidator() instanceof Cas20ServiceTicketValidator) {
//                 String proxyCallbackUrl =
//                         ((ProxyCallbackAndServiceAuthenticationDetails) authentication.getDetails()).getProxyCallbackUrl();
//                 ((Cas20ServiceTicketValidator) getTicketValidator()).setProxyCallbackUrl(proxyCallbackUrl);
//             } else if (getTicketValidator() instanceof ProxyCallbackUrlAwareTicketValidator) {
//                 String proxyCallbackUrl =
//                         ((ProxyCallbackAndServiceAuthenticationDetails) authentication.getDetails()).getProxyCallbackUrl();
//                 ((ProxyCallbackUrlAwareTicketValidator) getTicketValidator()).setProxyCallbackUrl(proxyCallbackUrl);
//             }
//         }
//         return super.authenticate(authentication);
//     }
// }


import com.kakawait.spring.security.cas.authentication.DynamicProxyCallbackUrlCasAuthenticationProvider;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.jasig.cas.client.validation.TicketValidator;
import org.springframework.context.MessageSource;
import org.springframework.security.cas.authentication.CasAssertionAuthenticationToken;
import org.springframework.security.cas.authentication.CasAuthenticationProvider;
import org.springframework.security.cas.authentication.StatelessTicketCache;
import org.springframework.security.config.annotation.SecurityBuilder;
import org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper;
import org.springframework.security.core.userdetails.AuthenticationUserDetailsService;
package com.kakawait.spring.boot.security.cas.autoconfigure;


/**
 * @author Thibaud Leprêtre
 */
@Accessors(fluent = true)
@Setter
public class CasAuthenticationProviderSecurityBuilder implements SecurityBuilder<CasAuthenticationProvider> {

    private CasSecurityProperties.ServiceResolutionMode serviceResolutionMode;

    private AuthenticationUserDetailsService<CasAssertionAuthenticationToken> authenticationUserDetailsService;

    private GrantedAuthoritiesMapper grantedAuthoritiesMapper;

    private MessageSource messageSource;

    private StatelessTicketCache statelessTicketCache;

    private TicketValidator ticketValidator;

    private String key;

    @Override
    public CasAuthenticationProvider build() {
        CasAuthenticationProvider provider;
        if (serviceResolutionMode == CasSecurityProperties.ServiceResolutionMode.DYNAMIC) {
// Path: spring-security-cas-extension/src/main/java/com/kakawait/spring/security/cas/authentication/DynamicProxyCallbackUrlCasAuthenticationProvider.java
// public class DynamicProxyCallbackUrlCasAuthenticationProvider extends CasAuthenticationProvider {
//     @Override
//     public Authentication authenticate(Authentication authentication) {
//         if (authentication.getDetails() instanceof ProxyCallbackAndServiceAuthenticationDetails) {
//             if (getTicketValidator() instanceof Cas20ServiceTicketValidator) {
//                 String proxyCallbackUrl =
//                         ((ProxyCallbackAndServiceAuthenticationDetails) authentication.getDetails()).getProxyCallbackUrl();
//                 ((Cas20ServiceTicketValidator) getTicketValidator()).setProxyCallbackUrl(proxyCallbackUrl);
//             } else if (getTicketValidator() instanceof ProxyCallbackUrlAwareTicketValidator) {
//                 String proxyCallbackUrl =
//                         ((ProxyCallbackAndServiceAuthenticationDetails) authentication.getDetails()).getProxyCallbackUrl();
//                 ((ProxyCallbackUrlAwareTicketValidator) getTicketValidator()).setProxyCallbackUrl(proxyCallbackUrl);
//             }
//         }
//         return super.authenticate(authentication);
//     }
// }


// Path: cas-security-spring-boot-autoconfigure/src/main/java/com/kakawait/spring/boot/security/cas/autoconfigure/CasAuthenticationProviderSecurityBuilder.java
import com.kakawait.spring.security.cas.authentication.DynamicProxyCallbackUrlCasAuthenticationProvider;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.jasig.cas.client.validation.TicketValidator;
import org.springframework.context.MessageSource;
import org.springframework.security.cas.authentication.CasAssertionAuthenticationToken;
import org.springframework.security.cas.authentication.CasAuthenticationProvider;
import org.springframework.security.cas.authentication.StatelessTicketCache;
import org.springframework.security.config.annotation.SecurityBuilder;
import org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper;
import org.springframework.security.core.userdetails.AuthenticationUserDetailsService;

package com.kakawait.spring.boot.security.cas.autoconfigure;


/**
 * @author Thibaud Leprêtre
 */
@Accessors(fluent = true)
@Setter
public class CasAuthenticationProviderSecurityBuilder implements SecurityBuilder<CasAuthenticationProvider> {

    private CasSecurityProperties.ServiceResolutionMode serviceResolutionMode;

    private AuthenticationUserDetailsService<CasAssertionAuthenticationToken> authenticationUserDetailsService;

    private GrantedAuthoritiesMapper grantedAuthoritiesMapper;

    private MessageSource messageSource;

    private StatelessTicketCache statelessTicketCache;

    private TicketValidator ticketValidator;

    private String key;

    @Override
    public CasAuthenticationProvider build() {
        CasAuthenticationProvider provider;
        if (serviceResolutionMode == CasSecurityProperties.ServiceResolutionMode.DYNAMIC) {
            provider = new DynamicProxyCallbackUrlCasAuthenticationProvider();