當前位置: 首頁>>代碼示例>>Java>>正文


Java ConstraintSecurityHandler.setConstraintMappings方法代碼示例

本文整理匯總了Java中org.eclipse.jetty.security.ConstraintSecurityHandler.setConstraintMappings方法的典型用法代碼示例。如果您正苦於以下問題:Java ConstraintSecurityHandler.setConstraintMappings方法的具體用法?Java ConstraintSecurityHandler.setConstraintMappings怎麽用?Java ConstraintSecurityHandler.setConstraintMappings使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jetty.security.ConstraintSecurityHandler的用法示例。


在下文中一共展示了ConstraintSecurityHandler.setConstraintMappings方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: configureCommonAuthentication

import org.eclipse.jetty.security.ConstraintSecurityHandler; //導入方法依賴的package包/類
protected ConstraintSecurityHandler configureCommonAuthentication(Server server,
    ServerConnector connector, AvaticaServerConfiguration config, String constraintName,
    String[] allowedRoles, Authenticator authenticator, String realm,
    LoginService loginService) {

  Constraint constraint = new Constraint();
  constraint.setName(constraintName);
  constraint.setRoles(allowedRoles);
  // This is telling Jetty to not allow unauthenticated requests through (very important!)
  constraint.setAuthenticate(true);

  ConstraintMapping cm = new ConstraintMapping();
  cm.setConstraint(constraint);
  cm.setPathSpec("/*");

  ConstraintSecurityHandler sh = new ConstraintSecurityHandler();
  sh.setAuthenticator(authenticator);
  sh.setLoginService(loginService);
  sh.setConstraintMappings(new ConstraintMapping[]{cm});
  sh.setRealmName(realm);

  return sh;
}
 
開發者ID:apache,項目名稱:calcite-avatica,代碼行數:24,代碼來源:HttpServer.java

示例2: getSecurityHandler

import org.eclipse.jetty.security.ConstraintSecurityHandler; //導入方法依賴的package包/類
private SecurityHandler getSecurityHandler() throws IOException {
    Constraint constraint = new Constraint(Constraint.__BASIC_AUTH, "user");
    constraint.setAuthenticate(true);

    ConstraintMapping cm = new ConstraintMapping();
    cm.setPathSpec("/*");
    cm.setConstraint(constraint);

    ConstraintSecurityHandler sh = new ConstraintSecurityHandler();
    sh.setAuthenticator(new BasicAuthenticator());
    sh.setConstraintMappings(Arrays.asList(new ConstraintMapping[] {cm}));

    HashLoginService loginService = new HashLoginService("MyRealm", "src/test/resources/myRealm.properties");
    sh.setLoginService(loginService);
    sh.setConstraintMappings(Arrays.asList(new ConstraintMapping[]{cm}));

    return sh;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:19,代碼來源:HttpAuthMethodPriorityTest.java

示例3: constrainHttpMethods

import org.eclipse.jetty.security.ConstraintSecurityHandler; //導入方法依賴的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

示例4: addAuthHandler

import org.eclipse.jetty.security.ConstraintSecurityHandler; //導入方法依賴的package包/類
private static void addAuthHandler(Server server, String auth, LoginAuthenticator authenticator, Handler handler) {

        server.addBean(LOGIN_SERVICE);

        Constraint constraint = new Constraint();
        constraint.setName(auth);
        constraint.setRoles(new String[] { USER, ADMIN });
        constraint.setAuthenticate(true);

        ConstraintMapping mapping = new ConstraintMapping();
        mapping.setConstraint(constraint);
        mapping.setPathSpec("/*");

        Set<String> knownRoles = new HashSet<>();
        knownRoles.add(USER);
        knownRoles.add(ADMIN);

        List<ConstraintMapping> cm = new ArrayList<>();
        cm.add(mapping);

        ConstraintSecurityHandler security = new ConstraintSecurityHandler();
        security.setConstraintMappings(cm, knownRoles);
        security.setAuthenticator(authenticator);
        security.setLoginService(LOGIN_SERVICE);
        security.setHandler(handler);
        server.setHandler(security);
    }
 
開發者ID:amaralDaniel,項目名稱:megaphone,代碼行數:28,代碼來源:TestUtils.java

示例5: setupAuthentication

import org.eclipse.jetty.security.ConstraintSecurityHandler; //導入方法依賴的package包/類
private static void setupAuthentication(Server server, ServletHandler shandler) {
    	if(realmProps == null) {		// notta
    		server.setHandler(shandler);
    		return;
    	}
    	
        // setup a hashmap based LoginService
        HashLoginService loginService = new HashLoginService("CTrealm",realmProps);
        server.addBean(loginService);

        // The ConstraintSecurityHandler allows matching of urls to different constraints. 
        ConstraintSecurityHandler security = new ConstraintSecurityHandler();
        server.setHandler(security);

        // This constraint requires authentication and that an
        // authenticated user be a member of a given set of roles
        Constraint constraint = new Constraint();
        constraint.setName("auth");
        constraint.setAuthenticate(true);
//        constraint.setRoles(new String[] { "user", "admin" });
        constraint.setRoles(new String[] { "**" });		// any role
        
        // Binds a url pattern with the previously created constraint.
        ConstraintMapping mapping = new ConstraintMapping();
        mapping.setPathSpec("/*");
        mapping.setConstraint(constraint);

        // Next we set a BasicAuthenticator that checks the credentials
        // followed by the LoginService which is the store of known users, etc.
        security.setConstraintMappings(Collections.singletonList(mapping));
        security.setAuthenticator(new BasicAuthenticator());
        security.setLoginService(loginService);

        // set the given servlet handler on the to complete the simple handler chain.
        security.setHandler(shandler);
    }
 
開發者ID:cycronix,項目名稱:cloudturbine,代碼行數:37,代碼來源:CTweb.java

示例6: createSecurityHandler

import org.eclipse.jetty.security.ConstraintSecurityHandler; //導入方法依賴的package包/類
/**
 * @return {@link SecurityHandler} with appropriate {@link LoginService}, {@link Authenticator} and constraints.
 */
private ConstraintSecurityHandler createSecurityHandler() {
  ConstraintSecurityHandler security = new ConstraintSecurityHandler();

  Set<String> knownRoles = ImmutableSet.of(AUTHENTICATED_ROLE, ADMIN_ROLE);
  security.setConstraintMappings(Collections.<ConstraintMapping>emptyList(), knownRoles);

  security.setAuthenticator(new FormAuthenticator("/login", "/login", true));
  security.setLoginService(new DrillRestLoginService(workManager.getContext()));

  return security;
}
 
開發者ID:axbaretto,項目名稱:drill,代碼行數:15,代碼來源:WebServer.java

示例7: initClass

import org.eclipse.jetty.security.ConstraintSecurityHandler; //導入方法依賴的package包/類
@BeforeClass
public static void initClass() throws Exception {
    server = new Server(8180);

    LoginService loginService = new HashLoginService("MyRealm",
            "src/test/resources/realm.properties");
    server.addBean(loginService);

    ConstraintSecurityHandler security = new ConstraintSecurityHandler();
    server.setHandler(security);

    Constraint constraint = new Constraint();
    constraint.setName("auth");
    constraint.setAuthenticate(true);
    constraint.setRoles(new String[] { "user", "admin" });

    ConstraintMapping mapping = new ConstraintMapping();
    mapping.setPathSpec("/*");
    mapping.setConstraint(constraint);

    security.setConstraintMappings(Collections.singletonList(mapping));
    security.setAuthenticator(new BasicAuthenticator());
    security.setLoginService(loginService);

    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    context.addServlet(EmbeddedServlet.class, "/hello");
    security.setHandler(context);

    server.start();
}
 
開發者ID:hawkular,項目名稱:hawkular-apm,代碼行數:32,代碼來源:JavaxServletSyncServerITest.java

示例8: initClass

import org.eclipse.jetty.security.ConstraintSecurityHandler; //導入方法依賴的package包/類
@BeforeClass
public static void initClass() {
    server = new Server(8180);

    LoginService loginService = new HashLoginService("MyRealm",
            "src/test/resources/realm.properties");
    server.addBean(loginService);

    ConstraintSecurityHandler security = new ConstraintSecurityHandler();
    server.setHandler(security);

    Constraint constraint = new Constraint();
    constraint.setName("auth");
    constraint.setAuthenticate(true);
    constraint.setRoles(new String[] { "user", "admin" });

    ConstraintMapping mapping = new ConstraintMapping();
    mapping.setPathSpec("/*");
    mapping.setConstraint(constraint);

    security.setConstraintMappings(Collections.singletonList(mapping));
    security.setAuthenticator(new BasicAuthenticator());
    security.setLoginService(loginService);

    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    context.addServlet(EmbeddedServlet.class, "/hello");
    security.setHandler(context);

    try {
        server.start();
    } catch (Exception e) {
        fail("Failed to start server: " + e);
    }
}
 
開發者ID:hawkular,項目名稱:hawkular-apm,代碼行數:36,代碼來源:ClientJettyStreamITest.java

示例9: configureServer

import org.eclipse.jetty.security.ConstraintSecurityHandler; //導入方法依賴的package包/類
private void configureServer(Server server, WebAuthConfig authConfig,
		Handler servletHandler) throws BaleenException {
	Handler serverHandler;

	if (authConfig == null || authConfig.getType() == AuthType.NONE) {
		LOGGER.warn("No security applied to API");
		// No security
		serverHandler = servletHandler;
	} else if (authConfig.getType() == AuthType.BASIC) {
		// Basic authentication
		LOGGER.info("Using Basic HTTP authentication for API");

		HashLoginService loginService = new HashLoginService(
				authConfig.getName());

		for (WebUser user : authConfig.getUsers()) {
			Credential credential = Credential.getCredential(user
					.getPassword());
			loginService.putUser(user.getUsername(), credential,
					user.getRolesAsArray());
		}
		server.addBean(loginService);

		ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();

		securityHandler.setHandler(servletHandler);
		securityHandler.setConstraintMappings(constraintMappings);
		securityHandler.setAuthenticator(new BasicAuthenticator());
		securityHandler.setLoginService(loginService);

		serverHandler = securityHandler;
	} else {
		throw new InvalidParameterException(
				"Configuration of authentication failed");
	}

	server.setHandler(serverHandler);

}
 
開發者ID:dstl,項目名稱:baleen,代碼行數:40,代碼來源:BaleenWebApi.java

示例10: createSecurityHandler

import org.eclipse.jetty.security.ConstraintSecurityHandler; //導入方法依賴的package包/類
protected SecurityHandler createSecurityHandler(
    Server server, Configuration appConf, ServletContextHandler appHandler, String appContext
) {
  ConstraintSecurityHandler securityHandler;
  String auth = conf.get(AUTHENTICATION_KEY, AUTHENTICATION_DEFAULT);
  boolean isDPMEnabled = runtimeInfo.isDPMEnabled();
  if (isDPMEnabled) {
    securityHandler = configureSSO(appConf, appHandler, appContext);
  } else {
    switch (auth) {
      case "none":
        securityHandler = null;
        break;
      case "digest":
      case "basic":
        securityHandler = configureDigestBasic(appConf, server, auth);
        break;
      case "form":
        securityHandler = configureForm(appConf, server, auth);
        break;
      default:
        throw new RuntimeException(Utils.format("Invalid authentication mode '{}', must be one of '{}'",
            auth, AUTHENTICATION_MODES));
    }
  }
  if (securityHandler != null) {
    List<ConstraintMapping> constraintMappings = new ArrayList<>();
    constraintMappings.addAll(createConstraintMappings());
    securityHandler.setConstraintMappings(constraintMappings);
  }
  return securityHandler;
}
 
開發者ID:streamsets,項目名稱:datacollector,代碼行數:33,代碼來源:WebServerTask.java

示例11: createSecurityHandler

import org.eclipse.jetty.security.ConstraintSecurityHandler; //導入方法依賴的package包/類
/**
 * Creates a {@link ConstraintSecurityHandler} for the server that
 * configures (secure) transport guarantees, authentication, authorization,
 * etc according to the builder security settings.
 *
 * @param server
 *            The {@link Server} for which the security handler is created.
 * @return
 */
private ConstraintSecurityHandler createSecurityHandler(Server server, ServletDefinition servletDefinition) {
    ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
    securityHandler.setServer(server);

    Constraint constraint = new Constraint();
    constraint.setName("security" + servletDefinition.hashCode());

    if (servletDefinition.isRequireBasicAuth()) {
        // add basic authentication and role-based authorization based on
        // the credentials store (realm file)
        LoginService loginService = new HashLoginService("elastisys:scale security realm",
                servletDefinition.getRealmFile());
        securityHandler.getServer().addBean(loginService);
        securityHandler.setAuthenticator(new BasicAuthenticator());
        securityHandler.setLoginService(loginService);
        constraint.setAuthenticate(true);
        constraint.setRoles(new String[] { servletDefinition.getRequireRole() });
    }

    // require confidential transport: HTTP requests will be redirected to
    // the secure (https) port.
    if (servletDefinition.isRequireHttps()) {
        constraint.setDataConstraint(Constraint.DC_CONFIDENTIAL);
    }

    // apply constraint to all pages/web resources
    ConstraintMapping mapping = new ConstraintMapping();
    mapping.setConstraint(constraint);
    mapping.setPathSpec("/*");
    securityHandler.setConstraintMappings(Arrays.asList(mapping));

    return securityHandler;
}
 
開發者ID:elastisys,項目名稱:scale.commons,代碼行數:43,代碼來源:ServletServerBuilder.java

示例12: deployWebApp

import org.eclipse.jetty.security.ConstraintSecurityHandler; //導入方法依賴的package包/類
private void deployWebApp() {
    try {
        Server server = new Server();
        SelectChannelConnector connector = new SelectChannelConnector();
        connector.setMaxIdleTime(MAX_IDLE_TIME_MILLIS);
        connector.setRequestHeaderSize(HEADER_BUFFER_SIZE);
        connector.setResponseHeaderSize(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.setRequestHeaderSize(HEADER_BUFFER_SIZE);
            sslConnector.setResponseHeaderSize(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());

        if (isHttpsEnabled()) {
            ConstraintMapping constraintMapping = new ConstraintMapping();
            Constraint constraint = new Constraint();
            constraint.setDataConstraint(Constraint.DC_CONFIDENTIAL);
            constraintMapping.setPathSpec("/");
            constraintMapping.setConstraint(constraint);
            ConstraintSecurityHandler csh = (ConstraintSecurityHandler) context.getSecurityHandler();
            csh.setConstraintMappings(new ConstraintMapping[]{constraintMapping});
        } 

        server.setHandler(context);
        server.start();

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

    } catch (Throwable x) {
        x.printStackTrace();
        exception = x;
    }
}
 
開發者ID:FutureSonic,項目名稱:FutureSonic-Server,代碼行數:55,代碼來源:SubsonicDeployer.java

示例13: deployWebApp

import org.eclipse.jetty.security.ConstraintSecurityHandler; //導入方法依賴的package包/類
private void deployWebApp() {
    try {
        Server server = new Server();
        SelectChannelConnector connector = new SelectChannelConnector();
        connector.setMaxIdleTime(MAX_IDLE_TIME_MILLIS);
        connector.setRequestHeaderSize(HEADER_BUFFER_SIZE);
        connector.setResponseHeaderSize(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.setRequestHeaderSize(HEADER_BUFFER_SIZE);
            sslConnector.setResponseHeaderSize(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());

        if (isHttpsEnabled()) {
            ConstraintMapping constraintMapping = new ConstraintMapping();
            Constraint constraint = new Constraint();
            constraint.setDataConstraint(Constraint.DC_CONFIDENTIAL);
            constraintMapping.setPathSpec("/");
            constraintMapping.setConstraint(constraint);
            ConstraintSecurityHandler csh = (ConstraintSecurityHandler) context.getSecurityHandler();
            csh.setConstraintMappings(new ConstraintMapping[]{constraintMapping});
        } 

        server.setHandler(context);
        server.start();

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

    } catch (Throwable x) {
        x.printStackTrace();
        exception = x;
    }
}
 
開發者ID:MadMarty,項目名稱:madsonic-server-5.0,代碼行數:55,代碼來源:SubsonicDeployer.java


注:本文中的org.eclipse.jetty.security.ConstraintSecurityHandler.setConstraintMappings方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。