Package org.mortbay.jetty.security

Examples of org.mortbay.jetty.security.SecurityHandler


       
       
        ServletHolder servlet = new ServletHolder(new XFireServlet());
       
        context.addServlet(servlet, "/*");
        SecurityHandler sh = new SecurityHandler();
        context.addHandler(sh);
       
        HashUserRealm userRealm = new HashUserRealm();
        userRealm.put("user", "pass");
        userRealm.addUserToRole("user", "role");

        assertNotNull(userRealm.authenticate("user", "pass", null));
       
        sh.setUserRealm(userRealm);
       
        Constraint constraint = new Constraint();
        constraint.setName(Constraint.__BASIC_AUTH);;
        constraint.setRoles(new String[]{"role"});
        constraint.setAuthenticate(true);
View Full Code Here


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

        securityHandler = new SecurityHandler();

        securityRealm = new HashUserRealm( "Test Server" );

        securityHandler.setUserRealm( securityRealm );
        securityHandler.setConstraintMappings( new ConstraintMapping[]{ cm } );
View Full Code Here

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

     */
    public WebAppContext(SecurityHandler securityHandler,SessionHandler sessionHandler, ServletHandler servletHandler, ErrorHandler errorHandler)
    {
        super(null,
              sessionHandler!=null?sessionHandler:new SessionHandler(),
              securityHandler!=null?securityHandler:new SecurityHandler(),
              servletHandler!=null?servletHandler:new ServletHandler(),
              null);
       
        setErrorHandler(errorHandler!=null?errorHandler:new ErrorPageErrorHandler());
    }   
View Full Code Here

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

        SecurityHandler sh = new SecurityHandler();

        HashUserRealm realm = new HashUserRealm( "POC Server" );
        realm.put( "user", "password" );
        realm.put( "longuser", LONG_PASSWORD );
        realm.addUserToRole( "user", "allowed" );
        realm.addUserToRole( "longuser", "allowed" );

        sh.setUserRealm( realm );
        sh.setConstraintMappings( new ConstraintMapping[]{ cm } );

        WebAppContext ctx = new WebAppContext();
        ctx.setContextPath( "/" );

        File base = getBase();
View Full Code Here

     */
    public WebAppContext(SecurityHandler securityHandler,SessionHandler sessionHandler, ServletHandler servletHandler, ErrorHandler errorHandler)
    {
        super(null,
              sessionHandler!=null?sessionHandler:new SessionHandler(),
              securityHandler!=null?securityHandler:new SecurityHandler(),
              servletHandler!=null?servletHandler:new ServletHandler(),
              null);
       
        setErrorHandler(errorHandler!=null?errorHandler:new ErrorPageErrorHandler());
    }   
View Full Code Here

    }
   
    /* ------------------------------------------------------------ */
    public Context(HandlerContainer parent, String contextPath, int options)
    {
        this(parent,((options&SESSIONS)!=0)?new SessionHandler():null,((options&SECURITY)!=0)?new SecurityHandler():null,null,null);
        setContextPath(contextPath);
    }
View Full Code Here

        ServletMapping mapping = new ServletMapping();
        mapping.setServletName("jbiServlet");
        mapping.setPathSpec("/*");
        handler.setServletMappings(new ServletMapping[] {mapping});
        if (processor.getAuthMethod() != null) {
            SecurityHandler secHandler = new SecurityHandler();
            ConstraintMapping constraintMapping = new ConstraintMapping();
            Constraint constraint = new Constraint();
            constraint.setAuthenticate(true);
            constraint.setRoles(new String[] {"*"});
            constraintMapping.setConstraint(constraint);
            constraintMapping.setPathSpec("/");
            secHandler.setConstraintMappings(new ConstraintMapping[] {constraintMapping});
            secHandler.setHandler(handler);
            secHandler.setAuthMethod(processor.getAuthMethod());
            JaasUserRealm realm = new JaasUserRealm();
            if (configuration.getAuthenticationService() != null) {
                realm.setAuthenticationService(configuration.getAuthenticationService());
            }
            secHandler.setUserRealm(realm);
            context.setHandler(secHandler);
        } else {
            context.setHandler(handler);
        }
        context.setAttribute("processor", processor);
View Full Code Here

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

         SecurityHandler sh = new SecurityHandler();
         _server.setHandler(sh);
         sh.setUserRealm(userRealm);
         sh.setConstraintMappings(new ConstraintMapping[]{cm});
         sh.setAuthenticator(new BasicAuthenticator());

         Handler testHandler = new AbstractHandler()
         {

             public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException
             {
                 System.out.println("passed authentication!");
                 Request base_request=(request instanceof Request)?(Request)request:HttpConnection.getCurrentConnection().getRequest();
                 base_request.setHandled(true);
                 response.setStatus(200);
                 if (request.getServerName().equals("jetty.mortbay.org"))
                 {
                     response.getOutputStream().println("Proxy request: "+request.getRequestURL());
                 }
                 else if (request.getMethod().equalsIgnoreCase("GET"))
                 {
                     response.getOutputStream().println("<hello>");
                     for (int i=0; i<100; i++)
                     {
                         response.getOutputStream().println("  <world>"+i+"</world>");
                         if (i%20==0)
                             response.getOutputStream().flush();
                     }
                     response.getOutputStream().println("</hello>");
                 }
                 else
                 {
                     copyStream(request.getInputStream(),response.getOutputStream());
                 }
             }
         };

         sh.setHandler(testHandler);

         _server.start();
         _port = connector.getLocalPort();
     }
View Full Code Here

            HashUserRealm realm = new HashUserRealm("test");
            realm.put("testuser","password");
            realm.addUserToRole("testuser","test");
            _server.setUserRealms(new UserRealm[]{realm});
           
            SecurityHandler security=context.getSecurityHandler();
            security.setAuthenticator(new DigestAuthenticator());
            security.setUserRealm(realm);
          
            Constraint constraint = new Constraint("SecureTest","test");
            constraint.setAuthenticate(true);
            ConstraintMapping mapping = new ConstraintMapping();
            mapping.setConstraint(constraint);
            mapping.setPathSpec("/*");
            security.setConstraintMappings(new ConstraintMapping[]{mapping});
           
            HandlerCollection handlers = new HandlerCollection();
            handlers.setHandlers(new Handler[]
            { context, new DefaultHandler() });
            _server.setHandler(handlers);
View Full Code Here

TOP

Related Classes of org.mortbay.jetty.security.SecurityHandler

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.