本文整理汇总了Java中org.apache.shiro.config.Ini类的典型用法代码示例。如果您正苦于以下问题:Java Ini类的具体用法?Java Ini怎么用?Java Ini使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Ini类属于org.apache.shiro.config包,在下文中一共展示了Ini类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shiroFilter
import org.apache.shiro.config.Ini; //导入依赖的package包/类
@Bean
public ShiroFilterFactoryBean shiroFilter() {
ShiroFilterFactoryBean factoryBean = new ShiroFilterFactoryBean();
//设置Filter映射
LinkedHashMap<String, Filter> filterMap = new LinkedHashMap<>();
DefaultCasFilter casFilter = new DefaultCasFilter();
casFilter.setFailureUrl(loginProperties.getFailureUrl()); //配置验证错误时的失败页面
casFilter.setReloginUrl(loginProperties.getCasLogin() + "&msg={0}"); //验证错误后显示登录页面,并提示错误信息。只试用于ErrorContext异常
casFilter.setLogoutUrl(loginProperties.getCasLogout());
filterMap.put("casFilter", casFilter);
LogoutFilter logoutFilter = new LogoutFilter();
logoutFilter.setRedirectUrl(loginProperties.getCasLogout() + "?service=" + loginProperties.getCasLogoutCallback());
filterMap.put("logoutFilter", logoutFilter);
filterMap.put("perms", new DefaultPermissionsAuthorizationFilter());
filterMap.put("authc", new DefaultFormAuthenticationFilter());
filterMap.put("sense", new SenseLoginFilter());
factoryBean.setFilters(filterMap);
factoryBean.setSecurityManager(securityManager());
factoryBean.setLoginUrl(loginProperties.getCasLogin());
factoryBean.setUnauthorizedUrl(loginProperties.getUnauthorizedUrl());
//加载权限配置
Ini ini = new Ini();
ini.loadFromPath(loginProperties.getShiroFilterFile());
//did they explicitly state a 'urls' section? Not necessary, but just in case:
Ini.Section section = ini.getSection(IniFilterChainResolverFactory.URLS);
if (MapUtils.isEmpty(section)) {
//no urls section. Since this _is_ a urls chain definition property, just assume the
//default section contains only the definitions:
section = ini.getSection(Ini.DEFAULT_SECTION_NAME);
}
factoryBean.setFilterChainDefinitionMap(section);
return factoryBean;
}
示例2: beautifyUrlPermissionExpression
import org.apache.shiro.config.Ini; //导入依赖的package包/类
protected String beautifyUrlPermissionExpression(String expression){
StringBuilder sb = new StringBuilder();
Scanner scanner = new Scanner(expression);
while(scanner.hasNextLine()){
String line = org.apache.shiro.util.StringUtils.clean(scanner.nextLine());
if (line == null || line.startsWith(Ini.COMMENT_POUND) || line.startsWith(Ini.COMMENT_SEMICOLON)) {
//skip empty lines and comments:
continue;
}
if(!line.endsWith("\n")){
line += "\n";
}
sb.append("\t\t" + line);
}
scanner.close();
return sb.toString();
}
示例3: getObject
import org.apache.shiro.config.Ini; //导入依赖的package包/类
public Object getObject() throws Exception {
logger.info(">>> create filter bean : {}, singleton : {}", getObjectType(), isSingleton());
ReflectionUtils.setFieldValue(ReflectionUtils.findField(ShiroFilterFactoryBean.class, "instance"), this, null);
Map<String, String> filterChainDefinitionMap = (Map<String, String>) applicationContext.getBean(Ini.Section.class);
setFilterChainDefinitionMap(filterChainDefinitionMap);
return super.getObject();
}
示例4: CentralDogmaSecurityManager
import org.apache.shiro.config.Ini; //导入依赖的package包/类
public CentralDogmaSecurityManager(File dataDir, Ini securityConfig) {
try {
sessionDao = new FileBasedSessionDAO(new File(dataDir, "_sessions").toPath());
} catch (IOException e) {
throw new IOError(e);
}
sessionManager = new CentralDogmaSessionManager(sessionDao);
final Factory<SecurityManager> factory = new IniSecurityManagerFactory(securityConfig) {
@Override
protected SecurityManager createDefaultInstance() {
DefaultSecurityManager securityManager = new DefaultSecurityManager();
securityManager.setSessionManager(sessionManager);
securityManager.setCacheManager(new MemoryConstrainedCacheManager());
return securityManager;
}
};
delegate = factory.getInstance();
}
示例5: setFilterChainDefinitions
import org.apache.shiro.config.Ini; //导入依赖的package包/类
/**
* 从数据库动态读取权限
*/
@Override
public void setFilterChainDefinitions(String definitions) {
MyShiroFilterFactoryBean.definitions = definitions;
//数据库动态权限
List<TbShiroFilter> list = systemService.getShiroFilter();
for(TbShiroFilter tbShiroFilter : list){
//字符串拼接权限
definitions = definitions+tbShiroFilter.getName() + " = "+tbShiroFilter.getPerms()+"\n";
}
log.info(definitions);
//从配置文件加载权限配置
Ini ini = new Ini();
ini.load(definitions);
Ini.Section section = ini.getSection("urls");
if (CollectionUtils.isEmpty(section)) {
section = ini.getSection("");
}
this.setFilterChainDefinitionMap(section);
}
示例6: doParse
import org.apache.shiro.config.Ini; //导入依赖的package包/类
@Override
public Ini doParse(String raw) throws IllegalArgumentException {
Ini ini;
try {
ini = Ini.fromResourcePath(raw);
} catch (ConfigurationException e) {
throw new ShiroConfigurationException(e);
}
Set<String> presentSections = ImmutableSortedSet.copyOf(ini.getSectionNames());
if (presentSections.isEmpty()) {
throw new MissingSectionsException();
}
Set<String> extraSections = Sets.difference(presentSections, ALLOWED_SECTION_NAMES);
if (!extraSections.isEmpty()) {
throw new ExtraSectionsException(extraSections);
}
return ini;
}
示例7: createRealm
import org.apache.shiro.config.Ini; //导入依赖的package包/类
@Override
public Realm createRealm(Injector injector) {
Ini ini = new Ini();
if (users != null && !users.isEmpty()) {
ini.addSection("users").putAll(users);
}
if (roles != null && !roles.isEmpty()) {
ini.addSection("roles").putAll(roles);
}
IniRealm realm = new IniRealm(ini);
realm.setIni(ini);
if (name != null) {
realm.setName(name);
}
return realm;
}
示例8: testCreateRealm
import org.apache.shiro.config.Ini; //导入依赖的package包/类
@Test
public void testCreateRealm() {
IniRealmFactory factory = new IniRealmFactory();
factory.setName("xyz");
factory.setRoles(Collections.singletonMap("r1", "p1, p2"));
factory.setUsers(Collections.singletonMap("u1", "up, r1"));
IniRealm realm = (IniRealm) factory.createRealm(mock(Injector.class));
assertEquals("xyz", realm.getName());
assertNull(realm.getResourcePath());
Ini ini = realm.getIni();
assertNotNull(realm.getIni());
assertNotNull(ini.getSection("users"));
assertNotNull(ini.getSection("roles"));
}
示例9: applyFilterChainResolver
import org.apache.shiro.config.Ini; //导入依赖的package包/类
protected void applyFilterChainResolver(Ini ini, Map<String, ?> defaults) {
if (ini == null || ini.isEmpty()) {
//nothing to use to create the resolver, just return
//(the AbstractShiroFilter allows a null resolver, in which case the original FilterChain is
// always used).
return;
}
//only create a resolver if the 'filters' or 'urls' sections are defined:
Ini.Section urls = ini.getSection(IniFilterChainResolverFactory.URLS);
Ini.Section filters = ini.getSection(IniFilterChainResolverFactory.FILTERS);
if ((urls != null && !urls.isEmpty()) || (filters != null && !filters.isEmpty())) {
//either the urls section or the filters section was defined. Go ahead and create the resolver
//and set it:
IniFilterChainResolverFactory filterChainResolverFactory = new IniFilterChainResolverFactory(ini, defaults);
filterChainResolverFactory.setFilterConfig(getFilterConfig());
FilterChainResolver resolver = filterChainResolverFactory.getInstance();
setFilterChainResolver(resolver);
}
}
示例10: getServletContextIniResource
import org.apache.shiro.config.Ini; //导入依赖的package包/类
/**
* Returns the INI instance reflecting the specified servlet context resource path or {@code null} if no
* resource was found.
*
* @param servletContextPath the servlet context resource path of the INI file to load
* @return the INI instance reflecting the specified servlet context resource path or {@code null} if no
* resource was found.
* @since 1.2
*/
protected Ini getServletContextIniResource(String servletContextPath) {
String path = WebUtils.normalize(servletContextPath);
if (getServletContext() != null) {
InputStream is = getServletContext().getResourceAsStream(path);
if (is != null) {
Ini ini = new Ini();
ini.load(is);
if (CollectionUtils.isEmpty(ini)) {
log.warn("ServletContext INI resource '" + servletContextPath + "' exists, but it did not contain " +
"any data.");
}
return ini;
}
}
return null;
}
示例11: convertPathToIni
import org.apache.shiro.config.Ini; //导入依赖的package包/类
/**
* Converts the specified file path to an {@link Ini} instance.
* <p/>
* If the path does not have a resource prefix as defined by {@link ResourceUtils#hasResourcePrefix(String)}, the
* path is expected to be resolvable by the {@code ServletContext} via
* {@link javax.servlet.ServletContext#getResourceAsStream(String)}.
*
* @param path the path of the INI resource to load into an INI instance.
* @return an INI instance populated based on the given INI resource path.
*/
protected Ini convertPathToIni(String path) {
Ini ini = new Ini();
//SHIRO-178: Check for servlet context resource and not
//only resource paths:
if (!ResourceUtils.hasResourcePrefix(path)) {
ini = getServletContextIniResource(path);
if (ini == null) {
String msg = "There is no servlet context resource corresponding to configPath '" + path + "' If " +
"the resource is located elsewhere (not immediately resolveable in the servlet context), " +
"specify an appropriate classpath:, url:, or file: resource prefix accordingly.";
throw new ConfigurationException(msg);
}
} else {
//normal resource path - load as usual:
ini.loadFromPath(path);
}
return ini;
}
示例12: getSpecifiedIni
import org.apache.shiro.config.Ini; //导入依赖的package包/类
protected Ini getSpecifiedIni(String[] configLocations) throws ConfigurationException {
Ini ini = null;
if (configLocations != null && configLocations.length > 0) {
if (configLocations.length > 1) {
log.warn("More than one Shiro .ini config location has been specified. Only the first will be " +
"used for configuration as the {} implementation does not currently support multiple " +
"files. This may be supported in the future however.", IniWebEnvironment.class.getName());
}
//required, as it is user specified:
ini = createIni(configLocations[0], true);
}
return ini;
}
示例13: getDefaultIni
import org.apache.shiro.config.Ini; //导入依赖的package包/类
protected Ini getDefaultIni() {
Ini ini = null;
String[] configLocations = getDefaultConfigLocations();
if (configLocations != null) {
for (String location : configLocations) {
ini = createIni(location, false);
if (!CollectionUtils.isEmpty(ini)) {
log.debug("Discovered non-empty INI configuration at location '{}'. Using for configuration.",
location);
break;
}
}
}
return ini;
}
示例14: createIni
import org.apache.shiro.config.Ini; //导入依赖的package包/类
/**
* Creates an {@link Ini} instance reflecting the specified path, or {@code null} if the path does not exist and
* is not required.
* <p/>
* If the path is required and does not exist or is empty, a {@link ConfigurationException} will be thrown.
*
* @param configLocation the resource path to load into an {@code Ini} instance.
* @param required if the path must exist and be converted to a non-empty {@link Ini} instance.
* @return an {@link Ini} instance reflecting the specified path, or {@code null} if the path does not exist and
* is not required.
* @throws ConfigurationException if the path is required but results in a null or empty Ini instance.
*/
protected Ini createIni(String configLocation, boolean required) throws ConfigurationException {
Ini ini = null;
if (configLocation != null) {
ini = convertPathToIni(configLocation, required);
}
if (required && CollectionUtils.isEmpty(ini)) {
String msg = "Required configuration location '" + configLocation + "' does not exist or did not " +
"contain any INI configuration.";
throw new ConfigurationException(msg);
}
return ini;
}
示例15: createFilterChainResolver
import org.apache.shiro.config.Ini; //导入依赖的package包/类
protected FilterChainResolver createFilterChainResolver() {
FilterChainResolver resolver = null;
Ini ini = getIni();
if (!CollectionUtils.isEmpty(ini)) {
//only create a resolver if the 'filters' or 'urls' sections are defined:
Ini.Section urls = ini.getSection(IniFilterChainResolverFactory.URLS);
Ini.Section filters = ini.getSection(IniFilterChainResolverFactory.FILTERS);
if (!CollectionUtils.isEmpty(urls) || !CollectionUtils.isEmpty(filters)) {
//either the urls section or the filters section was defined. Go ahead and create the resolver:
IniFilterChainResolverFactory factory = new IniFilterChainResolverFactory(ini, this.objects);
resolver = factory.getInstance();
}
}
return resolver;
}