public ServerFixture()

in wagon-tcks/wagon-tck-http/src/main/java/org/apache/maven/wagon/tck/http/fixture/ServerFixture.java [80:139]


    public ServerFixture( final boolean ssl )
        throws URISyntaxException, IOException
    {
        server = new Server();
        if ( ssl )
        {
            String keystore = getResource( SERVER_SSL_KEYSTORE_RESOURCE_PATH ).getAbsolutePath();

            LoggerFactory.getLogger( ServerFixture.class ).info( "TCK Keystore path: " + keystore );
            System.setProperty( "javax.net.ssl.keyStore", keystore );
            System.setProperty( "javax.net.ssl.trustStore", keystore );

            SslContextFactory sslContextFactory = new SslContextFactory();
            sslContextFactory.setKeyStorePath( keystore );
            sslContextFactory.setKeyStorePassword( SERVER_SSL_KEYSTORE_PASSWORD );
            sslContextFactory.setKeyManagerPassword( SERVER_SSL_KEYSTORE_PASSWORD );
            serverConnector = new ServerConnector( server, sslContextFactory );
            server.addConnector( serverConnector );
        }
        else
        {
            serverConnector = new ServerConnector( server );
            serverConnector.setHost( "localhost" );
            //connector.setPort( port );
            server.addConnector( serverConnector );
        }

        Constraint constraint = new Constraint();
        constraint.setName( Constraint.__BASIC_AUTH );

        constraint.setRoles( new String[]{ "allowed" } );
        constraint.setAuthenticate( true );

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

        securityHandler = new ConstraintSecurityHandler();

        loginService = new HashLoginService( "Test Server" );

        securityHandler.setLoginService( loginService );
        securityHandler.setConstraintMappings( new ConstraintMapping[]{ cm } );

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

        File base = getResource( SERVER_ROOT_RESOURCE_PATH );
        logger.info( "docroot: " + base );
        webappContext.setWar( base.getAbsolutePath() );
        webappContext.setHandler( securityHandler );

        SessionHandler sessionHandler = webappContext.getSessionHandler();
        ( (AbstractSessionManager) sessionHandler.getSessionManager() ).setUsingCookies( false );

        HandlerCollection handlers = new HandlerCollection();
        handlers.setHandlers( new Handler[]{ webappContext, new DefaultHandler() } );

        server.setHandler( handlers );
    }