List of usage examples for org.apache.shiro.config Ini load
public void load(Scanner scanner)
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 av a 2 s .co m 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); 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;/* w w w . ja v a 2 s. 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;/*from www .ja va 2 s .co m*/ } 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 { // ??/* w w w . j a v a2 s . co m*/ 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 . com*/ * 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); }
From source file:com.ineunet.knife.security.DefaultChainDefinitionSectionInternal.java
License:Apache License
Section getObject() throws BeansException { Ini ini = new Ini(); ini.load(defaultChainDefinitionSection.filterChainDefinitions); //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); }/* w ww . ja v a 2 s . c o m*/ defaultChainDefinitionSection.section = section; return section; }
From source file:com.mto.arquillian.demo.security.ShiroBootstrap.java
License:Open Source License
@Override public void contextInitialized(ServletContextEvent servletContextEvent) { ServletContext ctx = servletContextEvent.getServletContext(); String shiroConfig = ctx.getInitParameter("shiroConfigFile"); InputStream in = ctx.getResourceAsStream(shiroConfig); Ini ini = new Ini(); ini.load(in); Factory<SecurityManager> factory = new IniSecurityManagerFactory(ini); SecurityManager sm = factory.getInstance(); SecurityUtils.setSecurityManager(sm); }
From source file:com.webarch.common.shiro.dynamic.DynamicPermissionServiceImpl.java
License:Apache License
/** * ?????????shiro??map/*from ww w . j a va2s . c o m*/ * {@see org.apache.shiro.spring.web.ShiroFilterFactoryBean#setFilterChainDefinitions(String)} * * @return Section */ private Map<String, String> generateSection() { Ini ini = new Ini(); ini.load(definitions); // ????? Ini.Section section = ini.getSection(IniFilterChainResolverFactory.URLS); // if (CollectionUtils.isEmpty(section)) { section = ini.getSection(Ini.DEFAULT_SECTION_NAME);//?,? } /** * ????? */ Map<String, String> permissionMap = loadDynamicPermission(); if (!CollectionUtils.isEmpty(permissionMap)) { if (CollectionUtils.isEmpty(section)) { logger.error( "*********?????URL??????*********"); return permissionMap; } else { section.putAll(permissionMap); } } return section; }
From source file:edu.usu.sdl.openstorefront.security.IniRealmManager.java
License:Apache License
@Override public List<UserRecord> findUsers(List<String> users) { List<UserRecord> userRecords = new ArrayList<>(); Set<String> userSet = new HashSet<>(users); //load config Ini ini = new Ini(); try (InputStream in = new FileInputStream(FileSystemManager.getConfig("shiro.ini"))) { ini.load(in); Section section = ini.getSection("users"); for (String user : section.keySet()) { if (userSet.contains(user)) { UserRecord userRecord = new UserRecord(); userRecord.setUsername(user); userRecords.add(userRecord); }//w ww. ja v a 2s .c o m } } catch (IOException ex) { throw new OpenStorefrontRuntimeException("Unable to read shiro.ini file.", "Check config path and permissions", ex); } return userRecords; }