com.cerebro.gorgone.boot.SecuritySystem.java Source code

Java tutorial

Introduction

Here is the source code for com.cerebro.gorgone.boot.SecuritySystem.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cerebro.gorgone.boot;

import static com.cerebro.gorgone.MyUI.logger;
import com.vaadin.server.VaadinServlet;
import java.io.InputStream;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.config.Ini;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;

/**
 *
 * @author matteo
 */
public class SecuritySystem {

    public SecuritySystem() {
        Ini ini = new Ini();
        InputStream shiroIni = VaadinServlet.getCurrent().getServletContext()
                .getResourceAsStream("/WEB-INF/shiro.ini");
        ini.load(shiroIni);
        Factory<org.apache.shiro.mgt.SecurityManager> factory = new IniSecurityManagerFactory(ini);
        org.apache.shiro.mgt.SecurityManager securityManager = factory.getInstance();
        SecurityUtils.setSecurityManager(securityManager);
    }

    public Subject getCurrentUser() {
        Subject currentUser = null;
        try {
            currentUser = SecurityUtils.getSubject();
        } catch (Exception ex) {
            logger.error("Errori nella creazione del soggetto: " + ex.getMessage());
        }
        return currentUser;
    }

}