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);
}
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());
}
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();
}
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;
}
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);
}
}
Aggregations