List of usage examples for org.apache.shiro SecurityUtils setSecurityManager
public static void setSecurityManager(SecurityManager securityManager)
From source file:org.apache.geode.internal.security.IntegratedSecurityService.java
License:Apache License
public void setSecurityManager(SecurityManager securityManager) { if (securityManager == null) { return;/* ww w . j a v a2 s .c om*/ } this.securityManager = securityManager; Realm realm = new CustomAuthRealm(securityManager); DefaultSecurityManager shiroManager = new DefaultSecurityManager(realm); SecurityUtils.setSecurityManager(shiroManager); increaseShiroGlobalSessionTimeout(shiroManager); isIntegratedSecurity = true; isClientAuthenticator = false; isPeerAuthenticator = false; }
From source file:org.apache.geode.internal.security.IntegratedSecurityServiceConstructorTest.java
License:Apache License
@After public void after() throws Exception { if (securityService != null) { securityService.close();/*from w ww . j av a 2 s.co m*/ } // some test manually set the shiro security manager SecurityUtils.setSecurityManager(null); }
From source file:org.apache.geode.internal.security.IntegratedSecurityServiceTest.java
License:Apache License
@Test public void testInitWithOutsideShiroSecurityManager() { SecurityUtils.setSecurityManager(new DefaultSecurityManager()); securityService.initSecurity(properties); assertTrue(securityService.isIntegratedSecurity()); }
From source file:org.apache.geode.internal.security.SecurityServiceFactoryTest.java
License:Apache License
@After public void after() throws Exception { if (service != null) { service.close();/*from w w w . ja va2s . c o m*/ } // some test manually set the shiro security manager SecurityUtils.setSecurityManager(null); }
From source file:org.apache.geode.internal.security.SecurityServiceFactoryTest.java
License:Apache License
@Test public void createWithOutsideShiro() throws Exception { SecurityUtils.setSecurityManager(mock(SecurityManager.class)); // create the service with empty properties, but we would still end up with // an IntegratedSecurityService service = SecurityServiceFactory.create(properties); assertThat(service).isInstanceOf(IntegratedSecurityService.class); assertThat(service.getSecurityManager()).isNull(); assertThat(service.getPostProcessor()).isNull(); }
From source file:org.apache.geode.internal.security.SecurityServiceTest.java
License:Apache License
@Test public void testInitWithOutsideShiroSecurityManager() { SecurityUtils.setSecurityManager(new DefaultSecurityManager()); this.securityService = SecurityServiceFactory.create(properties); assertThat(this.securityService.isIntegratedSecurity()).isTrue(); }
From source file:org.apache.geode.tools.pulse.tests.Server.java
License:Apache License
public Server(int port, String properties, String jsonAuthFile) throws Exception { this.propFile = properties; mbs = ManagementFactory.getPlatformMBeanServer(); url = new JMXServiceURL(formJMXServiceURLString(DEFAULT_HOST, port)); // Load the beans first, otherwise we get access denied loadMBeans();//from ww w . j a v a 2s .co m if (jsonAuthFile != null) { System.setProperty("spring.profiles.active", "pulse.authentication.gemfire"); Map<String, Object> env = new HashMap<String, Object>(); // set up Shiro Security Manager Properties securityProperties = new Properties(); securityProperties.setProperty(TestSecurityManager.SECURITY_JSON, jsonAuthFile); Realm realm = new CustomAuthRealm(TestSecurityManager.class.getName(), securityProperties); SecurityManager securityManager = new DefaultSecurityManager(realm); SecurityUtils.setSecurityManager(securityManager); // register the AccessControll bean AccessControlMBean acc = new AccessControlMBean(); ObjectName accessControlMBeanON = new ObjectName(ResourceConstants.OBJECT_NAME_ACCESSCONTROL); MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer(); platformMBeanServer.registerMBean(acc, accessControlMBeanON); // wire in the authenticator and authorizaton JMXShiroAuthenticator interceptor = new JMXShiroAuthenticator(); env.put(JMXConnectorServer.AUTHENTICATOR, interceptor); cs = JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs); cs.setMBeanServerForwarder(new MBeanServerWrapper()); // set up the AccessControlMXBean } else { System.setProperty("spring.profiles.active", "pulse.authentication.default"); cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs); } try { java.rmi.registry.LocateRegistry.createRegistry(port); System.out.println("RMI registry ready."); } catch (Exception e) { System.out.println("Exception starting RMI registry:"); e.printStackTrace(); } cs.start(); }
From source file:org.apache.isis.security.shiro.ShiroAuthenticatorOrAuthorizorTest.java
License:Apache License
@After public void tearDown() throws Exception { Subject subject = SecurityUtils.getSubject(); if (subject != null) { subject.logout();/*from w w w . j a v a 2 s. c o m*/ } SecurityUtils.setSecurityManager(null); }
From source file:org.apache.isis.security.shiro.ShiroAuthenticatorOrAuthorizorTest.java
License:Apache License
@Test public void happyCase() throws Exception { Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini"); SecurityManager securityManager = factory.getInstance(); SecurityUtils.setSecurityManager(securityManager); assertThat(authOrAuth.canAuthenticate(AuthenticationRequestPassword.class), is(true)); AuthenticationRequest ar = new AuthenticationRequestPassword("lonestarr", "vespa"); AuthenticationSession isisAuthSession = authOrAuth.authenticate(ar, null); assertThat(isisAuthSession, is(not(nullValue()))); assertThat(isisAuthSession.getUserName(), is("lonestarr")); assertThat(isisAuthSession.getValidationCode(), is(nullValue())); Identifier changeAddressIdentifier = Identifier.actionIdentifier("com.mycompany.myapp.Customer", "changeAddress", String.class, String.class); assertThat(authOrAuth.isVisibleInAnyRole(changeAddressIdentifier), is(true)); Identifier changeEmailIdentifier = Identifier.actionIdentifier("com.mycompany.myapp.Customer", "changeEmail", String.class); assertThat(authOrAuth.isVisibleInAnyRole(changeEmailIdentifier), is(true)); Identifier submitOrderIdentifier = Identifier.actionIdentifier("com.mycompany.myapp.Order", "submit"); assertThat(authOrAuth.isVisibleInAnyRole(submitOrderIdentifier), is(true)); Identifier cancelOrderIdentifier = Identifier.actionIdentifier("com.mycompany.myapp.Order", "cancel"); assertThat(authOrAuth.isVisibleInAnyRole(cancelOrderIdentifier), is(false)); }
From source file:org.apache.isis.security.shiro.ShiroAuthenticatorOrAuthorizorTest.java
License:Apache License
@Test public void vetoing() throws Exception { Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini"); SecurityManager securityManager = factory.getInstance(); SecurityUtils.setSecurityManager(securityManager); AuthenticationRequest ar = new AuthenticationRequestPassword("darkhelmet", "ludicrousspeed"); authOrAuth.authenticate(ar, null);/*ww w . j a v a 2s. c om*/ Identifier changeAddressIdentifier = Identifier.actionIdentifier("com.mycompany.myapp.Customer", "changeAddress", String.class, String.class); assertThat(authOrAuth.isVisibleInAnyRole(changeAddressIdentifier), is(true)); Identifier removeCustomerIdentifier = Identifier.actionIdentifier("com.mycompany.myapp.Customer", "remove"); assertThat(authOrAuth.isVisibleInAnyRole(removeCustomerIdentifier), is(false)); }