本文整理汇总了Java中org.mortbay.jetty.security.ConstraintMapping.setConstraint方法的典型用法代码示例。如果您正苦于以下问题:Java ConstraintMapping.setConstraint方法的具体用法?Java ConstraintMapping.setConstraint怎么用?Java ConstraintMapping.setConstraint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mortbay.jetty.security.ConstraintMapping
的用法示例。
在下文中一共展示了ConstraintMapping.setConstraint方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: enforceConstraints
import org.mortbay.jetty.security.ConstraintMapping; //导入方法依赖的package包/类
/**
* Impose constraints on the {@linkplain org.mortbay.jetty.servlet.Context}
* passed in.
* @param ctx - {@linkplain org.mortbay.jetty.servlet.Context} to impose
* constraints on.
*/
public static void enforceConstraints(Context ctx) {
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("/*");
SecurityHandler sh = new SecurityHandler();
sh.setConstraintMappings(new ConstraintMapping[]{cmt, cmo});
ctx.addHandler(sh);
}
示例2: constrainHttpMethods
import org.mortbay.jetty.security.ConstraintMapping; //导入方法依赖的package包/类
/**
* Add constraints to a Jetty Context to disallow undesirable Http methods.
* @param context The context to modify
*/
public static void constrainHttpMethods(Context context) {
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("/*");
SecurityHandler sh = new SecurityHandler();
sh.setConstraintMappings(new ConstraintMapping[]{ cmt, cmo });
context.addHandler(sh);
}
示例3: createConstraintMapping
import org.mortbay.jetty.security.ConstraintMapping; //导入方法依赖的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;
}
示例4: makeSecurityHandler
import org.mortbay.jetty.security.ConstraintMapping; //导入方法依赖的package包/类
private SecurityHandler makeSecurityHandler(String realm, String consoleUser, String consolePassword, String curatorUser, String curatorPassword)
{
HashUserRealm userRealm = new HashUserRealm(realm);
userRealm.put(consoleUser, Credential.getCredential(consolePassword));
userRealm.addUserToRole(consoleUser,"console");
userRealm.put(curatorUser, Credential.getCredential(curatorPassword));
userRealm.addUserToRole(curatorUser, "curator");
Constraint console = new Constraint();
console.setName("consoleauth");
console.setRoles(new String[]{"console"});
console.setAuthenticate(true);
Constraint curator = new Constraint();
curator.setName("curatorauth");
curator.setRoles(new String[]{"curator", "console"});
curator.setAuthenticate(true);
ConstraintMapping consoleMapping = new ConstraintMapping();
consoleMapping.setConstraint(console);
consoleMapping.setPathSpec("/*");
ConstraintMapping curatorMapping = new ConstraintMapping();
curatorMapping.setConstraint(curator);
curatorMapping.setPathSpec("/exhibitor/v1/cluster/list");
SecurityHandler handler = new SecurityHandler();
handler.setUserRealm(userRealm);
handler.setConstraintMappings(new ConstraintMapping[]{consoleMapping,curatorMapping});
handler.setAuthenticator(new BasicAuthenticator());
return handler;
}
示例5: jettyServer
import org.mortbay.jetty.security.ConstraintMapping; //导入方法依赖的package包/类
@BeforeClass
public static void jettyServer() throws Exception {
server = new Server();
Connector connector = new SelectChannelConnector();
connector.setPort(PORT);
server.setConnectors(new Connector[] { connector });
ConstraintMapping cm = new ConstraintMapping();
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[] { ROLE_NAME });
constraint.setAuthenticate(true);
cm.setConstraint(constraint);
cm.setPathSpec("/*");
sh = new SecurityHandler();
userRealm = new HashUserRealm(REALM);
userRealm.put(USERNAME, PASSWORD);
userRealm.addUserToRole(USERNAME, ROLE_NAME);
sh.setUserRealm(userRealm);
sh.setConstraintMappings(new ConstraintMapping[] { cm });
WebAppContext webappcontext = new WebAppContext();
webappcontext.setContextPath("/");
URL htmlRoot = HTTPAuthenticatorIT.class.getResource(HTML);
assertNotNull("Could not find " + HTML, htmlRoot);
webappcontext.setWar(htmlRoot.toExternalForm());
webappcontext.addHandler(sh);
HandlerCollection handlers = new HandlerCollection();
handlers.setHandlers(new Handler[] { webappcontext,
new DefaultHandler() });
server.setHandler(handlers);
server.start();
}