当前位置: 首页>>代码示例>>Java>>正文


Java ConstraintMapping.setMethod方法代码示例

本文整理汇总了Java中org.eclipse.jetty.security.ConstraintMapping.setMethod方法的典型用法代码示例。如果您正苦于以下问题:Java ConstraintMapping.setMethod方法的具体用法?Java ConstraintMapping.setMethod怎么用?Java ConstraintMapping.setMethod使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jetty.security.ConstraintMapping的用法示例。


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

示例1: addServlet

import org.eclipse.jetty.security.ConstraintMapping; //导入方法依赖的package包/类
private void addServlet(final Servlet servlet, final String path,
		WebPermission... permissions) {
	servletContextHandler.addServlet(new ServletHolder(servlet), path);
	if (permissions != null && permissions.length > 0) {
		for (WebPermission p : permissions) {
			Constraint constraint = getConstraintForPermission(p);
			ConstraintMapping mapping = new ConstraintMapping();
			mapping.setPathSpec(servletContextHandler.getContextPath()
					+ path);
			mapping.setConstraint(constraint);
			if (p.hasMethod()) {
				mapping.setMethod(p.getMethod().name());
			}
			constraintMappings.add(mapping);
		}
	}

	LOGGER.info("Servlet added on path {}", path);
}
 
开发者ID:dstl,项目名称:baleen,代码行数:20,代码来源:BaleenWebApi.java

示例2: constrainHttpMethods

import org.eclipse.jetty.security.ConstraintMapping; //导入方法依赖的package包/类
/**
 * Add constraints to a Jetty Context to disallow undesirable Http methods.
 * @param ctxHandler The context to modify
 */
public static void constrainHttpMethods(ServletContextHandler ctxHandler) {
  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("/*");

  ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
  securityHandler.setConstraintMappings(new ConstraintMapping[]{ cmt, cmo });

  ctxHandler.setSecurityHandler(securityHandler);
}
 
开发者ID:apache,项目名称:hbase,代码行数:24,代码来源:HttpServerUtil.java

示例3: setUnsecurePathConstraints

import org.eclipse.jetty.security.ConstraintMapping; //导入方法依赖的package包/类
static void setUnsecurePathConstraints(
    ServletContextHandler context,
    List<String> unsecurePaths
) {
  //we need to set unsecure path only if there is an existing security handler. Otherwise all
  // paths are by default unsecure
  if (context.getSecurityHandler() != null && !unsecurePaths.isEmpty()) {
    for (String path : unsecurePaths) {
      Constraint constraint = new Constraint();
      constraint.setAuthenticate(false);
      ConstraintMapping constraintMapping = new ConstraintMapping();
      constraintMapping.setConstraint(constraint);
      constraintMapping.setMethod("*");
      constraintMapping.setPathSpec(path);
      ((ConstraintSecurityHandler) context.getSecurityHandler())
          .addConstraintMapping(constraintMapping);
    }
  }
}
 
开发者ID:confluentinc,项目名称:rest-utils,代码行数:20,代码来源:Application.java

示例4: createSecurityHandler

import org.eclipse.jetty.security.ConstraintMapping; //导入方法依赖的package包/类
static ConstraintSecurityHandler createSecurityHandler(String realm, List<String> roles) {
  final ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
  Constraint constraint = new Constraint();
  constraint.setAuthenticate(true);
  constraint.setRoles(roles.toArray(new String[0]));
  ConstraintMapping constraintMapping = new ConstraintMapping();
  constraintMapping.setConstraint(constraint);
  constraintMapping.setMethod("*");
  constraintMapping.setPathSpec("/*");
  securityHandler.addConstraintMapping(constraintMapping);
  securityHandler.setAuthenticator(new BasicAuthenticator());
  securityHandler.setLoginService(new JAASLoginService(realm));
  securityHandler.setIdentityService(new DefaultIdentityService());
  securityHandler.setRealmName(realm);
  return securityHandler;
}
 
开发者ID:confluentinc,项目名称:rest-utils,代码行数:17,代码来源:Application.java

示例5: createSecurityHandler

import org.eclipse.jetty.security.ConstraintMapping; //导入方法依赖的package包/类
/**
 * Creates a basic auth security handler.
 */
private SecurityHandler createSecurityHandler() {
	HashLoginService hashLoginService = new HashLoginService();
	for (String user : Lists.newArrayList("testuser_1","testuser_2","admin_1","admin_2")) {
		String[] roles = new String[] { "ROLE_USER" };
		if (user.startsWith("admin"))
			roles = new String[] { "ROLE_ADMIN" };
		hashLoginService.putUser(user, Credential.getCredential(user), roles);
	}
	hashLoginService.setName("RTGovRealm");
	Constraint constraint = new Constraint();
	constraint.setName(Constraint.__BASIC_AUTH);
	constraint.setRoles(new String[] { "ROLE_USER", "ROLE_ADMIN" });
	constraint.setAuthenticate(true);
	String[] protectedMethods = new String[] { "GET", "HEAD", "POST", "PUT", "DELETE", "TRACE", "CONNECT" };
	ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
	csh.setAuthenticator(new BasicAuthenticator());
	csh.setRealmName("RTGovRealm");
	for (String method : protectedMethods) {
		ConstraintMapping cm = new ConstraintMapping();
		cm.setConstraint(constraint);
		cm.setPathSpec("/*");
		cm.setMethod(method);
		csh.addConstraintMapping(cm);
	}
	csh.setLoginService(hashLoginService);
	return csh;
}
 
开发者ID:Governance,项目名称:rtgov-ui,代码行数:31,代码来源:RTGovUIDevServer.java

示例6: addConstraint

import org.eclipse.jetty.security.ConstraintMapping; //导入方法依赖的package包/类
private void addConstraint(
    ConstraintSecurityHandler handler, String path, String name, String... roles) {
  Constraint constraint = new Constraint();
  constraint.setName(name);
  constraint.setRoles(roles);
  constraint.setAuthenticate(true);
  ConstraintMapping mapping = new ConstraintMapping();
  mapping.setMethod("GET");
  mapping.setPathSpec(path);
  mapping.setConstraint(constraint);
  handler.addConstraintMapping(mapping);
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:13,代码来源:AppEngineAuthenticationTest.java

示例7: createConstraintMappings

import org.eclipse.jetty.security.ConstraintMapping; //导入方法依赖的package包/类
private List<ConstraintMapping> createConstraintMappings() {
  // everything under /* public
  Constraint noAuthConstraint = new Constraint();
  noAuthConstraint.setName("auth");
  noAuthConstraint.setAuthenticate(false);
  noAuthConstraint.setRoles(new String[]{"user"});
  ConstraintMapping noAuthMapping = new ConstraintMapping();
  noAuthMapping.setPathSpec("/*");
  noAuthMapping.setConstraint(noAuthConstraint);

  // everything under /public-rest/* public
  Constraint publicRestConstraint = new Constraint();
  publicRestConstraint.setName("auth");
  publicRestConstraint.setAuthenticate(false);
  publicRestConstraint.setRoles(new String[] { "user"});
  ConstraintMapping publicRestMapping = new ConstraintMapping();
  publicRestMapping.setPathSpec("/public-rest/*");
  publicRestMapping.setConstraint(publicRestConstraint);


  // everything under /rest/* restricted
  Constraint restConstraint = new Constraint();
  restConstraint.setName("auth");
  restConstraint.setAuthenticate(true);
  restConstraint.setRoles(new String[] { "user"});
  ConstraintMapping restMapping = new ConstraintMapping();
  restMapping.setPathSpec("/rest/*");
  restMapping.setConstraint(restConstraint);

  // /logout is restricted
  Constraint logoutConstraint = new Constraint();
  logoutConstraint.setName("auth");
  logoutConstraint.setAuthenticate(true);
  logoutConstraint.setRoles(new String[] { "user"});
  ConstraintMapping logoutMapping = new ConstraintMapping();
  logoutMapping.setPathSpec("/logout");
  logoutMapping.setConstraint(logoutConstraint);

  // index page is restricted to trigger login correctly when using form authentication
  Constraint indexConstraint = new Constraint();
  indexConstraint.setName("auth");
  indexConstraint.setAuthenticate(true);
  indexConstraint.setRoles(new String[] { "user"});
  ConstraintMapping indexMapping = new ConstraintMapping();
  indexMapping.setPathSpec("");
  indexMapping.setConstraint(indexConstraint);

  // docs is restricted
  ConstraintMapping docMapping = new ConstraintMapping();
  docMapping.setPathSpec("/docs/*");
  docMapping.setConstraint(indexConstraint);

  // Disable TRACE method
  Constraint disableTraceConstraint = new Constraint();
  disableTraceConstraint.setName("Disable TRACE");
  disableTraceConstraint.setAuthenticate(true);
  ConstraintMapping disableTraceMapping = new ConstraintMapping();
  disableTraceMapping.setPathSpec("/*");
  disableTraceMapping.setMethod("TRACE");
  disableTraceMapping.setConstraint(disableTraceConstraint);

  return ImmutableList.of(
      disableTraceMapping,
      restMapping,
      indexMapping,
      docMapping,
      logoutMapping,
      noAuthMapping,
      publicRestMapping
  );
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:72,代码来源:WebServerTask.java


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