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

Java Constraint类代码示例

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

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



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

示例1: enforceConstraints

import org.mortbay.jetty.security.Constraint; //导入依赖的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.Constraint; //导入依赖的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: createConstraintMapping

import org.mortbay.jetty.security.Constraint; //导入依赖的package包/类
private ConstraintMapping createConstraintMapping(String pathSpec, int dataConstraint) {
    ConstraintMapping constraintMapping = new ConstraintMapping();
    Constraint constraint = new Constraint();
    constraint.setDataConstraint(dataConstraint);
    constraintMapping.setPathSpec(pathSpec);
    constraintMapping.setConstraint(constraint);
    return constraintMapping;
}
 
开发者ID:sindremehus,项目名称:subsonic,代码行数:9,代码来源:SubsonicDeployer.java


示例4: makeSecurityHandler

import org.mortbay.jetty.security.Constraint; //导入依赖的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


示例5: jettyServer

import org.mortbay.jetty.security.Constraint; //导入依赖的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


示例6: deployWebApp

import org.mortbay.jetty.security.Constraint; //导入依赖的package包/类
private void deployWebApp() {
    try {
        Server server = new Server();
        SelectChannelConnector connector = new SelectChannelConnector();
        connector.setMaxIdleTime(MAX_IDLE_TIME_MILLIS);
        connector.setHeaderBufferSize(HEADER_BUFFER_SIZE);
        connector.setHost(getHost());
        connector.setPort(getPort());
        if (isHttpsEnabled()) {
            connector.setConfidentialPort(getHttpsPort());
        }
        server.addConnector(connector);

        if (isHttpsEnabled()) {
            SslSocketConnector sslConnector = new SslSocketConnector();
            sslConnector.setMaxIdleTime(MAX_IDLE_TIME_MILLIS);
            sslConnector.setHeaderBufferSize(HEADER_BUFFER_SIZE);
            sslConnector.setHost(getHost());
            sslConnector.setPort(getHttpsPort());
            sslConnector.setKeystore(System.getProperty("subsonic.ssl.keystore", getClass().getResource("/subsonic.keystore").toExternalForm()));
            sslConnector.setPassword(System.getProperty("subsonic.ssl.password", "subsonic"));
            server.addConnector(sslConnector);
        }

        WebAppContext context = new WebAppContext();
        context.setTempDirectory(getJettyDirectory());
        context.setContextPath(getContextPath());
        context.setWar(getWar());
        context.setOverrideDescriptor("/web-jetty.xml");

        if (isHttpsEnabled()) {

            // Allow non-https for streaming and cover art (for Chromecast, UPnP, Sonos etc)
            context.getSecurityHandler().setConstraintMappings(new ConstraintMapping[]{
                    createConstraintMapping("/stream", Constraint.DC_NONE),
                    createConstraintMapping("/coverArt.view", Constraint.DC_NONE),
                    createConstraintMapping("/ws/*", Constraint.DC_NONE),
                    createConstraintMapping("/sonos/*", Constraint.DC_NONE),
                    createConstraintMapping("/", Constraint.DC_CONFIDENTIAL)
            });
        }

        server.addHandler(context);
        server.start();

        System.err.println("Subsonic running on: " + getUrl());
        if (isHttpsEnabled()) {
            System.err.println("                and: " + getHttpsUrl());
        }

    } catch (Throwable x) {
        x.printStackTrace();
        exception = x;
    }
}
 
开发者ID:sindremehus,项目名称:subsonic,代码行数:56,代码来源:SubsonicDeployer.java


示例7: updateAuthentication

import org.mortbay.jetty.security.Constraint; //导入依赖的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.Constraint类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java StandardEngine类代码示例发布时间:2022-05-21
下一篇:
Java Manager类代码示例发布时间: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