Package org.eclipse.jetty.security

Examples of org.eclipse.jetty.security.ConstraintSecurityHandler


    /**
     * Construct new security handler for basic authentication.
     */
    public SecurityHandler getObject() throws Exception {
       
        ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
        securityHandler.setAuthenticator(authenticator);
        securityHandler.setRealmName(realm);
       
        for (Entry<String, Constraint> constraint : constraints.entrySet()) {
            ConstraintMapping constraintMapping = new ConstraintMapping();
            constraintMapping.setConstraint(constraint.getValue());
            constraintMapping.setPathSpec(constraint.getKey());
           
            securityHandler.addConstraintMapping(constraintMapping);
        }
       
        for (User user : users) {
            loginService.putUser(user.getName(), Credential.getCredential(user.getPassword()), user.getRoles());
        }
       
        securityHandler.setLoginService(loginService);
       
        return securityHandler;
    }
View Full Code Here


  public void setup() throws Exception {
    server = new Server(0);
    ResourceHandler handler = new ResourceHandler();
    handler.setBaseResource(Resource.newClassPathResource("/site"));

    ConstraintSecurityHandler csh = newSecurityHandler(handler);

    server.setHandler(csh);
    server.start();

    this.port = ((ServerConnector) server.getConnectors()[0]).getLocalPort();
View Full Code Here

    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;
  }
View Full Code Here

        HashLoginService loginService = new HashLoginService("CometD-Realm");
        loginService.putUser(userName, Credential.getCredential(password), roles);
        server.addBean(loginService);

        Handler handler = server.getHandler();
        ConstraintSecurityHandler security = new ConstraintSecurityHandler();
        server.setHandler(security);
        security.setHandler(handler);

        Constraint constraint = new Constraint();
        constraint.setAuthenticate(true);
        constraint.setRoles(roles);

        ConstraintMapping mapping = new ConstraintMapping();
        mapping.setPathSpec(cometdServletPath + "/*");
        mapping.setConstraint(constraint);

        security.setConstraintMappings(Collections.singletonList(mapping));
        security.setAuthenticator(new BasicAuthenticator());
        security.setLoginService(loginService);

        connector.setPort(port);
        server.start();

        LongPollingTransport transport = new LongPollingTransport(null, httpClient)
View Full Code Here

        ConstraintMapping constraintMapping = new ConstraintMapping();
        constraintMapping.setConstraint(constraint);
        constraintMapping.setPathSpec("/*");

        ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
        securityHandler.setLoginService(loginService);

        // TODO: support for other auth schemes (digest, etc)
        securityHandler.setAuthenticator(new BasicAuthenticator());
        securityHandler.setConstraintMappings(Arrays.asList(constraintMapping));
        return securityHandler;
    }
View Full Code Here

      ConstraintMapping mapping = new ConstraintMapping();
      mapping.setPathSpec("/*");
      mapping.setConstraint(constraint);

      ConstraintSecurityHandler sh = new ConstraintSecurityHandler();
      sh.addConstraintMapping(mapping);
      sh.setAuthenticator(new BasicAuthenticator());
      sh.setLoginService(loginService);
      sh.setStrict(true);

      // set the handers: the server hands the request to the security handler,
      // which hands the request to the other handlers when authenticated
      sh.setHandler(handlers);
      server.setHandler(sh);
    } else {
      server.setHandler(handlers);
    }
  }
View Full Code Here

        ConstraintMapping constraintMapping = new ConstraintMapping();
        constraintMapping.setConstraint(constraint);
        constraintMapping.setPathSpec("/*");

        ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
        securityHandler.setLoginService(loginService);

        // TODO: support for other auth schemes (digest, etc)
        securityHandler.setAuthenticator(new BasicAuthenticator());
        securityHandler.setConstraintMappings(Arrays.asList(constraintMapping));
        return securityHandler;
    }
View Full Code Here

      ConstraintMapping mapping = new ConstraintMapping();
      mapping.setPathSpec("/*");
      mapping.setConstraint(constraint);

      ConstraintSecurityHandler sh = new ConstraintSecurityHandler();
      sh.addConstraintMapping(mapping);
      sh.setAuthenticator(new BasicAuthenticator());
      sh.setLoginService(loginService);
      sh.setStrict(true);

      // set the handers: the server hands the request to the security handler,
      // which hands the request to the other handlers when authenticated
      sh.setHandler(handlers);
      server.setHandler(sh);
    } else {
      server.setHandler(handlers);
    }
  }
View Full Code Here

        knownRoles.add(ADMIN);

        List<ConstraintMapping> cm = new ArrayList<ConstraintMapping>();
        cm.add(mapping);

        ConstraintSecurityHandler security = new ConstraintSecurityHandler();
        security.setConstraintMappings(cm, knownRoles);
        security.setAuthenticator(authenticator);
        security.setLoginService(LOGIN_SERVICE);
        security.setStrict(strict);
        security.setHandler(handler);
        server.setHandler(security);
    }
View Full Code Here

        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
        context.setContextPath("/");
        context.addServlet(sh, Api1.PATH + "*");
        server.setHandler(context);

        ConstraintSecurityHandler sec = new ConstraintSecurityHandler();
        sec.addRole(USER.toString());
        sec.addRole(MOD.toString());
        sec.addRole(ADMIN.toString());
        sec.addRole(App.APP_ROLE);
        context.setSecurityHandler(sec);
      }
    });
    return factory;
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jetty.security.ConstraintSecurityHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.