當前位置: 首頁>>代碼示例>>Java>>正文


Java ConstraintSecurityHandler.setHandler方法代碼示例

本文整理匯總了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;
}
 
開發者ID:aminmf,項目名稱:crawljax,代碼行數:21,代碼來源:PassBasicHttpAuthTest.java

示例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;
}
 
開發者ID:BandwidthOnDemand,項目名稱:bandwidth-on-demand,代碼行數:23,代碼來源:MockHttpServer.java

示例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);
    }
 
開發者ID:amaralDaniel,項目名稱:megaphone,代碼行數:28,代碼來源:TestUtils.java

示例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);
    }
 
開發者ID:cycronix,項目名稱:cloudturbine,代碼行數:37,代碼來源:CTweb.java

示例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();
}
 
開發者ID:hawkular,項目名稱:hawkular-apm,代碼行數:32,代碼來源:JavaxServletSyncServerITest.java

示例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);
    }
}
 
開發者ID:hawkular,項目名稱:hawkular-apm,代碼行數:36,代碼來源:ClientJettyStreamITest.java

示例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);

}
 
開發者ID:dstl,項目名稱:baleen,代碼行數:40,代碼來源:BaleenWebApi.java


注:本文中的org.eclipse.jetty.security.ConstraintSecurityHandler.setHandler方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。