List of usage examples for org.apache.shiro.mgt DefaultSecurityManager DefaultSecurityManager
public DefaultSecurityManager()
From source file:ApacheShiro.ShiroMVC.java
public void CrearIni() { defaultSecurityManager = new DefaultSecurityManager(); ini = new Ini(); usuarios = ini.addSection(IniRealm.USERS_SECTION_NAME); roles = ini.addSection(IniRealm.ROLES_SECTION_NAME); // defaultSecurityManager.setRealm(new IniRealm(ini)); // SecurityUtils.setSecurityManager(defaultSecurityManager); }
From source file:com.app.test.BaseTestCase.java
License:Open Source License
protected static void setUpSecurityUtils(boolean authenticated) throws Exception { PowerMockito.spy(SecurityUtils.class); DefaultSecurityManager defaultSecurityManager = new DefaultSecurityManager(); Subject subject = new DelegatingSubject(null, authenticated, null, null, defaultSecurityManager); PowerMockito.doReturn(subject).when(SecurityUtils.class, "getSubject"); }
From source file:com.freedomotic.security.AuthImpl.java
License:Open Source License
/** * *///from ww w.jav a 2s . c o m @Override public void initBaseRealm() { DefaultSecurityManager securityManager = null; if (!realmInited && config.getBooleanProperty("KEY_SECURITY_ENABLE", true)) { baseRealm.setName(BASE_REALM_NAME); baseRealm.setResourcePath( new File(Info.PATHS.PATH_WORKDIR + "/config/security.properties").getAbsolutePath()); baseRealm.init(); pluginRealm.init(); securityManager = new DefaultSecurityManager(); //securityManager = injector.getInstance(DefaultSecurityManager.class); realmCollection.add(baseRealm); realmCollection.add(pluginRealm); securityManager.setRealms(realmCollection); realmInited = true; } SecurityUtils.setSecurityManager(securityManager); }
From source file:com.freedomotic.security.AuthImpl2.java
License:Open Source License
/** * *//*ww w .ja v a 2 s .com*/ @Override public void initBaseRealm() { DefaultSecurityManager securityManager = null; if (!realmInited && config.getBooleanProperty("KEY_SECURITY_ENABLE", true)) { baseRealm.init(); pluginRealm.init(); securityManager = new DefaultSecurityManager(); //securityManager = injector.getInstance(DefaultSecurityManager.class); realmCollection.add(baseRealm); realmCollection.add(pluginRealm); securityManager.setRealms(realmCollection); SecurityUtils.setSecurityManager(securityManager); realmInited = true; } }
From source file:com.stormpath.shiro.spring.config.AbstractShiroConfiguration.java
License:Apache License
protected SessionsSecurityManager createSecurityManager() { return new DefaultSecurityManager(); }
From source file:ddf.catalog.event.retrievestatus.AbstractDownloadsStatusEventPublisherTest.java
License:Open Source License
private void addSecurity() { org.apache.shiro.mgt.SecurityManager secManager = new DefaultSecurityManager(); PrincipalCollection principals = new SimplePrincipalCollection(USER_ID, "testrealm"); Subject subject = new Subject.Builder(secManager).principals(principals).session(new SimpleSession()) .authenticated(true).buildSubject(); ThreadContext.bind(secManager);/* w ww . jav a 2s. c om*/ ThreadContext.bind(subject); }
From source file:ddf.catalog.plugin.resource.usage.TestResourceUsagePlugin.java
License:Open Source License
private ResourceRequest getMockResourceRequest(String resourceSize, String expectedUsername) { AuthorizingRealm realm = mock(AuthorizingRealm.class); when(realm.getName()).thenReturn("mockRealm"); when(realm.isPermitted(any(PrincipalCollection.class), any(Permission.class))).thenReturn(true); Collection<Realm> realms = new ArrayList<Realm>(); realms.add(realm);/*from w w w . j a v a 2 s .co m*/ DefaultSecurityManager manager = new DefaultSecurityManager(); manager.setRealms(realms); SimplePrincipalCollection principalCollection = new SimplePrincipalCollection(new Principal() { @Override public String getName() { return expectedUsername; } @Override public String toString() { return expectedUsername; } }, realm.getName()); subject = new MockSubject(manager, principalCollection); ResourceRequest resourceRequest = mock(ResourceRequest.class); Map<String, Serializable> requestProperties = new HashMap<>(); requestProperties.put(SecurityConstants.SECURITY_SUBJECT, subject); requestProperties.put(Metacard.RESOURCE_SIZE, resourceSize); when(resourceRequest.getPropertyNames()).thenReturn(requestProperties.keySet()); when(resourceRequest.getPropertyValue(SecurityConstants.SECURITY_SUBJECT)).thenReturn(subject); when(resourceRequest.getPropertyValue(Metacard.RESOURCE_SIZE)).thenReturn(resourceSize); return resourceRequest; }
From source file:ddf.catalog.security.filter.plugin.test.FilterPluginTest.java
License:Open Source License
@Before public void setup() { AuthorizingRealm realm = mock(AuthorizingRealm.class); when(realm.getName()).thenReturn("mockRealm"); when(realm.isPermitted(any(PrincipalCollection.class), any(Permission.class))).then(makeDecision()); Collection<org.apache.shiro.realm.Realm> realms = new ArrayList<>(); realms.add(realm);//from w ww. j a v a2s . com DefaultSecurityManager manager = new DefaultSecurityManager(); manager.setRealms(realms); SimplePrincipalCollection principalCollection = new SimplePrincipalCollection(new Principal() { @Override public String getName() { return "testuser"; } }, realm.getName()); Subject systemSubject = new MockSubject(manager, principalCollection); plugin = new FilterPlugin() { @Override protected Subject getSystemSubject() { return systemSubject; } }; QueryRequestImpl request = getSampleRequest(); Map<String, Serializable> properties = new HashMap<>(); Subject subject = new MockSubject(manager, principalCollection); properties.put(SecurityConstants.SECURITY_SUBJECT, subject); request.setProperties(properties); incomingResponse = new QueryResponseImpl(request); ResourceRequest resourceRequest = mock(ResourceRequest.class); when(resourceRequest.getProperties()).thenReturn(properties); resourceResponse = new ResourceResponseImpl(resourceRequest, mock(Resource.class)); resourceResponse.setProperties(properties); DeleteRequest deleteRequest = mock(DeleteRequest.class); when(deleteRequest.getProperties()).thenReturn(properties); List<Metacard> deletedMetacards = new ArrayList<>(); deletedMetacards.add(getExactRolesMetacard()); deleteResponse = new DeleteResponseImpl(deleteRequest, properties, deletedMetacards); List<Metacard> badDeletedMetacards = new ArrayList<>(); badDeletedMetacards.add(getMoreRolesMetacard()); badDeleteResponse = new DeleteResponseImpl(deleteRequest, properties, badDeletedMetacards); createRequest = new CreateRequestImpl(getExactRolesMetacard()); createRequest.setProperties(properties); badCreateRequest = new CreateRequestImpl(getMoreRolesMetacard()); badCreateRequest.setProperties(properties); updateRequest = new UpdateRequestImpl(getExactRolesMetacard().getId(), getExactRolesMetacard()); updateRequest.setProperties(properties); ResultImpl result1 = new ResultImpl(getMoreRolesMetacard()); ResultImpl result2 = new ResultImpl(getMissingRolesMetacard()); ResultImpl result3 = new ResultImpl(getExactRolesMetacard()); ResultImpl result4 = new ResultImpl(getNoRolesMetacard()); ResultImpl result5 = new ResultImpl(getNoSecurityAttributeMetacard()); incomingResponse.addResult(result1, false); incomingResponse.addResult(result2, false); incomingResponse.addResult(result3, false); incomingResponse.addResult(result4, false); incomingResponse.addResult(result5, true); }
From source file:ddf.catalog.security.operation.plugin.OperationPluginTest.java
License:Open Source License
@Before public void setup() { plugin = new OperationPlugin(); AuthorizingRealm realm = mock(AuthorizingRealm.class); when(realm.getName()).thenReturn("mockRealm"); when(realm.isPermitted(any(PrincipalCollection.class), any(Permission.class))).then(makeDecision()); Collection<Realm> realms = new ArrayList<Realm>(); realms.add(realm);/* w w w .j a v a2 s . c o m*/ DefaultSecurityManager manager = new DefaultSecurityManager(); manager.setRealms(realms); SimplePrincipalCollection principalCollection = new SimplePrincipalCollection(new Principal() { @Override public String getName() { return "testuser"; } }, realm.getName()); subject = new MockSubject(manager, principalCollection); }
From source file:ddf.content.plugin.cataloger.TestCatalogContentPlugin.java
License:Open Source License
private void mockSecurity() { org.apache.shiro.mgt.SecurityManager secManager = new DefaultSecurityManager(); PrincipalCollection principals = new SimplePrincipalCollection(TEST_USER_NAME, TEST_REALM); org.apache.shiro.subject.Subject subject = new org.apache.shiro.subject.Subject.Builder(secManager) .principals(principals).session(new SimpleSession()).authenticated(true).buildSubject(); ThreadContext.bind(secManager);//from w ww. jav a2 s . c om ThreadContext.bind(subject); }