001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.shiro.env; 020 021import java.util.function.Function; 022 023import org.apache.shiro.config.Ini; 024import org.apache.shiro.ini.IniSecurityManagerFactory; 025 026/** 027 * Basic usage:<p> 028 * <code> 029 * Environment env = new BasicIniEnvironment("classpath:shiro.ini"); 030 * SecurityManager securityManager = env.getSecurityManager(); 031 * </code> 032 * 033 * @since 1.5 034 */ 035public class BasicIniEnvironment extends DefaultEnvironment { 036 @SuppressWarnings({"deprecation", "checkstyle:JavadocVariable"}) 037 public static final String INI_REALM_NAME = IniSecurityManagerFactory.INI_REALM_NAME; 038 039 public BasicIniEnvironment(Ini ini) { 040 this(ini, (name) -> null); 041 } 042 043 public BasicIniEnvironment(Ini ini, Function<String, ?> alternateObjectSupplier) { 044 @SuppressWarnings("deprecation") 045 var securityManagerFactory = new IniSecurityManagerFactory(ini); 046 securityManagerFactory.getReflectionBuilder().setAlternateObjectSupplier(alternateObjectSupplier); 047 setSecurityManager(securityManagerFactory.getInstance()); 048 } 049 050 public BasicIniEnvironment(String iniResourcePath) { 051 this(Ini.fromResourcePath(iniResourcePath)); 052 } 053 054 public BasicIniEnvironment(String iniResourcePath, Function<String, ?> alternateObjectSupplier) { 055 this(Ini.fromResourcePath(iniResourcePath), alternateObjectSupplier); 056 } 057}