Search in sources :

Example 1 with SecurityManager

use of org.apache.shiro.mgt.SecurityManager in project perry by ca-cwds.

the class AbstractApiSecurityTest method initShiro.

private static void initShiro() {
    Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");
    setSecurityManager(factory.getInstance());
    Subject subjectUnderTest = new Subject.Builder(getSecurityManager()).authenticated(true).principals(new SimplePrincipalCollection("user", "realm")).buildSubject();
    // 2. Bind the subject to the current thread:
    setSubject(subjectUnderTest);
}
Also used : IniSecurityManagerFactory(org.apache.shiro.config.IniSecurityManagerFactory) SecurityManager(org.apache.shiro.mgt.SecurityManager) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) Subject(org.apache.shiro.subject.Subject)

Example 2 with SecurityManager

use of org.apache.shiro.mgt.SecurityManager in project shiro by apache.

the class GuiceEnvironmentTest method testGetSecurityManager.

@Test
public void testGetSecurityManager() throws Exception {
    SecurityManager securityManager = createMock(SecurityManager.class);
    GuiceEnvironment underTest = new GuiceEnvironment(securityManager);
    assertSame(securityManager, underTest.getSecurityManager());
}
Also used : SecurityManager(org.apache.shiro.mgt.SecurityManager) Test(org.junit.Test)

Example 3 with SecurityManager

use of org.apache.shiro.mgt.SecurityManager in project shiro by apache.

the class DummyServiceTest method setUpClass.

@BeforeClass
public static void setUpClass() throws Exception {
    Logger log = Logger.getLogger(AspectjAnnotationsAuthorizingMethodInterceptor.class);
    log.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
    log.setLevel(Level.TRACE);
    Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiroDummyServiceTest.ini");
    SecurityManager securityManager = factory.getInstance();
    SecurityUtils.setSecurityManager(securityManager);
    SECURED_SERVICE = new SecuredDummyService();
    RESTRICTED_SERVICE = new RestrictedDummyService();
}
Also used : ConsoleAppender(org.apache.log4j.ConsoleAppender) IniSecurityManagerFactory(org.apache.shiro.config.IniSecurityManagerFactory) SimpleLayout(org.apache.log4j.SimpleLayout) SecurityManager(org.apache.shiro.mgt.SecurityManager) Logger(org.apache.log4j.Logger)

Example 4 with SecurityManager

use of org.apache.shiro.mgt.SecurityManager in project shiro by apache.

the class IniSecurityManagerFactory method createDefaults.

protected Map<String, ?> createDefaults(Ini ini, Ini.Section mainSection) {
    Map<String, Object> defaults = new LinkedHashMap<String, Object>();
    SecurityManager securityManager = createDefaultInstance();
    defaults.put(SECURITY_MANAGER_NAME, securityManager);
    if (shouldImplicitlyCreateRealm(ini)) {
        Realm realm = createRealm(ini);
        if (realm != null) {
            defaults.put(INI_REALM_NAME, realm);
        }
    }
    // The values from 'getDefaults()' will override the above.
    Map<String, ?> defaultBeans = getDefaults();
    if (!CollectionUtils.isEmpty(defaultBeans)) {
        defaults.putAll(defaultBeans);
    }
    return defaults;
}
Also used : DefaultSecurityManager(org.apache.shiro.mgt.DefaultSecurityManager) RealmSecurityManager(org.apache.shiro.mgt.RealmSecurityManager) SecurityManager(org.apache.shiro.mgt.SecurityManager) IniRealm(org.apache.shiro.realm.text.IniRealm) Realm(org.apache.shiro.realm.Realm) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with SecurityManager

use of org.apache.shiro.mgt.SecurityManager in project shiro by apache.

the class SubjectThreadState method bind.

/**
 * Binds a {@link Subject} and {@link org.apache.shiro.mgt.SecurityManager SecurityManager} to the
 * {@link ThreadContext} so they can be retrieved later by any
 * {@code SecurityUtils.}{@link org.apache.shiro.SecurityUtils#getSubject() getSubject()} calls that might occur
 * during the thread's execution.
 * <p/>
 * Prior to binding, the {@code ThreadContext}'s existing {@link ThreadContext#getResources() resources} are
 * retained so they can be restored later via the {@link #restore restore} call.
 */
public void bind() {
    SecurityManager securityManager = this.securityManager;
    if (securityManager == null) {
        // try just in case the constructor didn't find one at the time:
        securityManager = ThreadContext.getSecurityManager();
    }
    this.originalResources = ThreadContext.getResources();
    ThreadContext.remove();
    ThreadContext.bind(this.subject);
    if (securityManager != null) {
        ThreadContext.bind(securityManager);
    }
}
Also used : SecurityManager(org.apache.shiro.mgt.SecurityManager)

Aggregations

SecurityManager (org.apache.shiro.mgt.SecurityManager)36 DefaultSecurityManager (org.apache.shiro.mgt.DefaultSecurityManager)13 IniSecurityManagerFactory (org.apache.shiro.config.IniSecurityManagerFactory)11 Test (org.junit.Test)11 Injector (com.google.inject.Injector)8 Provides (com.google.inject.Provides)6 Subject (org.apache.shiro.subject.Subject)6 Session (org.apache.shiro.session.Session)5 WebSecurityManager (org.apache.shiro.web.mgt.WebSecurityManager)5 Realm (org.apache.shiro.realm.Realm)4 IniRealm (org.apache.shiro.realm.text.IniRealm)4 DefaultWebSecurityManager (org.apache.shiro.web.mgt.DefaultWebSecurityManager)4 UnavailableSecurityManagerException (org.apache.shiro.UnavailableSecurityManagerException)3 Ini (org.apache.shiro.config.Ini)3 DelegatingSubject (org.apache.shiro.subject.support.DelegatingSubject)3 AfterClass (org.junit.AfterClass)3 Callable (java.util.concurrent.Callable)2 ServletContext (javax.servlet.ServletContext)2 ConfigurationException (org.apache.shiro.config.ConfigurationException)2 ShiroModuleTest (org.apache.shiro.guice.ShiroModuleTest)2