Example usage for org.apache.shiro.config Ini loadFromPath

List of usage examples for org.apache.shiro.config Ini loadFromPath

Introduction

In this page you can find the example usage for org.apache.shiro.config Ini loadFromPath.

Prototype

public void loadFromPath(String resourcePath) throws ConfigurationException 

Source Link

Document

Loads data from the specified resource path into this current Ini instance.

Usage

From source file:annis.security.MultipleIniWebEnvironment.java

License:Apache License

@Override
public void init() throws ShiroException {
    Ini ini = new Ini();

    Preconditions.checkNotNull(getConfigLocations());

    for (String p : getConfigLocations()) {
        Ini subIni = new Ini(ini);
        subIni.loadFromPath(p);

        // add all values from the sub file to the main configuration
        for (Section section : subIni.getSections()) {
            Section existing = ini.getSection(section.getName());
            if (existing == null) {
                existing = ini.addSection(section.getName());
            }/* w  ww.  j a  v a  2s.c o  m*/
            existing.putAll(section);
        }
    }

    setIni(ini);
    configure();
}

From source file:com.caricah.iotracah.core.security.DefaultSecurityHandler.java

License:Apache License

public SecurityManager createSecurityManager(String securityFilePath) throws UnRetriableException {

    Ini ini = new Ini();
    ini.loadFromPath(securityFilePath);

    IOTIniSecurityManagerFactory iniSecurityManagerFactory = new IOTIniSecurityManagerFactory(ini,
            getIotSecurityDatastore(), getDefaultPartitionName());

    SecurityManager securityManager = iniSecurityManagerFactory.getInstance();

    if (securityManager instanceof IOTSecurityManager) {

        //configure the security manager.
        IOTSecurityManager iotSecurityManager = (IOTSecurityManager) securityManager;
        DefaultSessionManager sessionManager = (DefaultSessionManager) iotSecurityManager.getSessionManager();

        SecurityUtils.setSecurityManager(iotSecurityManager);

        //Assign session dao from the security datastore.
        sessionManager.setSessionDAO(getIotSecurityDatastore());

        sessionManager.setSessionListeners(getSessionListenerList());
        sessionManager.setSessionValidationSchedulerEnabled(true);
        sessionManager.setSessionValidationInterval(1000);

        return securityManager;

    } else {/*from www  . ja va2  s. c  o m*/
        throw new UnRetriableException(
                "Security manager has to be an instance of the default security manager (DefaultSecurityManager). "
                        + securityManager.getClass().getName() + " was used instead.");
    }
}

From source file:org.apache.activemq.shiro.env.IniEnvironment.java

License:Apache License

@Override
public void init() throws ShiroException {
    //this.environment and this.securityManager are null.  Try Ini config:
    Ini ini = this.ini;
    if (ini != null) {
        apply(ini);/* ww  w  .  ja  va  2s .  c  o m*/
    }

    if (this.objects.isEmpty() && this.iniConfig != null) {
        ini = new Ini();
        ini.load(this.iniConfig);
        apply(ini);
    }

    if (this.objects.isEmpty() && this.iniResourePath != null) {
        ini = new Ini();
        ini.loadFromPath(this.iniResourePath);
        apply(ini);
    }

    if (this.objects.isEmpty()) {
        if (ResourceUtils.resourceExists("classpath:shiro.ini")) {
            ini = new Ini();
            ini.loadFromPath("classpath:shiro.ini");
            apply(ini);
        }
    }

    if (this.objects.isEmpty()) {
        String msg = "Configuration error.  All heuristics for acquiring Shiro INI config "
                + "have been exhausted.  Ensure you configure one of the following properties: "
                + "1) ini 2) iniConfig 3) iniResourcePath and the Ini sections are not empty.";
        throw new ConfigurationException(msg);
    }

    LifecycleUtils.init(this.objects.values());
}

From source file:org.obiba.opal.core.upgrade.security.HashShiroIniPasswordUpgradeStepTest.java

License:Open Source License

@Test
public void testExecute() throws Exception {

    String iniFileMd5 = new Md5Hash(iniFile).toHex();

    upgradeStep.execute(null);/*w w  w  . j a v a 2 s.c  o  m*/

    assertThat(iniBackup.exists()).isTrue();
    assertThat(new Md5Hash(iniBackup).toHex()).isEqualTo(iniFileMd5);
    assertThat(destIniFile.exists()).isTrue();
    assertThat(new Md5Hash(destIniFile).toHex()).isNotEqualTo(iniFileMd5);

    Ini ini = new Ini();
    ini.loadFromPath(destIniFile.getAbsolutePath());
    Ini.Section section = ini.getSection(IniRealm.USERS_SECTION_NAME);
    assertThat(section).isNotNull();
    assertThat(section).hasSize(3);
    for (String username : usernamePassword.keySet()) {
        assertThat(section.containsKey(username)).isTrue();
        String[] passwordAndRolesArray = StringUtils.split(section.get(username));
        String encrypted = passwordAndRolesArray[0];
        assertThat(passwordService.passwordsMatch(usernamePassword.get(username), encrypted)).isTrue();
    }

}

From source file:org.obiba.opal.core.upgrade.v2_0_x.HashShiroIniPasswordUpgradeStep.java

License:Open Source License

private Map<String, String> getUsernamePasswords() {
    Ini ini = new Ini();
    ini.loadFromPath(srcIniFile.getAbsolutePath());
    Ini.Section section = ini.getSection(IniRealm.USERS_SECTION_NAME);
    if (section == null || section.isEmpty()) {
        return Collections.emptyMap();
    }//w ww  .j  a v a 2  s .c o  m

    Map<String, String> map = new LinkedHashMap<>();
    for (Map.Entry<String, String> entry : section.entrySet()) {
        String username = entry.getKey();
        String[] passwordAndRolesArray = StringUtils.split(entry.getValue());
        String password = passwordAndRolesArray[0];
        map.put(username, password);
    }
    return map;
}

From source file:org.opendaylight.aaa.shiro.web.env.KarafIniWebEnvironment.java

License:Open Source License

/**
 *
 * @param path/*from w ww.  jav a 2 s. c om*/
 *            the file path, which is either absolute or relative to
 *            <code>$KARAF_HOME</code>
 * @return Ini loaded from <code>path</code>
 */
static Ini createShiroIni(final String path) throws FileNotFoundException {
    File f = new File(path);
    Ini ini = new Ini();
    final String fileBasedIniPath = createFileBasedIniPath(f.getAbsolutePath());
    ini.loadFromPath(fileBasedIniPath);
    return ini;
}