use of org.apache.shiro.config.IniSecurityManagerFactory in project cas by apereo.
the class ShiroAuthenticationHandler method loadShiroConfiguration.
/**
* Sets shiro configuration to the path of the resource
* that points to the {@code shiro.ini} file.
*
* @param resource the resource
*/
public void loadShiroConfiguration(final Resource resource) {
try {
final Resource shiroResource = ResourceUtils.prepareClasspathResourceIfNeeded(resource);
if (shiroResource != null && shiroResource.exists()) {
final String location = shiroResource.getURI().toString();
LOGGER.debug("Loading Shiro configuration from [{}]", location);
final Factory<SecurityManager> factory = new IniSecurityManagerFactory(location);
final SecurityManager securityManager = factory.getInstance();
SecurityUtils.setSecurityManager(securityManager);
} else {
LOGGER.debug("Shiro configuration is not defined");
}
} catch (final Exception e) {
throw Throwables.propagate(e);
}
}
use of org.apache.shiro.config.IniSecurityManagerFactory 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);
}
use of org.apache.shiro.config.IniSecurityManagerFactory in project killbill by killbill.
the class UtilTestSuiteNoDB method configureShiro.
protected void configureShiro() {
final Ini config = new Ini();
config.addSection("users");
config.getSection("users").put("pierre", "password, creditor");
config.getSection("users").put("stephane", "password, refunder");
config.addSection("roles");
config.getSection("roles").put("creditor", Permission.INVOICE_CAN_CREDIT.toString() + "," + Permission.INVOICE_CAN_ITEM_ADJUST.toString());
config.getSection("roles").put("refunder", Permission.PAYMENT_CAN_REFUND.toString());
// Reset the security manager
ThreadContext.unbindSecurityManager();
final Factory<SecurityManager> factory = new IniSecurityManagerFactory(config);
final SecurityManager securityManager = factory.getInstance();
SecurityUtils.setSecurityManager(securityManager);
}
use of org.apache.shiro.config.IniSecurityManagerFactory in project zeppelin by apache.
the class SecurityUtils method initSecurityManager.
public static void initSecurityManager(String shiroPath) {
IniSecurityManagerFactory factory = new IniSecurityManagerFactory("file:" + shiroPath);
SecurityManager securityManager = factory.getInstance();
org.apache.shiro.SecurityUtils.setSecurityManager(securityManager);
isEnabled = true;
}
use of org.apache.shiro.config.IniSecurityManagerFactory in project killbill by killbill.
the class IniRealmProvider method get.
@Override
public IniRealm get() {
try {
final Factory<SecurityManager> factory = new IniSecurityManagerFactory(securityConfig.getShiroResourcePath());
// TODO Pierre hack - lame cast here, but we need to have Shiro go through its reflection magic
// to parse the [main] section of the ini file. Without duplicating code, this seems to be possible only
// by going through IniSecurityManagerFactory.
final DefaultSecurityManager securityManager = (DefaultSecurityManager) factory.getInstance();
final Collection<Realm> realms = securityManager.getRealms();
IniRealm iniRealm = null;
if (realms == null || realms.isEmpty()) {
iniRealm = new IniRealm(securityConfig.getShiroResourcePath());
} else {
for (final Realm cur : realms) {
if (cur instanceof IniRealm) {
iniRealm = (IniRealm) cur;
break;
}
}
}
if (iniRealm != null) {
// See JavaDoc warning: https://shiro.apache.org/static/1.2.3/apidocs/org/apache/shiro/realm/AuthenticatingRealm.html
iniRealm.setAuthenticationCachingEnabled(true);
return iniRealm;
} else {
throw new ConfigurationException();
}
} catch (final ConfigurationException e) {
log.warn("Unable to configure RBAC", e);
return new IniRealm();
}
}
Aggregations