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

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

Introduction

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

Prototype

public Ini() 

Source Link

Document

Creates a new empty 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);/*from  w w  w .  j av  a  2  s . c  o m*/

        // 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());
            }
            existing.putAll(section);
        }
    }

    setIni(ini);
    configure();
}

From source file:ApacheShiro.ShiroMVC.java

public void CrearIni() {
    defaultSecurityManager = new DefaultSecurityManager();
    ini = new Ini();
    usuarios = ini.addSection(IniRealm.USERS_SECTION_NAME);
    roles = ini.addSection(IniRealm.ROLES_SECTION_NAME);

    //        defaultSecurityManager.setRealm(new IniRealm(ini));
    //        SecurityUtils.setSecurityManager(defaultSecurityManager);
}

From source file:at.pollux.thymeleaf.shiro.dialect.ShiroDialectTest.java

License:Apache License

private static void setupShiro() {
    Ini ini = new Ini();
    Ini.Section usersSection = ini.addSection("users");
    usersSection.put(USER1, PASS1 + ",rolea,roled");
    usersSection.put(USER2, PASS2 + ",roleb,rolec");
    usersSection.put(USER3, PASS3 + ",rolec,rolee");
    Ini.Section rolesSection = ini.addSection("roles");
    rolesSection.put("rolea", "*");
    rolesSection.put("roleb", "permtype1:permaction1:perminst1");
    rolesSection.put("rolec", "permtype1:permaction2:*");
    rolesSection.put("roled", "permtype3:*");
    Factory<SecurityManager> factory = new TestIniSecurityManagerFactory(ini);
    SecurityManager secMgr = factory.getInstance();
    setSecurityManager(secMgr);//from   w ww  .ja v  a  2s.c  om
}

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);/*from w  w w .  ja  v a 2s. c o m*/

    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 {
        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:com.centfor.frame.shiro.FrameShiroFilterFactoryBean.java

License:Apache License

/**
 * A convenience method that sets the {@link #setFilterChainDefinitionMap(java.util.Map) filterChainDefinitionMap}
 * property by accepting a {@link java.util.Properties Properties}-compatible string (multi-line key/value pairs).
 * Each key/value pair must conform to the format defined by the
 * {@link FilterChainManager#createChain(String,String)} JavaDoc - each property key is an ant URL
 * path expression and the value is the comma-delimited chain definition.
 *
 * @param definitions a {@link java.util.Properties Properties}-compatible string (multi-line key/value pairs)
 *                    where each key/value pair represents a single urlPathExpression-commaDelimitedChainDefinition.
 *///from  w  w w. j a v  a2 s .com
public void setFilterChainDefinitions(String definitions) {
    Ini ini = new Ini();
    ini.load(definitions);
    //did they explicitly state a 'urls' section?  Not necessary, but just in case:
    Ini.Section section = ini.getSection(IniFilterChainResolverFactory.URLS);
    if (CollectionUtils.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);
    }
    setFilterChainDefinitionMap(section);
}

From source file:com.cerebro.gorgone.boot.SecuritySystem.java

public SecuritySystem() {
    Ini ini = new Ini();
    InputStream shiroIni = VaadinServlet.getCurrent().getServletContext()
            .getResourceAsStream("/WEB-INF/shiro.ini");
    ini.load(shiroIni);// w ww  . j  av  a 2s  .c o  m
    Factory<org.apache.shiro.mgt.SecurityManager> factory = new IniSecurityManagerFactory(ini);
    org.apache.shiro.mgt.SecurityManager securityManager = factory.getInstance();
    SecurityUtils.setSecurityManager(securityManager);
}

From source file:com.cerebro.gorgone.landingpage.Login.java

public Login() {
    InputStream iniFile = VaadinServlet.getCurrent().getServletContext()
            .getResourceAsStream("/WEB-INF/shiro.ini");
    if (iniFile == null) {
        logger.error("Il file Shiro.ini non esiste");
        return;/*from  www.  ja  va 2s. co m*/
    } else {
        logger.info("File Shiro.ini presente");
    }
    Ini ini = new Ini();
    ini.load(iniFile);
    Factory<org.apache.shiro.mgt.SecurityManager> factory = new IniSecurityManagerFactory(ini);
    org.apache.shiro.mgt.SecurityManager securityManager = factory.getInstance();
    SecurityUtils.setSecurityManager(securityManager);

    email.focus();
    errorMessage.setVisible(false);
    this.addComponents(email, password, errorMessage, rememberMe, loginB);

    loginB.addClickListener((Button.ClickEvent e) -> {
        logger.info("Tentativo di connessione");
        Subject currentUser = SecurityUtils.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken(email.getValue(), password.getValue());
        token.setRememberMe(rememberMe.getValue());
        try {
            currentUser.login(token);
            Session session = currentUser.getSession();
            User user = new User();
            user.loadUser();
            //session.setAttribute("User", user);
            getUI().setContent(new Game());
            VaadinService.reinitializeSession(VaadinService.getCurrentRequest());
        } catch (Exception ex) {
            logger.error(ex.toString());
            email.setValue("");
            password.setValue("");
            errorMessage.setVisible(true);
        }
    });
}

From source file:com.cerebro.provevaadin.Start.java

public Start() {

    InputStream iniFile = VaadinServlet.getCurrent().getServletContext()
            .getResourceAsStream("/WEB-INF/shiro.ini");
    if (iniFile == null) {
        logger.error("Il file Shiro.ini non esiste");
        return;/*w w w  .jav a  2 s . c om*/
    } else {
        logger.info("File presente");
    }
    Ini ini = new Ini();
    ini.load(iniFile);
    Factory<SecurityManager> factory = new IniSecurityManagerFactory(ini);
    SecurityManager securityManager = factory.getInstance();
    SecurityUtils.setSecurityManager(securityManager);

    HorizontalLayout root = new HorizontalLayout();
    root.setWidth("800px");
    root.setHeight("600px");
    this.addComponent(root);
    this.setComponentAlignment(root, Alignment.MIDDLE_CENTER);

    FormLayout loginDiv = new FormLayout();
    root.addComponent(loginDiv);
    username.focus();
    errorMessage.setVisible(false);
    loginDiv.addComponents(username, password, rememberMe, login, errorMessage);

    login.addClickListener((Button.ClickEvent e) -> {
        logger.info("Pulsante: " + e.toString());
        Subject currentUser = SecurityUtils.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken(username.getValue(), password.getValue());
        token.setRememberMe(rememberMe.getValue());
        try {
            currentUser.login(token);
            if (currentUser.hasRole("firsttime")) {
                logger.info("Configurazione parametri del primo avvio");
                getUI().setContent(new FirstTime());
            } else {
                logger.info("Classe di gioco principale");
                getUI().setContent(new Game());
                VaadinService.reinitializeSession(VaadinService.getCurrentRequest());
            }
        } catch (Exception ex) {
            logger.error("Errore nel login: " + ex.getMessage());
            username.setValue("");
            password.setValue("");
            errorMessage.setVisible(true);
        }
    });

    FormLayout signInForm = new FormLayout();
    root.addComponent(signInForm);
    usernameSignIn.focus();
    sesso.addItems("Maschio", "Femmina");
    signInForm.addComponents(usernameSignIn, passwordSignIn, passwordConf, nome, cognome, sesso, eta, signIn);
    signIn.addClickListener((Button.ClickEvent event) -> {
        logger.info("Iscrizione al sito");
        User utente = new User();
        utente.setEmail(usernameSignIn.getValue());
        utente.setPassword(passwordSignIn.getValue());
        utente.setNomeUtente(nome.getValue());
        utente.setCognomeUtente(cognome.getValue());
        utente.setSessoUtente(sesso.getValue().toString());
        utente.setDataNascitaUtente(eta.getValue());
        SignIn signInWindow = new SignIn(utente);
        signInWindow.center();
        UI.getCurrent().addWindow(signInWindow);
    });

}

From source file:com.codestudio.dorm.web.security.shiro.ChainDefinitionSectionMetaSource.java

License:Open Source License

@Override
public Section getObject() throws Exception {
    // ??/*  ww w .j  a v a2  s.com*/
    Ini ini = new Ini();
    // url
    ini.load(filterChainDefinitions);
    Ini.Section section = ini.getSection(Ini.DEFAULT_SECTION_NAME);
    return section;
}

From source file:com.ethercis.logonservice.security.ServiceSecurityManager.java

License:Apache License

/**
 * initialize the service<p>//from  www  . j a  v a  2 s . c om
 * Service initialization consists in:<p>
 * <ul>
 * <li>loading the policy file</li>
 * </ul>
 */
public void doInit(RunTimeSingleton glob, ServiceInfo serviceInfo) throws ServiceManagerException {
    this.global = (glob == null) ? RunTimeSingleton.instance() : glob;

    String policyType = get(Constants.POLICY_TYPE_TAG, "DEBUG");

    //        if (serviceInfo != null && serviceInfo.getParameters().containsKey(Constants.POLICY_TYPE_TAG))
    //            policyType = (String) serviceInfo.getParameters().get(Constants.POLICY_TYPE_TAG);
    //        else //look in environment or default
    //          policyType = global.getProperty().get(Constants.POLICY_TYPE_TAG, "DEBUG");

    switch (policyType) { //Java 1.8 !
    case "XML":
        policyMode = Constants.POLICY_XML;
        break;
    case "LDAP":
        policyMode = Constants.POLICY_LDAP;
        break;
    case "JDBC":
        policyMode = Constants.POLICY_JDBC;
        break;
    case "DEBUG":
        policyMode = Constants.POLICY_DEBUG;
        break;
    case "SHIRO":
        policyMode = Constants.POLICY_SHIRO;
        //initialize Shiro security manager with the specified policy
        try {
            String inipath = (String) serviceInfo.getParameters().get("server.security.shiro.inipath");
            if (inipath != null) {
                inipath = global.getProperty().get("server.security.shiro.inipath", "");
                if (inipath.length() == 0) {
                    throw new ServiceManagerException(global, SysErrorCode.INTERNAL_ILLEGALARGUMENT, ME,
                            "No ini path supplied for Shiro configuration, please set server.security.shiro.inipath");

                }
            }
            Ini configuration = new Ini();
            InputStream inputStream = new FileInputStream(inipath);
            configuration.load(inputStream);
            Factory<org.apache.shiro.mgt.SecurityManager> factory = new IniSecurityManagerFactory(
                    configuration);
            org.apache.shiro.mgt.SecurityManager securityManager = factory.getInstance();
            SecurityUtils.setSecurityManager(securityManager);
        } catch (Exception e) {
            throw new ServiceManagerException(glob, SysErrorCode.RESOURCE_CONFIGURATION, ME,
                    "Could not initialize Shiro framework:" + e);
        }
        break;
    default:
        throw new IllegalArgumentException("Supplied policy mode is not supported:" + policyType);

    }

    AnnotatedMBean.RegisterMBean(serviceId, ServiceSecurityManagerMBean.class, this);
}