use of org.apache.shiro.mgt.SecurityManager in project shiro by apache.
the class DefaultWebEnvironment method getWebSecurityManager.
public WebSecurityManager getWebSecurityManager() {
SecurityManager sm = super.getSecurityManager();
assertWebSecurityManager(sm);
return (WebSecurityManager) sm;
}
use of org.apache.shiro.mgt.SecurityManager in project shiro by apache.
the class ShiroModuleTest method testEventBusAware.
/**
* @since 1.4
* @throws Exception
*/
@Test
public void testEventBusAware() throws Exception {
final MockRealm mockRealm = createMock(MockRealm.class);
final ShiroModule shiroModule = new ShiroModule() {
@Override
protected void configureShiro() {
bindRealm().to(MockRealm.class);
binder().bind(MockEventBusAware.class).asEagerSingleton();
expose(MockEventBusAware.class);
}
@Provides
public MockRealm createRealm() {
return mockRealm;
}
};
Injector injector = Guice.createInjector(shiroModule);
EventBus eventBus = injector.getInstance(EventBus.class);
SecurityManager securityManager = injector.getInstance(SecurityManager.class);
MockEventBusAware eventBusAware = injector.getInstance(MockEventBusAware.class);
assertSame(eventBus, eventBusAware.eventBus);
assertSame(eventBus, ((DefaultSecurityManager) securityManager).getEventBus());
}
use of org.apache.shiro.mgt.SecurityManager in project shiro by apache.
the class SecureRemoteInvocationExecutor method invoke.
/*--------------------------------------------
| M E T H O D S |
============================================*/
@SuppressWarnings({ "unchecked" })
public Object invoke(final RemoteInvocation invocation, final Object targetObject) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
try {
SecurityManager securityManager = this.securityManager != null ? this.securityManager : SecurityUtils.getSecurityManager();
Subject.Builder builder = new Subject.Builder(securityManager);
String host = (String) invocation.getAttribute(SecureRemoteInvocationFactory.HOST_KEY);
if (host != null) {
builder.host(host);
}
Serializable sessionId = invocation.getAttribute(SecureRemoteInvocationFactory.SESSION_ID_KEY);
if (sessionId != null) {
builder.sessionId(sessionId);
} else {
if (log.isTraceEnabled()) {
log.trace("RemoteInvocation did not contain a Shiro Session id attribute under " + "key [" + SecureRemoteInvocationFactory.SESSION_ID_KEY + "]. A Subject based " + "on an existing Session will not be available during the method invocation.");
}
}
Subject subject = builder.buildSubject();
return subject.execute(new Callable() {
public Object call() throws Exception {
return SecureRemoteInvocationExecutor.super.invoke(invocation, targetObject);
}
});
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof NoSuchMethodException) {
throw (NoSuchMethodException) cause;
} else if (cause instanceof IllegalAccessException) {
throw (IllegalAccessException) cause;
} else if (cause instanceof InvocationTargetException) {
throw (InvocationTargetException) cause;
} else {
throw new InvocationTargetException(cause);
}
} catch (Throwable t) {
throw new InvocationTargetException(t);
}
}
use of org.apache.shiro.mgt.SecurityManager in project shiro by apache.
the class ShiroFilterFactoryBean method createInstance.
/**
* This implementation:
* <ol>
* <li>Ensures the required {@link #setSecurityManager(org.apache.shiro.mgt.SecurityManager) securityManager}
* property has been set</li>
* <li>{@link #createFilterChainManager() Creates} a {@link FilterChainManager} instance that reflects the
* configured {@link #setFilters(java.util.Map) filters} and
* {@link #setFilterChainDefinitionMap(java.util.Map) filter chain definitions}</li>
* <li>Wraps the FilterChainManager with a suitable
* {@link org.apache.shiro.web.filter.mgt.FilterChainResolver FilterChainResolver} since the Shiro Filter
* implementations do not know of {@code FilterChainManager}s</li>
* <li>Sets both the {@code SecurityManager} and {@code FilterChainResolver} instances on a new Shiro Filter
* instance and returns that filter instance.</li>
* </ol>
*
* @return a new Shiro Filter reflecting any configured filters and filter chain definitions.
* @throws Exception if there is a problem creating the AbstractShiroFilter instance.
*/
protected AbstractShiroFilter createInstance() throws Exception {
log.debug("Creating Shiro Filter instance.");
SecurityManager securityManager = getSecurityManager();
if (securityManager == null) {
String msg = "SecurityManager property must be set.";
throw new BeanInitializationException(msg);
}
if (!(securityManager instanceof WebSecurityManager)) {
String msg = "The security manager does not implement the WebSecurityManager interface.";
throw new BeanInitializationException(msg);
}
FilterChainManager manager = createFilterChainManager();
// Expose the constructed FilterChainManager by first wrapping it in a
// FilterChainResolver implementation. The AbstractShiroFilter implementations
// do not know about FilterChainManagers - only resolvers:
PathMatchingFilterChainResolver chainResolver = new PathMatchingFilterChainResolver();
chainResolver.setFilterChainManager(manager);
// injection of the SecurityManager and FilterChainResolver:
return new SpringShiroFilter((WebSecurityManager) securityManager, chainResolver);
}
use of org.apache.shiro.mgt.SecurityManager in project killbill by killbill.
the class EntitlementTestSuiteWithEmbeddedDB method configureShiro.
protected void configureShiro() {
final Ini config = new Ini();
config.addSection("users");
config.getSection("users").put("EntitlementUser", "password, entitlement");
config.addSection("roles");
config.getSection("roles").put("entitlement", Permission.ACCOUNT_CAN_CREATE.toString() + "," + Permission.ENTITLEMENT_CAN_CREATE.toString() + "," + Permission.ENTITLEMENT_CAN_CHANGE_PLAN.toString() + "," + Permission.ENTITLEMENT_CAN_PAUSE_RESUME.toString() + "," + Permission.ENTITLEMENT_CAN_TRANSFER.toString() + "," + Permission.ENTITLEMENT_CAN_CANCEL.toString());
// Reset the security manager
ThreadContext.unbindSecurityManager();
final Factory<SecurityManager> factory = new IniSecurityManagerFactory(config);
final SecurityManager securityManager = factory.getInstance();
SecurityUtils.setSecurityManager(securityManager);
}
Aggregations