List of usage examples for org.apache.shiro SecurityUtils setSecurityManager
public static void setSecurityManager(SecurityManager securityManager)
From source file:uk.ac.ox.it.ords.api.database.structure.resources.AbstractResourceTest.java
License:Apache License
/** * Configure Shiro and start the server/*from w w w. j ava 2 s .co m*/ * @throws Exception */ @BeforeClass public static void initialize() throws Exception { // // Set up roles // createTestUsersAndRoles(); // // This is for unit testing only and uses the test.shiro.ini configuration // Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:test.shiro.ini"); SecurityManager securityManager = factory.getInstance(); SecurityUtils.setSecurityManager(securityManager); // // Create an embedded server with JSON processing // // // Create an embedded server with JSON processing // JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); ArrayList<Object> providers = new ArrayList<Object>(); providers.add(new JacksonJsonProvider()); //providers.add(new UnrecognizedPropertyExceptionMapper()); //providers.add(new ValidationExceptionMapper()); sf.setProviders(providers); // // Add our REST resources to the server // ArrayList<ResourceProvider> resources = new ArrayList<ResourceProvider>(); // // Add our REST resources to the server // resources.add(new SingletonResourceProvider(new Database(), true)); resources.add(new SingletonResourceProvider(new Odbc(), true)); sf.setResourceProviders(resources); // // Start the server at the endpoint // sf.setAddress(ENDPOINT_ADDRESS); server = sf.create(); databaseIds = new HashMap<String, String>(); startServer(); }
From source file:uk.ac.ox.it.ords.api.project.resources.AbstractResourceTest.java
License:Apache License
/** * Configure Shiro and start the server/*from ww w .j a v a 2 s . com*/ * @throws Exception */ @BeforeClass public static void initialize() throws Exception { // // Set up roles // createTestUsersAndRoles(); // // This is for unit testing only and uses the test.shiro.ini configuration // Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:test.shiro.ini"); SecurityManager securityManager = factory.getInstance(); SecurityUtils.setSecurityManager(securityManager); // // Create an embedded server with JSON processing // JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); ArrayList<Object> providers = new ArrayList<Object>(); providers.add(new JacksonJsonProvider()); providers.add(new UnrecognizedPropertyExceptionMapper()); providers.add(new ValidationExceptionMapper()); sf.setProviders(providers); // // Add our REST resources to the server // ArrayList<ResourceProvider> resources = new ArrayList<ResourceProvider>(); resources.add(new SingletonResourceProvider(new Project(), true)); resources.add(new SingletonResourceProvider(new ProjectRole(), true)); resources.add(new SingletonResourceProvider(new ProjectDatabase(), true)); resources.add(new SingletonResourceProvider(new ProjectInvitation(), true)); sf.setResourceProviders(resources); // // Start the server at the endpoint // sf.setAddress(ENDPOINT_ADDRESS); server = sf.create(); startServer(); }
From source file:uk.ac.ox.it.ords.api.user.resources.AbstractResourceTest.java
License:Apache License
/** * Configure Shiro and start the server/*from w w w . j a va 2s .c om*/ * @throws Exception */ @BeforeClass public static void initialize() throws Exception { // // Set up roles // if (!dbCreated) createTestUsersAndRoles(); // // This is for unit testing only and uses the test.shiro.ini configuration // Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:test.shiro.ini"); SecurityManager securityManager = factory.getInstance(); SecurityUtils.setSecurityManager(securityManager); // // Create an embedded server with JSON processing // JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean(); ArrayList<Object> providers = new ArrayList<Object>(); providers.add(new JacksonJsonProvider()); //providers.add(new UnrecognizedPropertyExceptionMapper()); //providers.add(new ValidationExceptionMapper()); sf.setProviders(providers); // // Add our REST resources to the server // ArrayList<ResourceProvider> resources = new ArrayList<ResourceProvider>(); resources.add(new SingletonResourceProvider(new UserResource(), true)); resources.add(new SingletonResourceProvider(new Verification(), true)); resources.add(new SingletonResourceProvider(new ContactRequestResource(), true)); sf.setResourceProviders(resources); // // Start the server at the endpoint // sf.setAddress(ENDPOINT_ADDRESS); server = sf.create(); startServer(); }
From source file:uk.ac.ox.it.ords.security.AbstractShiroTest.java
License:Apache License
/** * Set the security manager for testing//from ww w . ja v a2 s.co m * @param securityManager the security manager for testing */ protected static void setSecurityManager(SecurityManager securityManager) { SecurityUtils.setSecurityManager(securityManager); }
From source file:uk.ac.ox.it.ords.security.SSOFilterTest.java
License:Apache License
@BeforeClass public static void setup() { Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini"); SecurityManager securityManager = factory.getInstance(); SecurityUtils.setSecurityManager(securityManager); }
From source file:uk.co.q3c.v7.base.guice.BaseGuiceServletInjector.java
License:Apache License
/** * Module instances for the base should be added in {@link #getModules()}. Module instance for the app using V7 * should be added to {@link AppModules#appModules()} * /*from w w w . j a v a 2 s .co m*/ * @see com.google.inject.servlet.GuiceServletContextListener#getInjector() */ @Override protected Injector getInjector() { injector = Guice.createInjector(new IniModule(), new I18NModule()); injector = injector.createChildInjector(getModules()); // The SecurityManager binding is in ShiroWebModule, and therefore // DefaultShiroWebModule. By default the binding // is to DefaultWebSecurityManager SecurityManager securityManager = injector.getInstance(SecurityManager.class); SecurityUtils.setSecurityManager(securityManager); ((V7SecurityManager) securityManager).setSessionManager(new VaadinSessionManager()); return injector; }
From source file:uk.co.q3c.v7.base.view.component.LoginStatusPanelTest.java
License:Apache License
@Before public void setup() { V7SecurityManager securityManager = new V7SecurityManager(); SecurityUtils.setSecurityManager(securityManager); when(subjectPro.get()).thenReturn(subject); panel = new LoginStatusPanel(navigator, securityManager, subjectPro); loginoutBtn = ((LoginStatusPanel) panel).getLogin_logout_Button(); }
From source file:uk.co.q3c.v7.base.view.components.LoginStatusPanelTest.java
License:Apache License
@Before public void setup() { V7SecurityManager securityManager = new V7SecurityManager(); SecurityUtils.setSecurityManager(securityManager); panel = new LoginStatusPanel(navigator, securityManager); loginoutBtn = ((LoginStatusPanel) panel).getLogin_logout_Button(); }
From source file:uk.q3c.krail.core.guice.DefaultBindingManager.java
License:Apache License
protected void createInjector() { injector = Guice.createInjector(getModules()); log.debug("injector created"); // By default Shiro provides a binding to DefaultSecurityManager, but that is replaced by a binding to // KrailSecurityManager in {@link DefaultShiroModule#bindSecurityManager} (or potentially to another security manager if // the developer overrides that method) SecurityManager securityManager = injector.getInstance(SecurityManager.class); SecurityUtils.setSecurityManager(securityManager); }
From source file:uk.q3c.krail.core.guice.uiscope.UIScopeTest.java
License:Apache License
@Test public void uiScope2() { // given//from w w w . ja v a 2 s . c o m KrailSecurityManager securityManager = new KrailSecurityManager(cacheManagerOpt); // securityManager.setVaadinSessionProvider(vaadinSessionProvider); SecurityUtils.setSecurityManager(securityManager); when(subject.isPermitted(anyString())).thenReturn(true); when(subject.isPermitted(any(org.apache.shiro.authz.Permission.class))).thenReturn(true); when(mockedSession.hasLock()).thenReturn(true); // when injector = Guice.createInjector(new PushModule(), new TestModule(), new ApplicationConfigurationModule(), new ViewModule(), new UIScopeModule(), new ServicesModule(), new OptionModule().activeSource(InMemory.class), new UserModule(), new DefaultComponentModule(), new TestI18NModule(), new DefaultShiroModule(), new ShiroVaadinModule(), new VaadinSessionScopeModule(), new SitemapModule(), new TestUIModule(), new TestPersistenceModule(), new NavigationModule(), new EventBusModule(), new DataModule(), new DataTypeModule(), new UtilsModule(), new InMemoryModule().provideOptionDao()); provider = injector.getInstance(UIProvider.class); createUI(BasicUI.class); TestObject to1 = injector.getInstance(TestObject.class); createUI(BasicUI.class); TestObject to2 = injector.getInstance(TestObject.class); // then assertThat(to1).isNotNull(); assertThat(to2).isNotNull(); assertThat(to1).isNotEqualTo(to2); }