• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SecurityHandler类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.mortbay.jetty.security.SecurityHandler的典型用法代码示例。如果您正苦于以下问题:Java SecurityHandler类的具体用法?Java SecurityHandler怎么用?Java SecurityHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SecurityHandler类属于org.mortbay.jetty.security包,在下文中一共展示了SecurityHandler类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: enforceConstraints

import org.mortbay.jetty.security.SecurityHandler; //导入依赖的package包/类
/**
 * Impose constraints on the {@linkplain org.mortbay.jetty.servlet.Context}
 * passed in.
 * @param ctx - {@linkplain org.mortbay.jetty.servlet.Context} to impose
 *            constraints on.
 */
public static void enforceConstraints(Context ctx) {
  Constraint c = new Constraint();
  c.setAuthenticate(true);

  ConstraintMapping cmt = new ConstraintMapping();
  cmt.setConstraint(c);
  cmt.setMethod("TRACE");
  cmt.setPathSpec("/*");

  ConstraintMapping cmo = new ConstraintMapping();
  cmo.setConstraint(c);
  cmo.setMethod("OPTIONS");
  cmo.setPathSpec("/*");

  SecurityHandler sh = new SecurityHandler();
  sh.setConstraintMappings(new ConstraintMapping[]{cmt, cmo});
  ctx.addHandler(sh);
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:25,代码来源:HTTPServerConstraintUtil.java


示例2: constrainHttpMethods

import org.mortbay.jetty.security.SecurityHandler; //导入依赖的package包/类
/**
 * Add constraints to a Jetty Context to disallow undesirable Http methods.
 * @param context The context to modify
 */
public static void constrainHttpMethods(Context context) {
  Constraint c = new Constraint();
  c.setAuthenticate(true);

  ConstraintMapping cmt = new ConstraintMapping();
  cmt.setConstraint(c);
  cmt.setMethod("TRACE");
  cmt.setPathSpec("/*");

  ConstraintMapping cmo = new ConstraintMapping();
  cmo.setConstraint(c);
  cmo.setMethod("OPTIONS");
  cmo.setPathSpec("/*");

  SecurityHandler sh = new SecurityHandler();
  sh.setConstraintMappings(new ConstraintMapping[]{ cmt, cmo });

  context.addHandler(sh);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:24,代码来源:HttpServerUtil.java


示例3: makeSecurityHandler

import org.mortbay.jetty.security.SecurityHandler; //导入依赖的package包/类
private SecurityHandler makeSecurityHandler(String realm, String consoleUser, String consolePassword, String curatorUser, String curatorPassword)
{
    HashUserRealm userRealm = new HashUserRealm(realm);
    userRealm.put(consoleUser, Credential.getCredential(consolePassword));
    userRealm.addUserToRole(consoleUser,"console");
    userRealm.put(curatorUser, Credential.getCredential(curatorPassword));
    userRealm.addUserToRole(curatorUser, "curator");

    Constraint console = new Constraint();
    console.setName("consoleauth");
    console.setRoles(new String[]{"console"});
    console.setAuthenticate(true);

    Constraint curator = new Constraint();
    curator.setName("curatorauth");
    curator.setRoles(new String[]{"curator", "console"});
    curator.setAuthenticate(true);

    ConstraintMapping consoleMapping = new ConstraintMapping();
    consoleMapping.setConstraint(console);
    consoleMapping.setPathSpec("/*");

    ConstraintMapping curatorMapping = new ConstraintMapping();
    curatorMapping.setConstraint(curator);
    curatorMapping.setPathSpec("/exhibitor/v1/cluster/list");

    SecurityHandler handler = new SecurityHandler();
    handler.setUserRealm(userRealm);
    handler.setConstraintMappings(new ConstraintMapping[]{consoleMapping,curatorMapping});
    handler.setAuthenticator(new BasicAuthenticator());

    return handler;
}
 
开发者ID:dcos,项目名称:exhibitor,代码行数:34,代码来源:ExhibitorCreator.java


示例4: jettyServer

import org.mortbay.jetty.security.SecurityHandler; //导入依赖的package包/类
@BeforeClass
public static void jettyServer() throws Exception {

	server = new Server();

	Connector connector = new SelectChannelConnector();
	connector.setPort(PORT);
	server.setConnectors(new Connector[] { connector });
	ConstraintMapping cm = new ConstraintMapping();
	Constraint constraint = new Constraint();
	constraint.setName(Constraint.__BASIC_AUTH);
	constraint.setRoles(new String[] { ROLE_NAME });
	constraint.setAuthenticate(true);
	cm.setConstraint(constraint);
	cm.setPathSpec("/*");

	sh = new SecurityHandler();
	userRealm = new HashUserRealm(REALM);
	userRealm.put(USERNAME, PASSWORD);
	userRealm.addUserToRole(USERNAME, ROLE_NAME);
	sh.setUserRealm(userRealm);
	sh.setConstraintMappings(new ConstraintMapping[] { cm });

	WebAppContext webappcontext = new WebAppContext();
	webappcontext.setContextPath("/");

	URL htmlRoot = HTTPAuthenticatorIT.class.getResource(HTML);
	assertNotNull("Could not find " + HTML, htmlRoot);
	webappcontext.setWar(htmlRoot.toExternalForm());
	
	webappcontext.addHandler(sh);

	HandlerCollection handlers = new HandlerCollection();
	handlers.setHandlers(new Handler[] { webappcontext,
			new DefaultHandler() });

	server.setHandler(handlers);
	server.start();
}
 
开发者ID:apache,项目名称:incubator-taverna-engine,代码行数:40,代码来源:HTTPAuthenticatorIT.java


示例5: configureSecurity

import org.mortbay.jetty.security.SecurityHandler; //导入依赖的package包/类
private void configureSecurity() {
    SecurityHandler handler = new SecurityHandler();

    handler.setAuthenticator(new AppengineAuthenticator());
    handler.setUserRealm(createAppengineUserRealm());

    webapp.setSecurityHandler(handler);
}
 
开发者ID:feroult,项目名称:yawp,代码行数:9,代码来源:AppengineWebAppContextHelper.java


示例6: addSecurityFile

import org.mortbay.jetty.security.SecurityHandler; //导入依赖的package包/类
private void addSecurityFile(HashUserRealm realm, String securityFile, Context root) throws Exception
{
    // create a temp Jetty context to parse the security portion of the web.xml file

    /*
        TODO

        This code assumes far too much internal knowledge of Jetty. I don't know
        of simple way to parse the web.xml though and don't want to write it myself.
     */

    final URL url = new URL("file", null, securityFile);
    final WebXmlConfiguration webXmlConfiguration = new WebXmlConfiguration();
    WebAppContext context = new WebAppContext();
    context.setServer(server);
    webXmlConfiguration.setWebAppContext(context);
    ContextHandler contextHandler = new ContextHandler("/")
    {
        @Override
        protected void startContext() throws Exception
        {
            super.startContext();
            setServer(server);
            webXmlConfiguration.configure(url.toString());
        }
    };
    contextHandler.start();
    try
    {
        SecurityHandler securityHandler = webXmlConfiguration.getWebAppContext().getSecurityHandler();

        if ( realm != null )
        {
            securityHandler.setUserRealm(realm);
        }

        root.setSecurityHandler(securityHandler);
    }
    finally
    {
        contextHandler.stop();
    }
}
 
开发者ID:dcos,项目名称:exhibitor,代码行数:44,代码来源:ExhibitorMain.java


示例7: getSecurityHandler

import org.mortbay.jetty.security.SecurityHandler; //导入依赖的package包/类
public SecurityHandler getSecurityHandler()
{
    return securityHandler;
}
 
开发者ID:dcos,项目名称:exhibitor,代码行数:5,代码来源:ExhibitorCreator.java


示例8: updateAuthentication

import org.mortbay.jetty.security.SecurityHandler; //导入依赖的package包/类
public static void updateAuthentication() {
	try {
		SagexConfiguration config = new SagexConfiguration();

		boolean httpenabled = config.getBoolean(SagexConfiguration.PROP_ENABLE_HTTP, true);
		Context ctx = (Context) SagexServlet.getUserData().get("jetty_context");
		if (!httpenabled) {
			System.out.println("SAGEX-API: Stopping Http Context");
			ctx.stop();
			return;
		} else {
			if (ctx.isStopped()) {
				System.out.println("SAGEX-API: Starting Http Context");
				ctx.start();
			}
		}
		
		if (ctx == null) {
			System.out
					.println("SAGEX-API: Can't configure authentication; No Jetty Context.");
			return;
		}
		SecurityHandler sh = ctx.getSecurityHandler();
		if (sh == null) {
			System.out
					.println("SAGEX-API: Can't configure authentication; No Security Handler.");
			return;
		}
		ConstraintMapping cmap[] = sh.getConstraintMappings();
		if (cmap == null) {
			System.out
					.println("SAGEX-API: Can't configure authentication; No Constraints.");
			return;
		}

		boolean auth = config.getBoolean(
				SagexConfiguration.PROP_SECURE_HTTP, true);
		for (ConstraintMapping c : cmap) {
			Constraint cs = c.getConstraint();
			if (cs != null) {
				System.out
						.println("SAGEX-API: Updated Constrant Authentication: "
								+ auth);
				cs.setAuthenticate(auth);
			}
		}
	} catch (Throwable t) {
		t.printStackTrace();
	}
}
 
开发者ID:stuckless,项目名称:sagetv-sagex-api,代码行数:51,代码来源:JettyInitializer.java



注:本文中的org.mortbay.jetty.security.SecurityHandler类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Sensor类代码示例发布时间:2022-05-21
下一篇:
Java ItemizedOverlay类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap