本文整理汇总了Java中org.mortbay.jetty.security.Constraint类的典型用法代码示例。如果您正苦于以下问题:Java Constraint类的具体用法?Java Constraint怎么用?Java Constraint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Constraint类属于org.mortbay.jetty.security包,在下文中一共展示了Constraint类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: enforceConstraints
import org.mortbay.jetty.security.Constraint; //导入依赖的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.Constraint; //导入依赖的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.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;
}
示例4: makeSecurityHandler
import org.mortbay.jetty.security.Constraint; //导入依赖的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.Constraint; //导入依赖的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();
}
示例6: deployWebApp
import org.mortbay.jetty.security.Constraint; //导入依赖的package包/类
private void deployWebApp() {
try {
Server server = new Server();
SelectChannelConnector connector = new SelectChannelConnector();
connector.setMaxIdleTime(MAX_IDLE_TIME_MILLIS);
connector.setHeaderBufferSize(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.setHeaderBufferSize(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());
context.setOverrideDescriptor("/web-jetty.xml");
if (isHttpsEnabled()) {
// Allow non-https for streaming and cover art (for Chromecast, UPnP, Sonos etc)
context.getSecurityHandler().setConstraintMappings(new ConstraintMapping[]{
createConstraintMapping("/stream", Constraint.DC_NONE),
createConstraintMapping("/coverArt.view", Constraint.DC_NONE),
createConstraintMapping("/ws/*", Constraint.DC_NONE),
createConstraintMapping("/sonos/*", Constraint.DC_NONE),
createConstraintMapping("/", Constraint.DC_CONFIDENTIAL)
});
}
server.addHandler(context);
server.start();
System.err.println("Subsonic running on: " + getUrl());
if (isHttpsEnabled()) {
System.err.println(" and: " + getHttpsUrl());
}
} catch (Throwable x) {
x.printStackTrace();
exception = x;
}
}
示例7: updateAuthentication
import org.mortbay.jetty.security.Constraint; //导入依赖的package包/类
public static void updateAuthentication() {
try {
SagexConfiguration config = new SagexConfiguration();
boolean httpenabled = config.getBoolean(SagexConfiguration.PROP_ENABLE_HTTP, true);
Context ctx = (Context) SagexServlet.getUserData().get("jetty_context");
if (!httpenabled) {
System.out.println("SAGEX-API: Stopping Http Context");
ctx.stop();
return;
} else {
if (ctx.isStopped()) {
System.out.println("SAGEX-API: Starting Http Context");
ctx.start();
}
}
if (ctx == null) {
System.out
.println("SAGEX-API: Can't configure authentication; No Jetty Context.");
return;
}
SecurityHandler sh = ctx.getSecurityHandler();
if (sh == null) {
System.out
.println("SAGEX-API: Can't configure authentication; No Security Handler.");
return;
}
ConstraintMapping cmap[] = sh.getConstraintMappings();
if (cmap == null) {
System.out
.println("SAGEX-API: Can't configure authentication; No Constraints.");
return;
}
boolean auth = config.getBoolean(
SagexConfiguration.PROP_SECURE_HTTP, true);
for (ConstraintMapping c : cmap) {
Constraint cs = c.getConstraint();
if (cs != null) {
System.out
.println("SAGEX-API: Updated Constrant Authentication: "
+ auth);
cs.setAuthenticate(auth);
}
}
} catch (Throwable t) {
t.printStackTrace();
}
}