本文整理汇总了Java中org.apache.shiro.web.util.WebUtils.getRequiredWebEnvironment方法的典型用法代码示例。如果您正苦于以下问题:Java WebUtils.getRequiredWebEnvironment方法的具体用法?Java WebUtils.getRequiredWebEnvironment怎么用?Java WebUtils.getRequiredWebEnvironment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.shiro.web.util.WebUtils
的用法示例。
在下文中一共展示了WebUtils.getRequiredWebEnvironment方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
/**
* Configures this instance based on the existing {@link org.apache.shiro.web.env.WebEnvironment} instance
* available to the currently accessible {@link #getServletContext() servletContext}.
*
* @see org.apache.shiro.web.env.EnvironmentLoaderListener
* @since 1.2
*/
@Override
public void init() throws Exception {
WebEnvironment env = WebUtils.getRequiredWebEnvironment(getServletContext());
setSecurityManager(env.getWebSecurityManager());
FilterChainResolver resolver = env.getFilterChainResolver();
if (resolver != null) {
setFilterChainResolver(resolver);
}
}
示例2: init
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
/**
* @see org.apache.wicket.Application#init()
*/
@Override
public void init() {
super.init();
String version = "0.0.17";
System.setProperty("MyOpenTraderWebVersion", version);
// Check the properties
PropertiesFactory pf = PropertiesFactory.getInstance();
ServletContext context = this.getServletContext();
String configDir = pf.getConfigDir();
// If the configDir is already set, use this one otherwise get the
// context
if (configDir == null) {
configDir = context.getRealPath("/WEB-INF/conf");
pf.setConfigDir(configDir);
}
System.out.println("*** STARTING NEW MYOPENTRADER WEB INSTANCE ***");
System.out.println("Using Config directory: " + configDir);
System.out.println("Using context path: " + context.getContextPath());
System.out.println("**********");
// Configure the log4j properties
PropertyConfigurator.configure(pf.getConfigDir() + "/log4j.properties");
// The following lines ensure that the context is set for SHIRO. If not,
// the securityFactory will not get a subject
WebEnvironment wm = WebUtils.getRequiredWebEnvironment(context);
WebSecurityManager wsm = wm.getWebSecurityManager();
ThreadContext.bind(wsm);
}
示例3: printDDBody
import org.apache.shiro.web.util.WebUtils; //导入方法依赖的package包/类
public static String printDDBody(String context_App_RealPath, HttpServletRequest request)
{
StringBuilder authInfoAndButtonHTMLBld = new StringBuilder();
// todo: if commons is refactored as singleton, we could do this only once and store it as a class member (the currentUser object)
boolean foundWebEnvInAppContext = false;
if (Common.getCommon().getAppContext() != null)
{
WebEnvironment webEnv = WebUtils.getRequiredWebEnvironment(Common.getCommon().getAppContext());
WebSecurityManager webSecurityManager = webEnv.getWebSecurityManager();
if(webSecurityManager!=null) {
SecurityUtils.setSecurityManager(webSecurityManager);
foundWebEnvInAppContext = true;
LOG.info("Success: Retrieved WebEnvironment from context! ");
}
}
// // get the currently executing user:
// Subject currentUser = SecurityUtils.getSubject();
if (!foundWebEnvInAppContext) {
LOG.info("Unable to retrieve WebEnvironment from context! ");
Factory<org.apache.shiro.mgt.SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro.ini");
org.apache.shiro.mgt.SecurityManager securityManager = factory.getInstance();
SecurityUtils.setSecurityManager(securityManager);
}
// A simple Shiro environment is set up
// get the currently executing user:
Subject currentUser = SecurityUtils.getSubject();
// Tests with session variables (todo: remove this after verifying what works and what not -session range / expiration / cleanup)
Session session = currentUser.getSession();
String value = (String) session.getAttribute("someKey");
if(value == null || value.trim().isEmpty()) {
LOG.info("Session did not have the value stored! ");
session.setAttribute("someKey", "aValue");
value = (String) session.getAttribute("someKey");
}
if (value.equals("aValue")) {
LOG.info("Retrieved the correct value! [" + value + "]");
}
Field [] list = currentUser.getClass().getDeclaredFields();
for(Field f:list)
LOG.info(f.getName());
if (currentUser.isAuthenticated()) {
authInfoAndButtonHTMLBld.append("<div class=\"container\" style=\"padding-top: 100px;\">");
authInfoAndButtonHTMLBld.append("</div>");
}
else
{
authInfoAndButtonHTMLBld.append("<div class=\"container\" style=\"padding-top: 100px;\">");
authInfoAndButtonHTMLBld.append("</div>");
authInfoAndButtonHTMLBld.append("<div id=\"notloggedin\" class=\"well\">");
authInfoAndButtonHTMLBld.append("Login to use the VITRO functionalities!");
authInfoAndButtonHTMLBld.append("</div>");
// authInfoAndButtonHTMLBld.append("<div id=\"logoHome\" align=\"center\">");
// authInfoAndButtonHTMLBld.append("<img src=" + request.getContextPath() +"/img/Vitrologo.jpg>");
// authInfoAndButtonHTMLBld.append("</div>");
}
StringBuilder strBuildToRet = new StringBuilder();
strBuildToRet.append("");
// strBuildToRet.append("<div id=\"bar\"><table id=general_table><tr>");
// strBuildToRet.append(menuWrapperfileContents);
strBuildToRet.append(authInfoAndButtonHTMLBld.toString());
// strBuildToRet.append("</tr></table></div>") ;
return strBuildToRet.toString();
}