Java Code Examples for org.apache.shiro.io.ResourceUtils

The following examples show how to use org.apache.shiro.io.ResourceUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: supplierShop   Source File: ShiroConfig.java    License: MIT License 6 votes vote down vote up
/**
 * 返回配置文件流 避免ehcache配置文件一直被占用,无法完全销毁项目重新部署
 */
protected InputStream getCacheManagerConfigFileInputStream()
{
    String configFile = "classpath:ehcache/ehcache-shiro.xml";
    InputStream inputStream = null;
    try
    {
        inputStream = ResourceUtils.getInputStreamForPath(configFile);
        byte[] b = IOUtils.toByteArray(inputStream);
        InputStream in = new ByteArrayInputStream(b);
        return in;
    }
    catch (IOException e)
    {
        throw new ConfigurationException(
                "Unable to obtain input stream for cacheManagerConfigFile [" + configFile + "]", e);
    }
    finally
    {
        IOUtils.closeQuietly(inputStream);
    }
}
 
Example 2
/**
 * 返回配置文件流 避免ehcache配置文件一直被占用,无法完全销毁项目重新部署
 */
protected InputStream getCacheManagerConfigFileInputStream()
{
    String configFile = "classpath:ehcache/ehcache-shiro.xml";
    InputStream inputStream = null;
    try
    {
        inputStream = ResourceUtils.getInputStreamForPath(configFile);
        byte[] b = IOUtils.toByteArray(inputStream);
        return new ByteArrayInputStream(b);
    }
    catch (IOException e)
    {
        throw new ConfigurationException(
                "Unable to obtain input stream for cacheManagerConfigFile [" + configFile + "]", e);
    }
    finally
    {
        IOUtils.closeQuietly(inputStream);
    }
}
 
Example 3
Source Project: v-mock   Source File: AuthConfig.java    License: MIT License 5 votes vote down vote up
/**
 * 返回配置文件流 避免ehcache配置文件一直被占用,无法完全销毁项目重新部署
 */
protected InputStream getCacheManagerConfigFileInputStream() {
    String configFile = "classpath:ehcache/ehcache-shiro.xml";
    try {
        @Cleanup InputStream inputStream = ResourceUtils.getInputStreamForPath(configFile);
        byte[] readBytes = IoUtil.readBytes(inputStream);
        InputStream in = new ByteArrayInputStream(readBytes);
        return in;
    } catch (IOException e) {
        throw new ConfigurationException(
                "Unable to obtain input stream for cacheManagerConfigFile [" + configFile + "]", e);
    }
}
 
Example 4
Source Project: RuoYi   Source File: ShiroConfig.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 返回配置文件流 避免ehcache配置文件一直被占用,无法完全销毁项目重新部署
 */
private InputStream getCacheManagerConfigFileInputStream(){
    String configFile = "classpath:ehcache/ehcache-shiro.xml";
    try(InputStream inputStream = ResourceUtils.getInputStreamForPath(configFile)){
        byte[] b = IOUtils.toByteArray(inputStream);
        return new ByteArrayInputStream(b);
    }catch (IOException e){
        throw new ConfigurationException(
                "Unable to obtain input stream for cacheManagerConfigFile [" + configFile + "]", e);
    }
}
 
Example 5
Source Project: ehcache-shiro   Source File: EhcacheShiroManager.java    License: Apache License 2.0 5 votes vote down vote up
private URL getResource() throws MalformedURLException {
  String cacheManagerConfigFile = getCacheManagerConfigFile();
  String configFileWithoutPrefix = stripPrefix(cacheManagerConfigFile);
  if (cacheManagerConfigFile.startsWith(ResourceUtils.CLASSPATH_PREFIX)) {
    return ClassUtils.getResource(configFileWithoutPrefix);
  }

  String url = ResourceUtils.hasResourcePrefix(cacheManagerConfigFile) ? configFileWithoutPrefix
          : cacheManagerConfigFile;

  return new URL(url);
}
 
Example 6
Source Project: cassandra-reaper   Source File: LoginResourceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testShiroConfig() throws IOException {
  try (InputStream is = ResourceUtils.getInputStreamForPath("classpath:shiro.ini")) {
    Ini ini = new Ini();
    ini.load(is);
    new WebIniSecurityManagerFactory(ini).getInstance();
  }
}
 
Example 7
Source Project: cassandra-reaper   Source File: LoginResourceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testLogin() throws IOException {
  try (InputStream is = ResourceUtils.getInputStreamForPath("classpath:shiro.ini")) {
    Ini ini = new Ini();
    ini.load(is);
    new WebIniSecurityManagerFactory(ini).getInstance().authenticate(new UsernamePasswordToken("admin", "admin"));
  }
}
 
Example 8
Source Project: cassandra-reaper   Source File: LoginResourceLdapTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testLoginLdap() throws IOException {
  try (InputStream is = ResourceUtils.getInputStreamForPath("classpath:test-shiro-ldap.ini")) {
    Ini ini = new Ini();
    ini.load(is);
    int port = embeddedLdapRule.embeddedServerPort();
    ini.setSectionProperty("main", "ldapRealm.contextFactory.url", "ldap://localhost:" + port);
    new WebIniSecurityManagerFactory(ini).getInstance().authenticate(new UsernamePasswordToken("sclaus", "abcdefg"));
  }
}
 
Example 9
Source Project: attic-aurora   Source File: ShiroIniConverterTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test(expected = ParameterException.class)
public void testDoParseNonexistent() {
  parser.convert(ResourceUtils.CLASSPATH_PREFIX + NONEXISTENT_RESOURCE);
}