本文整理匯總了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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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();
}
示例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);
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
}