Package org.eclipse.jetty.security

Examples of org.eclipse.jetty.security.ConstraintSecurityHandler


    }

    private SecurityHandler getSecurityHandler(String pUser, String pPassword, String pRole) {
      HashLoginService loginService = getLoginService(pUser, pPassword, pRole);
      server.addBean(loginService);         
      ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
      securityHandler.setConstraintMappings(getConstraintMappings(pRole));
      securityHandler.setAuthenticator(new BasicAuthenticator());
      securityHandler.addBean(loginService);
        return securityHandler;
    }
View Full Code Here


    loginService.putUser(properties.getProperty("eventhubhandler.username"),
        new Password(properties.getProperty("eventhubhandler.password")), new String[]{"user"});

    server.addBean(loginService);

    ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
    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 );
    securityHandler.setConstraintMappings(Collections.singletonList(mapping));
    securityHandler.setAuthenticator(new BasicAuthenticator());
    securityHandler.setLoginService(loginService);

    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setDirectoriesListed(false);
    resourceHandler.setWelcomeFiles(new String[]{"main.html"});
    resourceHandler.setResourceBase(webDir);
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[]{new JsonpCallbackHandler(eventHubHandler), securityHandler});

    server.setHandler(handlers);
    securityHandler.setHandler(resourceHandler);

    server.start();
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
      @Override
      public void run() {
View Full Code Here

   
    @Test
    public void itRequiresAuthenticationForAllRequests() throws Exception {
      config.configureContext(context);
     
      final ConstraintSecurityHandler securityHandler = (ConstraintSecurityHandler) context.getSecurityHandler();
      final ConstraintMapping authenticateAll = securityHandler.getConstraintMappings()[0];
      assertThat(authenticateAll.getPathSpec(), is("/*"));
      assertThat(authenticateAll.getConstraint().getAuthenticate(), is(true));
      assertThat(authenticateAll.getConstraint().getRoles(), is(new String[] { "user" }));
    }
View Full Code Here

   
    @Test
    public void itDoesNotRequireAuthenticationForAHealthCheckRequest() throws Exception {
      config.configureContext(context);
     
      final ConstraintSecurityHandler securityHandler = (ConstraintSecurityHandler) context.getSecurityHandler();
      final ConstraintMapping authenticateAll = securityHandler.getConstraintMappings()[1];
      assertThat(authenticateAll.getPathSpec(), is("/health/"));
      assertThat(authenticateAll.getConstraint().getAuthenticate(), is(false));
    }
View Full Code Here

   
    @Test
    public void itDoesNotRequireAuthenticationForAStatsRequest() throws Exception {
      config.configureContext(context);
     
      final ConstraintSecurityHandler securityHandler = (ConstraintSecurityHandler) context.getSecurityHandler();
      final ConstraintMapping authenticateAll = securityHandler.getConstraintMappings()[2];
      assertThat(authenticateAll.getPathSpec(), is("/stats/*"));
      assertThat(authenticateAll.getConstraint().getAuthenticate(), is(false));
    }
View Full Code Here

    return new SocketConnector();
  }
 
  @Override
  protected void configureContext(ServletContextHandler context) {
    final ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
    securityHandler.setRealmName("brcm-accounts-api");
   
    final Authenticator authenticator = new WesabeAuthenticator(securityHandler);
    securityHandler.setAuthenticator(authenticator);
   
    final Constraint requireAuthentication = new Constraint();
    requireAuthentication.setAuthenticate(true);
    requireAuthentication.setRoles(new String[] { "user" });
   
    final ConstraintMapping authenticateAll = new ConstraintMapping();
    authenticateAll.setPathSpec("/*");
    authenticateAll.setConstraint(requireAuthentication);
   
    final Constraint passThrough = new Constraint();
    passThrough.setAuthenticate(false);
   
    final ConstraintMapping healthCheckExemption = new ConstraintMapping();
    healthCheckExemption.setPathSpec("/health/");
    healthCheckExemption.setConstraint(passThrough);
   
    final ConstraintMapping statsExemption = new ConstraintMapping();
    statsExemption.setPathSpec("/stats/*");
    statsExemption.setConstraint(passThrough);
   
    securityHandler.setConstraintMappings(new ConstraintMapping[] { authenticateAll, healthCheckExemption, statsExemption });
    context.setSecurityHandler(securityHandler);
  }
View Full Code Here

    cm.getConstraint().setAuthenticate(true);
    cm.getConstraint().setDataConstraint(Constraint.DC_NONE);
    cm.getConstraint().setRoles(new String[] { role });
    cm.setPathSpec("/*");

    ConstraintSecurityHandler sec = new ConstraintSecurityHandler();
    sec.setStrict(false);
    sec.setRealmName(realm);
    sec.setAuthenticator(authType);
    sec.setLoginService(users);
    sec.setConstraintMappings(new ConstraintMapping[] { cm });
    sec.setHandler(ctx);

    contexts.removeHandler(ctx);
    contexts.addHandler(sec);
  }
View Full Code Here

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

    ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
    securityHandler.setRealmName("Test Server");
    securityHandler.setAuthMethod("BASIC");
    securityHandler.setStrict(true);
    securityHandler.setConstraintMappings(new ConstraintMapping[]{cm});
    HashLoginService hashLoginService = new HashLoginService("Test Server");
    securityHandler.setLoginService(hashLoginService);
    webappContext.setSecurityHandler(securityHandler);

    hashLoginService.putUser("admin", new Password("admin"), new String[]{"users"});

    server.start();
View Full Code Here

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

        ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
        csh.setAuthenticator(new BasicAuthenticator());
        csh.setRealmName(realm);
        csh.addConstraintMapping(cm);
        csh.setLoginService(l);

        return csh;

    }
View Full Code Here

    private void buildSecurityHandlerIfNecessary() {
        if (securityHandler == null) {
            HashLoginService l = new HashLoginService();
            l.setName("realm");

            ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
            csh.setAuthenticator(new BasicAuthenticator());
            csh.setRealmName("realm");
            csh.setLoginService(l);

            securityHandler = csh;
        }
    }
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.