Search in sources :

Example 96 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.

the class RegisteredServicePrincipalAttributeMultifactorAuthenticationProviderBypassEvaluatorTests method verifyNoService.

@Test
public void verifyNoService() {
    val applicationContext = new StaticApplicationContext();
    applicationContext.refresh();
    ApplicationContextProvider.holdApplicationContext(applicationContext);
    ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, MultifactorAuthenticationPrincipalResolver.identical(), UUID.randomUUID().toString());
    val provider = TestMultifactorAuthenticationProvider.registerProviderIntoApplicationContext(applicationContext);
    val eval = new DefaultChainingMultifactorAuthenticationBypassProvider();
    eval.addMultifactorAuthenticationProviderBypassEvaluator(new RegisteredServicePrincipalAttributeMultifactorAuthenticationProviderBypassEvaluator(TestMultifactorAuthenticationProvider.ID));
    val principal = CoreAuthenticationTestUtils.getPrincipal(Map.of("cn", List.of("example")));
    val authentication = CoreAuthenticationTestUtils.getAuthentication(principal);
    assertTrue(eval.shouldMultifactorAuthenticationProviderExecute(authentication, null, provider, new MockHttpServletRequest()));
}
Also used : lombok.val(lombok.val) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 97 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.

the class BaseActionTests method setUp.

@BeforeEach
public void setUp() {
    val applicationContext = new StaticApplicationContext();
    applicationContext.refresh();
    ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, CoreAuthenticationTestUtils.getAuthenticationSystemSupport(), AuthenticationSystemSupport.BEAN_NAME);
    requestContext = new MockRequestContext();
    request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    requestContext.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    setRequestContext(requestContext);
    setExternalContext(requestContext.getExternalContext());
    ((DefaultMessageContext) requestContext.getMessageContext()).setMessageSource(new AbstractMessageSource() {

        @Override
        protected MessageFormat resolveCode(final String code, final Locale locale) {
            return new MessageFormat(StringUtils.EMPTY);
        }
    });
    service = mock(InweboService.class);
    val authenticationEventExecutionPlan = new DefaultAuthenticationEventExecutionPlan();
    authenticationEventExecutionPlan.registerAuthenticationHandler(new InweboAuthenticationHandler(mock(ServicesManager.class), PrincipalFactoryUtils.newPrincipalFactory(), new InweboMultifactorAuthenticationProperties(), service));
    authenticationEventExecutionPlan.registerAuthenticationMetadataPopulator(new InweboAuthenticationDeviceMetadataPopulator());
    val authenticationManager = new DefaultAuthenticationManager(authenticationEventExecutionPlan, true, applicationContext);
    val authenticationTransactionManager = new DefaultAuthenticationTransactionManager(applicationContext, authenticationManager);
    val authenticationSystemSupport = new DefaultAuthenticationSystemSupport(authenticationTransactionManager, new DefaultPrincipalElectionStrategy(), new DefaultAuthenticationResultBuilderFactory(), new DefaultAuthenticationTransactionFactory());
    val context = CasWebflowEventResolutionConfigurationContext.builder().authenticationSystemSupport(authenticationSystemSupport).build();
    resolver = new InweboMultifactorAuthenticationWebflowEventResolver(context);
    setAuthenticationInContext(LOGIN);
}
Also used : Locale(java.util.Locale) InweboAuthenticationDeviceMetadataPopulator(org.apereo.cas.support.inwebo.authentication.InweboAuthenticationDeviceMetadataPopulator) MockServletContext(org.springframework.mock.web.MockServletContext) DefaultAuthenticationManager(org.apereo.cas.authentication.DefaultAuthenticationManager) DefaultPrincipalElectionStrategy(org.apereo.cas.authentication.principal.DefaultPrincipalElectionStrategy) AbstractMessageSource(org.springframework.context.support.AbstractMessageSource) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) lombok.val(lombok.val) InweboAuthenticationHandler(org.apereo.cas.support.inwebo.authentication.InweboAuthenticationHandler) InweboMultifactorAuthenticationWebflowEventResolver(org.apereo.cas.support.inwebo.web.flow.InweboMultifactorAuthenticationWebflowEventResolver) MessageFormat(java.text.MessageFormat) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockRequestContext(org.springframework.webflow.test.MockRequestContext) DefaultAuthenticationTransactionFactory(org.apereo.cas.authentication.DefaultAuthenticationTransactionFactory) DefaultAuthenticationTransactionManager(org.apereo.cas.authentication.DefaultAuthenticationTransactionManager) DefaultAuthenticationEventExecutionPlan(org.apereo.cas.authentication.DefaultAuthenticationEventExecutionPlan) DefaultAuthenticationResultBuilderFactory(org.apereo.cas.authentication.DefaultAuthenticationResultBuilderFactory) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) InweboMultifactorAuthenticationProperties(org.apereo.cas.configuration.model.support.mfa.InweboMultifactorAuthenticationProperties) DefaultMessageContext(org.springframework.binding.message.DefaultMessageContext) DefaultAuthenticationSystemSupport(org.apereo.cas.authentication.DefaultAuthenticationSystemSupport) InweboService(org.apereo.cas.support.inwebo.service.InweboService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 98 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.

the class JcifsConfigTests method verifyKerbSysConfig.

@Test
public void verifyKerbSysConfig() throws Exception {
    val applicationContext = new StaticApplicationContext();
    applicationContext.refresh();
    val path = new ClassPathResource("kerb5.conf").getFile().getCanonicalPath();
    val loginConf = new ClassPathResource("jaas.conf").getFile().getCanonicalPath();
    val settings = new JcifsConfig.SystemSettings();
    settings.setKerberosDebug("true");
    settings.setKerberosConf("file:" + path);
    assertDoesNotThrow(new Executable() {

        @Override
        public void execute() {
            settings.initialize(applicationContext, "file:" + loginConf);
        }
    });
}
Also used : lombok.val(lombok.val) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) Executable(org.junit.jupiter.api.function.Executable) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.jupiter.api.Test)

Example 99 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.

the class DefaultAuthenticationManagerTests method setup.

@BeforeEach
public void setup() {
    applicationContext = new StaticApplicationContext();
    applicationContext.refresh();
    ApplicationContextProvider.registerBeanIntoApplicationContext(applicationContext, CoreAuthenticationTestUtils.getAuthenticationSystemSupport(), AuthenticationSystemSupport.BEAN_NAME);
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 100 with StaticApplicationContext

use of org.springframework.context.support.StaticApplicationContext in project cas by apereo.

the class PasswordEncoderUtilsTests method verifyNoType.

@Test
public void verifyNoType() {
    val applicationContext = new StaticApplicationContext();
    applicationContext.refresh();
    val properties = new PasswordEncoderProperties();
    properties.setType(null);
    var encoder = PasswordEncoderUtils.newPasswordEncoder(properties, applicationContext);
    assertNotNull(encoder);
    properties.setType(StringUtils.EMPTY);
    encoder = PasswordEncoderUtils.newPasswordEncoder(properties, applicationContext);
    assertNotNull(encoder);
}
Also used : lombok.val(lombok.val) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) PasswordEncoderProperties(org.apereo.cas.configuration.model.core.authentication.PasswordEncoderProperties) Test(org.junit.jupiter.api.Test)

Aggregations

StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)322 Test (org.junit.jupiter.api.Test)218 lombok.val (lombok.val)159 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)59 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)39 BeforeEach (org.junit.jupiter.api.BeforeEach)36 Test (org.junit.Test)34 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)31 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)25 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)20 HashSet (java.util.HashSet)19 MockRequestContext (org.springframework.webflow.test.MockRequestContext)19 InMemoryServiceRegistry (org.apereo.cas.services.InMemoryServiceRegistry)16 MockServletContext (org.springframework.mock.web.MockServletContext)16 MultifactorAuthenticationProviderBypassProperties (org.apereo.cas.configuration.model.support.mfa.MultifactorAuthenticationProviderBypassProperties)15 BeanDefinitionReader (org.springframework.beans.factory.support.BeanDefinitionReader)13 ApplicationContext (org.springframework.context.ApplicationContext)12 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)11 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)11 QueueChannel (org.springframework.integration.channel.QueueChannel)11