List of usage examples for org.apache.shiro SecurityUtils setSecurityManager
public static void setSecurityManager(SecurityManager securityManager)
From source file:org.openscoring.service.ModelResourceTest.java
License:Open Source License
@Test public void decisionTreeIris() throws Exception { String id = "DecisionTreeIris"; // setup security manager & do login Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini"); SecurityManager securityManager = factory.getInstance(); SecurityUtils.setSecurityManager(securityManager); UserResponse user = new UserResponse(); user.setUsername("nhanndX"); user.setPassword("secret"); target("user").request(MediaType.APPLICATION_JSON).post(Entity.json(user)); assertEquals("Iris", extractSuffix(id)); deploy(id);/*from w w w. j a va 2s. c o m*/ download(id); List<EvaluationRequest> records = loadRecords(id); EvaluationRequest request = records.get(0); EvaluationResponse response = evaluate(id, request); List<EvaluationRequest> requests = Arrays.asList(records.get(0), invalidate(records.get(50)), records.get(100)); BatchEvaluationRequest batchRequest = new BatchEvaluationRequest(); batchRequest.setRequests(requests); BatchEvaluationResponse batchResponse = evaluateBatch(id, batchRequest); assertEquals("orgx##" + batchRequest.getId(), batchResponse.getId()); List<EvaluationResponse> responses = batchResponse.getResponses(); assertEquals(requests.size(), responses.size()); EvaluationRequest invalidRequest = requests.get(1); EvaluationResponse invalidResponse = responses.get(1); assertEquals(invalidRequest.getId(), invalidResponse.getId()); assertNotNull(invalidResponse.getMessage()); undeploy(id); }
From source file:org.openscoring.service.ModelResourceTest.java
License:Open Source License
@Test public void associationRulesShopping() throws Exception { // setup security manager & do login Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini"); SecurityManager securityManager = factory.getInstance(); SecurityUtils.setSecurityManager(securityManager); UserResponse user = new UserResponse(); user.setUsername("nhanndX"); user.setPassword("secret"); target("user").request(MediaType.APPLICATION_JSON).post(Entity.json(user)); String id = "AssociationRulesShopping"; assertEquals("Shopping", extractSuffix(id)); deployForm(id);/*from ww w . j a v a2 s. com*/ List<EvaluationRequest> records = loadRecords(id); BatchEvaluationRequest batchRequest = new BatchEvaluationRequest(); batchRequest.setRequests(records); BatchEvaluationResponse batchResponse = evaluateBatch(id, batchRequest); List<EvaluationRequest> aggregatedRecords = ModelResource.aggregateRequests(FieldName.create("transaction"), records); batchRequest = new BatchEvaluationRequest("aggregate"); batchRequest.setRequests(aggregatedRecords); batchResponse = evaluateBatch(id, batchRequest); assertEquals("orgx##" + batchRequest.getId(), batchResponse.getId()); evaluateCsv(id); evaluateCsvForm(id); undeployForm(id); }
From source file:org.ops4j.pax.shiro.cdi.AbstractCdiTest.java
License:Apache License
@BeforeClass public static void start() throws Exception { securityManager = new DefaultSecurityManager(); SecurityUtils.setSecurityManager(securityManager); realm = new SimpleAccountRealm("test-realm"); realm.addRole("role"); realm.addAccount("foo", "bar", "role"); realm.addAccount("bilbo", "precious", "hobbit"); realm.setRolePermissionResolver(new RolePermissionResolver() { public Collection<Permission> resolvePermissionsInRole(String roleString) { if ("role".equals(roleString)) { final Permission dp = new WildcardPermission("permission"); return Arrays.asList(dp); }//from ww w .ja v a 2 s . co m return Collections.emptyList(); } }); securityManager.setRealm(realm); }
From source file:org.ops4j.pax.shiro.cdi.AbstractCdiTest.java
License:Apache License
@AfterClass public static void close() throws Exception { SecurityUtils.setSecurityManager(null); }
From source file:org.ops4j.pax.shiro.cdi.config.CdiIniSecurityManagerFactoryTest.java
License:Apache License
@Test public void getCdiBeanFromIni() { CdiIniSecurityManagerFactory securityManagerFactory = new CdiIniSecurityManagerFactory( "classpath:test-shiro-cdi.ini", beanManager); DefaultSecurityManager securityManager = (DefaultSecurityManager) securityManagerFactory.createInstance(); assertThat(securityManager, is(notNullValue())); SecurityUtils.setSecurityManager(securityManager); Object passwordMatcher = securityManagerFactory.getBeans().get("myPasswordMatcher"); assertThat(passwordMatcher, is(instanceOf(MyPasswordMatcher.class))); IniRealm realm = (IniRealm) securityManager.getRealms().iterator().next(); assertThat(realm.getCredentialsMatcher(), is(instanceOf(MyPasswordMatcher.class))); Subject subject = SecurityUtils.getSubject(); assertThat(subject, is(notNullValue())); assertThat(subject.getPrincipal(), is(nullValue())); assertThat(subject.isAuthenticated(), is(false)); UsernamePasswordToken token = new UsernamePasswordToken("admin", "secret"); subject.login(token);//from w ww . j a va 2s . c o m assertThat(subject.isAuthenticated(), is(true)); subject.logout(); assertThat(subject.isAuthenticated(), is(false)); }
From source file:org.ops4j.pax.shiro.cdi.config.CdiIniSecurityManagerFactoryTest.java
License:Apache License
@Test public void checkInjectedSubject() { CdiIniSecurityManagerFactory securityManagerFactory = new CdiIniSecurityManagerFactory( "classpath:test-shiro-cdi.ini", beanManager); DefaultSecurityManager securityManager = (DefaultSecurityManager) securityManagerFactory.createInstance(); assertThat(securityManager, is(notNullValue())); SecurityUtils.setSecurityManager(securityManager); assertThat(subject, is(notNullValue())); assertThat(subject.getPrincipal(), is(nullValue())); assertThat(subject.isAuthenticated(), is(false)); UsernamePasswordToken token = new UsernamePasswordToken("admin", "secret"); subject.login(token);/* w w w . j a va2s .c o m*/ assertThat(subject.isAuthenticated(), is(true)); subject.logout(); assertThat(subject.isAuthenticated(), is(false)); }
From source file:org.qi4j.library.shiro.realms.AbstractQi4jRealm.java
License:Open Source License
public void activateRealm() { SecurityUtils.setSecurityManager(new DefaultSecurityManager(this)); }
From source file:org.qi4j.library.shiro.StandaloneShiroTest.java
License:Open Source License
public void documentationSupport_before() { // START SNIPPET: before IniSecurityManagerFactory factory = new IniSecurityManagerFactory("classpath:standalone-shiro.ini"); SecurityManager securityManager = factory.getInstance(); SecurityUtils.setSecurityManager(securityManager); // END SNIPPET: before }
From source file:org.solrsystem.ingest.servlet.IngestContextListener.java
License:Apache License
@Override public void contextInitialized(ServletContextEvent sce) { // Use the shiro.ini file at the root of the classpath // (file: and url: prefixes load from files and urls respectively): Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini"); SecurityManager securityManager = factory.getInstance(); // Since Vaadin doesn't really base its UI on distinct URL paths we will eschew // shiro web module entirely, we just don't need it. SecurityUtils.setSecurityManager(securityManager); }
From source file:org.sonatype.activemq.security.shiro.ShiroAuthenticationBrokerFilterTest.java
License:Open Source License
public void setUp() throws Exception { super.setUp(); PojoSimpleAccountRealm simpleAccountRealm = new PojoSimpleAccountRealm(); // jcoder has access to ALL queues and topics Set<Permission> jcoderPermissions = new HashSet<Permission>(); jcoderPermissions.add(new WildcardPermission("jms:queue:*")); jcoderPermissions.add(new WildcardPermission("jms:topic:*")); SimpleAccount jcoder = new SimpleAccount("jcoder", "jcoder123", simpleAccountRealm.getName(), Collections.<String>emptySet(), jcoderPermissions); simpleAccountRealm.add(jcoder);/*from w w w . j a v a2 s . c o m*/ // jcoder has access to all queues but NO topics Set<Permission> jbeanPermissions = new HashSet<Permission>(); jbeanPermissions.add(new WildcardPermission("jms:queue:*")); SimpleAccount jbean = new SimpleAccount("jbean", "jbean123", simpleAccountRealm.getName(), Collections.<String>emptySet(), jbeanPermissions); simpleAccountRealm.add(jbean); // onlyTestQueue has access to All topics and only the TEST queue Set<Permission> onlyTestQueuePermissions = new HashSet<Permission>(); onlyTestQueuePermissions.add(new WildcardPermission("jms:queue:TEST:read")); onlyTestQueuePermissions.add(new WildcardPermission("jms:topic:*")); SimpleAccount onlyTestQueue = new SimpleAccount("onlyTestQueue", "onlyTestQueue123", simpleAccountRealm.getName(), Collections.<String>emptySet(), onlyTestQueuePermissions); simpleAccountRealm.add(onlyTestQueue); // Set up the security manager DefaultSecurityManager securityManager = new DefaultSecurityManager(simpleAccountRealm); SecurityUtils.setSecurityManager(securityManager); // TODO maybe this should be configured as part of the Plugin and NOT using a ThreadLocal }