Search in sources :

Example 1 with WebIniSecurityManagerFactory

use of org.apache.shiro.web.config.WebIniSecurityManagerFactory in project shiro by apache.

the class IniShiroFilter method applySecurityManager.

protected Map<String, ?> applySecurityManager(Ini ini) {
    WebIniSecurityManagerFactory factory;
    if (CollectionUtils.isEmpty(ini)) {
        factory = new WebIniSecurityManagerFactory();
    } else {
        factory = new WebIniSecurityManagerFactory(ini);
    }
    // Create the security manager and check that it implements WebSecurityManager.
    // Otherwise, it can't be used with the filter.
    SecurityManager securityManager = factory.getInstance();
    if (!(securityManager instanceof WebSecurityManager)) {
        String msg = "The configured security manager is not an instance of WebSecurityManager, so " + "it can not be used with the Shiro servlet filter.";
        throw new ConfigurationException(msg);
    }
    setSecurityManager((WebSecurityManager) securityManager);
    return factory.getBeans();
}
Also used : WebSecurityManager(org.apache.shiro.web.mgt.WebSecurityManager) WebSecurityManager(org.apache.shiro.web.mgt.WebSecurityManager) SecurityManager(org.apache.shiro.mgt.SecurityManager) ConfigurationException(org.apache.shiro.config.ConfigurationException) WebIniSecurityManagerFactory(org.apache.shiro.web.config.WebIniSecurityManagerFactory)

Example 2 with WebIniSecurityManagerFactory

use of org.apache.shiro.web.config.WebIniSecurityManagerFactory in project shiro by apache.

the class DefaultWebSecurityManagerTest method testBuildNonWebSubjectWithDefaultServletContainerSessionManager.

/**
 * Asserts fix for <a href="https://issues.apache.org/jira/browse/SHIRO-350">SHIRO-350</a>.
 */
@Test
public void testBuildNonWebSubjectWithDefaultServletContainerSessionManager() {
    Ini ini = new Ini();
    Ini.Section section = ini.addSection(IniRealm.USERS_SECTION_NAME);
    section.put("user1", "user1");
    WebIniSecurityManagerFactory factory = new WebIniSecurityManagerFactory(ini);
    WebSecurityManager securityManager = (WebSecurityManager) factory.getInstance();
    PrincipalCollection principals = new SimplePrincipalCollection("user1", "iniRealm");
    Subject subject = new Subject.Builder(securityManager).principals(principals).buildSubject();
    assertNotNull(subject);
    assertEquals("user1", subject.getPrincipal());
}
Also used : Ini(org.apache.shiro.config.Ini) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) WebIniSecurityManagerFactory(org.apache.shiro.web.config.WebIniSecurityManagerFactory) WebSubject(org.apache.shiro.web.subject.WebSubject) Subject(org.apache.shiro.subject.Subject) Test(org.junit.Test)

Aggregations

WebIniSecurityManagerFactory (org.apache.shiro.web.config.WebIniSecurityManagerFactory)2 ConfigurationException (org.apache.shiro.config.ConfigurationException)1 Ini (org.apache.shiro.config.Ini)1 SecurityManager (org.apache.shiro.mgt.SecurityManager)1 PrincipalCollection (org.apache.shiro.subject.PrincipalCollection)1 SimplePrincipalCollection (org.apache.shiro.subject.SimplePrincipalCollection)1 Subject (org.apache.shiro.subject.Subject)1 WebSecurityManager (org.apache.shiro.web.mgt.WebSecurityManager)1 WebSubject (org.apache.shiro.web.subject.WebSubject)1 Test (org.junit.Test)1