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