// 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 org.jasig.cas.client.validation.TicketValidator;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.context.MessageSource;
import org.springframework.security.cas.authentication.CasAuthenticationProvider;
import org.springframework.security.cas.authentication.StatelessTicketCache;
import org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper;
import org.springframework.security.core.userdetails.AuthenticationUserDetailsService;
import java.util.Comparator;
import static org.assertj.core.api.Assertions.assertThat;
package com.kakawait.spring.boot.security.cas.autoconfigure;




/**
 * @author Thibaud Leprêtre
 */
public class CasAuthenticationProviderSecurityBuilderTest {

    private CasAuthenticationProviderSecurityBuilder builder;

    @Before
    public void setUp() {
        builder = new CasAuthenticationProviderSecurityBuilder();
    }

    @Test
    public void build_Default_ResolutionModeStatic() {
        assertThat(builder.build()).isExactlyInstanceOf(CasAuthenticationProvider.class);
    }

    @Test
    public void build_WithDynamicResolutionMode_InstanceOfDynamicProxyCallbackUrlCasAuthenticationProvider() {
        builder.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/test/java/com/kakawait/spring/boot/security/cas/autoconfigure/CasAuthenticationProviderSecurityBuilderTest.java
import com.kakawait.spring.security.cas.authentication.DynamicProxyCallbackUrlCasAuthenticationProvider;
import org.jasig.cas.client.validation.TicketValidator;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.context.MessageSource;
import org.springframework.security.cas.authentication.CasAuthenticationProvider;
import org.springframework.security.cas.authentication.StatelessTicketCache;
import org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper;
import org.springframework.security.core.userdetails.AuthenticationUserDetailsService;
import java.util.Comparator;
import static org.assertj.core.api.Assertions.assertThat;

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




/**
 * @author Thibaud Leprêtre
 */
public class CasAuthenticationProviderSecurityBuilderTest {

    private CasAuthenticationProviderSecurityBuilder builder;

    @Before
    public void setUp() {
        builder = new CasAuthenticationProviderSecurityBuilder();
    }

    @Test
    public void build_Default_ResolutionModeStatic() {
        assertThat(builder.build()).isExactlyInstanceOf(CasAuthenticationProvider.class);
    }

    @Test
    public void build_WithDynamicResolutionMode_InstanceOfDynamicProxyCallbackUrlCasAuthenticationProvider() {
        builder.serviceResolutionMode(CasSecurityProperties.ServiceResolutionMode.DYNAMIC);

        assertThat(builder.build()).isExactlyInstanceOf(DynamicProxyCallbackUrlCasAuthenticationProvider.class);