本文整理匯總了Java中org.eclipse.jetty.security.ConstraintSecurityHandler.setHandler方法的典型用法代碼示例。如果您正苦於以下問題:Java ConstraintSecurityHandler.setHandler方法的具體用法?Java ConstraintSecurityHandler.setHandler怎麽用?Java ConstraintSecurityHandler.setHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.eclipse.jetty.security.ConstraintSecurityHandler
的用法示例。
在下文中一共展示了ConstraintSecurityHandler.setHandler方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: newSecurityHandler
import org.eclipse.jetty.security.ConstraintSecurityHandler; //導入方法依賴的package包/類
private ConstraintSecurityHandler newSecurityHandler(ResourceHandler handler) {
HashLoginService login = new HashLoginService();
login.putUser(USERNAME, Credential.getCredential(PASSWORD), new String[] { "user" });
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[] { "user" });
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");
ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
csh.setAuthenticator(new BasicAuthenticator());
csh.addConstraintMapping(cm);
csh.setLoginService(login);
csh.setHandler(handler);
return csh;
}
示例2: getSecurityHandler
import org.eclipse.jetty.security.ConstraintSecurityHandler; //導入方法依賴的package包/類
private SecurityHandler getSecurityHandler() {
Constraint constraint = new Constraint();
constraint.setName(Constraint.__BASIC_AUTH);
constraint.setRoles(new String[] { "admin" });
constraint.setAuthenticate(true);
ConstraintMapping cm = new ConstraintMapping();
cm.setConstraint(constraint);
cm.setPathSpec("/*");
HashLoginService loginService = new HashLoginService();
loginService.putUser(username, Credential.getCredential(password), new String[] { "admin" });
ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
securityHandler.setRealmName("please password");
securityHandler.setAuthenticator(new BasicAuthenticator());
securityHandler.addConstraintMapping(cm);
securityHandler.setLoginService(loginService);
securityHandler.setHandler(this);
return securityHandler;
}
示例3: 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);
}
示例4: 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);
}
示例5: 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();
}
示例6: 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);
}
}
示例7: 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);
}