org.jasig.cas.web.support.CasArgumentExtractor Java Examples

The following examples show how to use org.jasig.cas.web.support.CasArgumentExtractor. 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: RegisteredServiceAttributeMultiFactorAuthenticationArgumentExtractorTests.java    From cas-mfa with Apache License 2.0 6 votes vote down vote up
@Test
public void testServiceWithNoAttributeValue() {
    final List<ArgumentExtractor> set = new ArrayList<>();
    set.add(new CasArgumentExtractor());
    
    final MultiFactorWebApplicationServiceFactory factory = mock(MultiFactorWebApplicationServiceFactory.class);
    final AuthenticationMethodVerifier verifier = mock(AuthenticationMethodVerifier.class);

    final RegisteredService svc = TestUtils.getRegisteredService(CAS_SERVICE);
    final DefaultRegisteredServiceProperty prop = new DefaultRegisteredServiceProperty();
    svc.getProperties().put(MultiFactorAuthenticationSupportingWebApplicationService.CONST_PARAM_AUTHN_METHOD, prop);
    
    final ServicesManager mgmr = mock(ServicesManager.class);
    when(mgmr.findServiceBy(anyInt())).thenReturn(svc);
    when(mgmr.findServiceBy(any(Service.class))).thenReturn(svc);
    
    final RegisteredServiceAttributeMultiFactorAuthenticationArgumentExtractor extractor = 
            new RegisteredServiceAttributeMultiFactorAuthenticationArgumentExtractor(set, factory, mgmr, verifier);
    
    final MultiFactorAuthenticationSupportingWebApplicationService webSvc =
            (MultiFactorAuthenticationSupportingWebApplicationService) extractor.extractService(getRequest());
    assertNull(webSvc);
}
 
Example #2
Source File: RegisteredServiceAttributeMultiFactorAuthenticationArgumentExtractorTests.java    From cas-mfa with Apache License 2.0 6 votes vote down vote up
@Test
public void testServiceWithDifferentServiceType() {
    final List<ArgumentExtractor> set = new ArrayList<>();
    set.add(new CasArgumentExtractor());
    
    final MultiFactorWebApplicationServiceFactory factory = mock(MultiFactorWebApplicationServiceFactory.class);
    final AuthenticationMethodVerifier verifier = mock(AuthenticationMethodVerifier.class);
    
    final RegisteredService svc = mock(RegisteredService.class);
    when(svc.getId()).thenReturn(0L);
    when(svc.getServiceId()).thenReturn(CAS_SERVICE);
    
    final ServicesManager mgmr = mock(ServicesManager.class);
    when(mgmr.findServiceBy(anyInt())).thenReturn(svc);
    when(mgmr.findServiceBy(any(Service.class))).thenReturn(svc);
    
    final RegisteredServiceAttributeMultiFactorAuthenticationArgumentExtractor extractor = 
            new RegisteredServiceAttributeMultiFactorAuthenticationArgumentExtractor(set, factory, mgmr, verifier);

    final MultiFactorAuthenticationSupportingWebApplicationService webSvc =
            (MultiFactorAuthenticationSupportingWebApplicationService) extractor.extractService(getRequest());
    assertNull(webSvc);
}
 
Example #3
Source File: WebUtilTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Test
public void verifyFindService() {
    final SamlArgumentExtractor openIdArgumentExtractor = new SamlArgumentExtractor();
    final CasArgumentExtractor casArgumentExtractor = new CasArgumentExtractor();
    final ArgumentExtractor[] argumentExtractors = new ArgumentExtractor[] {
            openIdArgumentExtractor, casArgumentExtractor};
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("service", "test");

    final Service service = WebUtils.getService(Arrays
            .asList(argumentExtractors), request);

    assertEquals("test", service.getId());
}
 
Example #4
Source File: AbstractServiceValidateControllerTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Before
public void onSetUp() throws Exception {
    final StaticApplicationContext context = new StaticApplicationContext();
    context.refresh();
    this.serviceValidateController = new ServiceValidateController();
    this.serviceValidateController.setCentralAuthenticationService(getCentralAuthenticationService());
    final Cas20ProxyHandler proxyHandler = new Cas20ProxyHandler();
    proxyHandler.setHttpClient(new SimpleHttpClientFactoryBean().getObject());
    this.serviceValidateController.setProxyHandler(proxyHandler);
    this.serviceValidateController.setApplicationContext(context);
    this.serviceValidateController.setArgumentExtractor(new CasArgumentExtractor());
    this.serviceValidateController.setServicesManager(this.servicesManager);
}
 
Example #5
Source File: InitialFlowSetupActionTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    this.warnCookieGenerator = new CookieRetrievingCookieGenerator();
    this.tgtCookieGenerator = new CookieRetrievingCookieGenerator();
    this.action.setTicketGrantingTicketCookieGenerator(this.tgtCookieGenerator);
    this.action.setWarnCookieGenerator(this.warnCookieGenerator);
    final ArgumentExtractor[] argExtractors = new ArgumentExtractor[] {new CasArgumentExtractor()};
    this.action.setArgumentExtractors(Arrays.asList(argExtractors));

    this.servicesManager = mock(ServicesManager.class);
    when(this.servicesManager.findServiceBy(any(Service.class))).thenReturn(TestUtils.getRegisteredService("test"));
    this.action.setServicesManager(this.servicesManager);

    this.action.afterPropertiesSet();
}
 
Example #6
Source File: WebUtilTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Test
public void testFindService() {
    final SamlArgumentExtractor openIdArgumentExtractor = new SamlArgumentExtractor();
    final CasArgumentExtractor casArgumentExtractor = new CasArgumentExtractor();
    final ArgumentExtractor[] argumentExtractors = new ArgumentExtractor[] {
            openIdArgumentExtractor, casArgumentExtractor};
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("service", "test");

    final Service service = WebUtils.getService(Arrays
            .asList(argumentExtractors), request);

    assertEquals("test", service.getId());
}
 
Example #7
Source File: InitialFlowSetupActionTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    this.warnCookieGenerator = new CookieRetrievingCookieGenerator();
    this.warnCookieGenerator.setCookiePath("");
    this.tgtCookieGenerator = new CookieRetrievingCookieGenerator();
    this.tgtCookieGenerator.setCookiePath("");
    this.action.setTicketGrantingTicketCookieGenerator(this.tgtCookieGenerator);
    this.action.setWarnCookieGenerator(this.warnCookieGenerator);
    final ArgumentExtractor[] argExtractors = new ArgumentExtractor[] {new CasArgumentExtractor()};
    this.action.setArgumentExtractors(Arrays.asList(argExtractors));
    this.action.afterPropertiesSet();
    this.action.afterPropertiesSet();
}
 
Example #8
Source File: ServiceValidateControllerTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Before
public void onSetUp() throws Exception {
    StaticApplicationContext context = new StaticApplicationContext();
    context.refresh();
    this.serviceValidateController = new ServiceValidateController();
    this.serviceValidateController.setCentralAuthenticationService(getCentralAuthenticationService());
    final Cas20ProxyHandler proxyHandler = new Cas20ProxyHandler();
    proxyHandler.setHttpClient(new SimpleHttpClient());
    this.serviceValidateController.setProxyHandler(proxyHandler);
    this.serviceValidateController.setApplicationContext(context);
    this.serviceValidateController.setArgumentExtractor(new CasArgumentExtractor());
}
 
Example #9
Source File: ServiceThemeResolverTests.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    this.servicesManager = new DefaultServicesManagerImpl(new InMemoryServiceRegistryDaoImpl());

    this.serviceThemeResolver = new ServiceThemeResolver();
    this.serviceThemeResolver.setDefaultThemeName("test");
    this.serviceThemeResolver.setServicesManager(this.servicesManager);
    this.serviceThemeResolver.setArgumentExtractors(Arrays.asList((ArgumentExtractor) new CasArgumentExtractor()));
    final Map<String, String> mobileBrowsers = new HashMap<String, String>();
    mobileBrowsers.put("Mozilla", "theme");
    this.serviceThemeResolver.setMobileBrowsers(mobileBrowsers);
}
 
Example #10
Source File: RegisteredServiceAttributeMultiFactorAuthenticationArgumentExtractorTests.java    From cas-mfa with Apache License 2.0 5 votes vote down vote up
@Test
public void testServiceWithDefaultMfaAttribute() {
    final List<ArgumentExtractor> set = new ArrayList<>();
    set.add(new CasArgumentExtractor());
    
    final MultiFactorWebApplicationServiceFactory factory = mock(MultiFactorWebApplicationServiceFactory.class);
    when(factory.create(anyString(), anyString(), anyString(), any(Response.ResponseType.class),
            anyString(), any(AuthenticationMethodSource.class)))
        .thenReturn(getMfaService());
    
    final AuthenticationMethodVerifier verifier = mock(AuthenticationMethodVerifier.class);

    final RegisteredService svc = TestUtils.getRegisteredService(CAS_SERVICE);
    final DefaultRegisteredServiceProperty prop = new DefaultRegisteredServiceProperty();
    prop.setValues(Collections.singleton(CAS_AUTHN_METHOD));
    svc.getProperties().put(MultiFactorAuthenticationSupportingWebApplicationService.CONST_PARAM_AUTHN_METHOD, prop);
    
    final ServicesManager mgmr = mock(ServicesManager.class);
    when(mgmr.findServiceBy(anyInt())).thenReturn(svc);
    when(mgmr.findServiceBy(any(Service.class))).thenReturn(svc);
    
    final RegisteredServiceAttributeMultiFactorAuthenticationArgumentExtractor extractor = 
            new RegisteredServiceAttributeMultiFactorAuthenticationArgumentExtractor(set, factory, mgmr, verifier);

    final MultiFactorAuthenticationSupportingWebApplicationService webSvc =
            (MultiFactorAuthenticationSupportingWebApplicationService) extractor.extractService(getRequest());
    assertNotNull(webSvc);
    assertEquals(webSvc.getAuthenticationMethod(), CAS_AUTHN_METHOD);
}
 
Example #11
Source File: RegisteredServiceAttributeMultiFactorAuthenticationArgumentExtractorTests.java    From cas-mfa with Apache License 2.0 5 votes vote down vote up
@Test
public void testServiceWithMfaRole() {
    final List<ArgumentExtractor> set = new ArrayList<>();
    set.add(new CasArgumentExtractor());

    final MultiFactorWebApplicationServiceFactory factory = mock(MultiFactorWebApplicationServiceFactory.class);
    when(factory.create(anyString(), anyString(), anyString(), any(Response.ResponseType.class),
            anyString(), any(AuthenticationMethodSource.class)))
            .thenReturn(getMfaService());

    final AuthenticationMethodVerifier verifier = mock(AuthenticationMethodVerifier.class);

    final RegisteredService svc = TestUtils.getRegisteredService(CAS_SERVICE);
    DefaultRegisteredServiceProperty prop = new DefaultRegisteredServiceProperty();
    prop.setValues(Collections.singleton(CAS_AUTHN_METHOD));
    svc.getProperties().put(MultiFactorAuthenticationSupportingWebApplicationService.CONST_PARAM_AUTHN_METHOD, prop);

    prop = new DefaultRegisteredServiceProperty();
    svc.getProperties().put(RegisteredServiceMfaRoleProcessor.MFA_ATTRIBUTE_NAME, prop);

    prop = new DefaultRegisteredServiceProperty();
    prop.setValues(Collections.singleton(CAS_AUTHN_METHOD));
    svc.getProperties().put(RegisteredServiceMfaRoleProcessor.MFA_ATTRIBUTE_PATTERN, prop);

    final ServicesManager mgmr = mock(ServicesManager.class);
    when(mgmr.findServiceBy(anyInt())).thenReturn(svc);
    when(mgmr.findServiceBy(any(Service.class))).thenReturn(svc);

    final RegisteredServiceAttributeMultiFactorAuthenticationArgumentExtractor extractor =
            new RegisteredServiceAttributeMultiFactorAuthenticationArgumentExtractor(set, factory, mgmr, verifier);

    final MultiFactorAuthenticationSupportingWebApplicationService webSvc =
            (MultiFactorAuthenticationSupportingWebApplicationService) extractor.extractService(getRequest());
    assertNull(webSvc);
}
 
Example #12
Source File: RequestParameterMultiFactorAuthenticationArgumentExtractorTests.java    From cas-mfa with Apache License 2.0 4 votes vote down vote up
public RequestParameterMultiFactorAuthenticationArgumentExtractorTests() {
    this.supportedArgumentExtractors = new ArrayList<>();
    this.supportedArgumentExtractors.add(new CasArgumentExtractor());
    this.supportedArgumentExtractors.add(new SamlArgumentExtractor());
    this.mfaWebApplicationServiceFactory = new DefaultMultiFactorWebApplicationServiceFactory();
}