SecurityServiceFactory { public static SecurityService create() { return new LegacySecurityService(); } private  SecurityServiceFactory(); static SecurityService create(); static SecurityService create(Properties securityProps); static SecurityService create(Properties securityProps, CacheConfig cacheConfig); static SecurityService create(Properties securityProps,
      SecurityManager preferredSecurityManager, PostProcessor preferredPostProcessor);  }
@Test public void createWithNoArgument() throws Exception { service = SecurityServiceFactory.create(); assertThat(service).isInstanceOf(LegacySecurityService.class); }
@Test public void createWithPropsWithNothingOrAuthenticators() throws Exception { service = SecurityServiceFactory.create(properties); assertThat(service).isInstanceOf(LegacySecurityService.class); assertThat(service.isClientSecurityRequired()).isFalse(); assertThat(service.isPeerSecurityRequired()).isFalse(); properties.setProperty(SECURITY_CLIENT_AUTHENTICATOR, "com.abc.Auth"); service = SecurityServiceFactory.create(properties); assertThat(service).isInstanceOf(LegacySecurityService.class); assertThat(service.isClientSecurityRequired()).isTrue(); assertThat(service.isPeerSecurityRequired()).isFalse(); properties.setProperty(SECURITY_PEER_AUTHENTICATOR, "com.abc.PeerAuth"); service = SecurityServiceFactory.create(properties); assertThat(service).isInstanceOf(LegacySecurityService.class); assertThat(service.isClientSecurityRequired()).isTrue(); assertThat(service.isPeerSecurityRequired()).isTrue(); }
@Test public void createWithPropsWithSecurityManager() throws Exception { properties.setProperty(SECURITY_MANAGER, SimpleSecurityManager.class.getName()); service = SecurityServiceFactory.create(properties); assertThat(service).isInstanceOf(IntegratedSecurityService.class); assertThat(service.getSecurityManager()).isNotNull(); assertThat(service.getPostProcessor()).isNull(); properties.setProperty(SECURITY_POST_PROCESSOR, TestPostProcessor.class.getName()); service = SecurityServiceFactory.create(properties); assertThat(service).isInstanceOf(IntegratedSecurityService.class); assertThat(service.getSecurityManager()).isNotNull(); assertThat(service.getPostProcessor()).isNotNull(); }
@Test public void createWithPropsWithShiro() throws Exception { properties.setProperty(SECURITY_SHIRO_INIT, "shiro.ini"); service = SecurityServiceFactory.create(properties); assertThat(service).isInstanceOf(IntegratedSecurityService.class); assertThat(service.getSecurityManager()).isNull(); assertThat(service.getPostProcessor()).isNull(); }
@Test public void shiroOverwritesSecurityManager() throws Exception { properties.setProperty(SECURITY_SHIRO_INIT, "shiro.ini"); properties.setProperty(SECURITY_MANAGER, SimpleSecurityManager.class.getName()); service = SecurityServiceFactory.create(properties); assertThat(service).isInstanceOf(IntegratedSecurityService.class); assertThat(service.getSecurityManager()).isNull(); assertThat(service.getPostProcessor()).isNull(); }
@Test public void createWithOutsideShiro() throws Exception { SecurityUtils.setSecurityManager(mock(SecurityManager.class)); service = SecurityServiceFactory.create(properties); assertThat(service).isInstanceOf(IntegratedSecurityService.class); assertThat(service.getSecurityManager()).isNull(); assertThat(service.getPostProcessor()).isNull(); }
@Test public void cacheConfigSecurityManagerOverideShiro() throws Exception { properties.setProperty(SECURITY_SHIRO_INIT, "shiro.ini"); when(cacheConfig.getSecurityManager()).thenReturn(securityManager); service = SecurityServiceFactory.create(properties, cacheConfig); assertThat(service).isInstanceOf(IntegratedSecurityService.class); assertThat(service.getSecurityManager()).isNotNull(); assertThat(service.getPostProcessor()).isNull(); }
@Test public void cacheConfigOverideProperties_securityManager() throws Exception { properties.setProperty(SECURITY_MANAGER, SimpleSecurityManager.class.getName()); when(cacheConfig.getSecurityManager()).thenReturn(securityManager); service = SecurityServiceFactory.create(properties, cacheConfig); assertThat(service).isInstanceOf(IntegratedSecurityService.class); assertThat(service.getSecurityManager()).isEqualTo(securityManager); assertThat(service.getPostProcessor()).isNull(); }
@Test public void cacheConfigOverideProperties_postProcessor() throws Exception { properties.setProperty(SECURITY_MANAGER, SimpleSecurityManager.class.getName()); properties.setProperty(SECURITY_POST_PROCESSOR, TestPostProcessor.class.getName()); when(cacheConfig.getPostProcessor()).thenReturn(postProcessor); service = SecurityServiceFactory.create(properties, cacheConfig); assertThat(service).isInstanceOf(IntegratedSecurityService.class); assertThat(service.getSecurityManager()).isInstanceOf(SimpleSecurityManager.class); assertThat(service.getPostProcessor()).isEqualTo(postProcessor); }
@Test public void cacheConfigSecurityManagerWithPropertyPostProcessor() throws Exception { properties.setProperty(SECURITY_POST_PROCESSOR, TestPostProcessor.class.getName()); when(cacheConfig.getSecurityManager()).thenReturn(securityManager); service = SecurityServiceFactory.create(properties, cacheConfig); assertThat(service).isInstanceOf(IntegratedSecurityService.class); assertThat(service.getSecurityManager()).isEqualTo(securityManager); assertThat(service.getPostProcessor()).isInstanceOf(TestPostProcessor.class); }
@Test public void cacheConfigPostProcessorWithPropertySecurityManager() throws Exception { properties.setProperty(SECURITY_MANAGER, SimpleSecurityManager.class.getName()); when(cacheConfig.getPostProcessor()).thenReturn(postProcessor); service = SecurityServiceFactory.create(properties, cacheConfig); assertThat(service).isInstanceOf(IntegratedSecurityService.class); assertThat(service.getSecurityManager()).isInstanceOf(SimpleSecurityManager.class); assertThat(service.getPostProcessor()).isEqualTo(postProcessor); }