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


Java Constraint.setDataConstraint方法代碼示例

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


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

示例1: createSecurityHandler

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

示例2: createConstraintMapping

import org.eclipse.jetty.util.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:MadMarty,項目名稱:madsonic-server-5.1,代碼行數:9,代碼來源:MadsonicDeployer.java

示例3: getConstraintSecurityHandlerConfidential

import org.eclipse.jetty.util.security.Constraint; //導入方法依賴的package包/類
/**
 * Create constraint which redirect to Secure Port
 * 
 * @return ConstraintSecurityHandler
 */
public static ConstraintSecurityHandler getConstraintSecurityHandlerConfidential() {
    Constraint constraint = new Constraint();
    constraint.setDataConstraint(Constraint.DC_CONFIDENTIAL);

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

    ConstraintSecurityHandler constraintSecurityHandler = new ConstraintSecurityHandler();
    constraintSecurityHandler.addConstraintMapping(constraintMapping);

    return constraintSecurityHandler;
}
 
開發者ID:teknux-org,項目名稱:jetty-bootstrap,代碼行數:19,代碼來源:JettyConstraintUtil.java

示例4: servletContainer

import org.eclipse.jetty.util.security.Constraint; //導入方法依賴的package包/類
@Bean
public EmbeddedServletContainerFactory servletContainer(SslProperties properties) {
	JettyEmbeddedServletContainerFactory jetty = new JettyEmbeddedServletContainerFactory() {
		@Override
		protected void postProcessWebAppContext(WebAppContext webAppContext) {
			// 所有請求都必須為 Https 協議
			ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
			ConstraintMapping mapping = new ConstraintMapping();
			Constraint constraint = new Constraint();
			constraint.setDataConstraint(Constraint.DC_CONFIDENTIAL);
			mapping.setConstraint(constraint);
			mapping.setPathSpec("/*");
			securityHandler.addConstraintMapping(mapping);
			webAppContext.setSecurityHandler(securityHandler);
		}
	};
	jetty.addServerCustomizers(new JettyServerCustomizer() {
		@Override
		public void customize(Server server) {
			// 移除Spring Boot 生成的 Connector
			int httpPort = 80;
			Connector[] connectors = server.getConnectors();
			for (Connector connector : connectors) {
				if (connector instanceof ServerConnector) {
					httpPort = ((ServerConnector) connector).getPort();
				}
				server.removeConnector(connector);
			}
			
			// 配置 Http 協議的 Connector
			HttpConfiguration httpConfig = new HttpConfiguration();
			// 重定向
			httpConfig.setSecureScheme(properties.getScheme());
			httpConfig.setSecurePort(properties.getPort());
			httpConfig.addCustomizer(new SecureRequestCustomizer());
			ServerConnector httpConnector = new ServerConnector(server, new HttpConnectionFactory(httpConfig));
			httpConnector.setPort(httpPort);
			server.addConnector(httpConnector);

			// 配置 Https 協議的 Connector
			HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
			httpsConfig.addCustomizer(new SecureRequestCustomizer());
			HttpConnectionFactory connectionFactory = new HttpConnectionFactory(httpsConfig);
			SslContextFactory sslContextFactory = new SslContextFactory();
			File keystoreFile = new File(properties.getKeystore());
			if (keystoreFile.exists()) {
				sslContextFactory.setKeyStorePath(properties.getKeystore());
				sslContextFactory.setKeyStorePassword(properties.getKeystorePassword());
			}
			SslConnectionFactory sslConnectionFactory = new SslConnectionFactory(sslContextFactory,
					HttpVersion.HTTP_1_1.asString());
			ServerConnector serverConnector = new ServerConnector(server, sslConnectionFactory, connectionFactory);
			serverConnector.setPort(properties.getPort());
			server.addConnector(serverConnector);
		}
	});
	return jetty;
}
 
開發者ID:Saisimon,項目名稱:tip,代碼行數:59,代碼來源:JettyWebConfig.java

示例5: deployWebApp

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

示例6: deployWebApp

import org.eclipse.jetty.util.security.Constraint; //導入方法依賴的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.util.security.Constraint.setDataConstraint方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。