org.eclipse.jetty.security.authentication.DigestAuthenticator Java Examples

The following examples show how to use org.eclipse.jetty.security.authentication.DigestAuthenticator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpServerExtension.java    From kareldb with Apache License 2.0 5 votes vote down vote up
@Override
protected ConstraintSecurityHandler configureDigestAuthentication(Server server,
                                                                  AvaticaServerConfiguration config) {
    LOG.info("Configuring digest auth");
    final String[] allowedRoles = config.getAllowedRoles();
    final String realm = config.getHashLoginServiceRealm();

    JAASLoginService loginService = new JAASLoginService(realm);
    server.addBean(loginService);

    return configureCommonAuthentication(Constraint.__DIGEST_AUTH,
        allowedRoles, new DigestAuthenticator(), null, loginService);
}
 
Example #2
Source File: TestInvokeHttpCommon.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private DigestAuthHandler() {
    digestAuthenticator = new DigestAuthenticator();
    ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();

    HashLoginService hashLoginService = new HashLoginService("realm");
    hashLoginService.putUser("basic_user", new Password("basic_password"), new String[]{"realm"});
    securityHandler.setLoginService(hashLoginService);
    securityHandler.setIdentityService(new DefaultIdentityService());
    digestAuthenticator.setConfiguration(securityHandler);
}
 
Example #3
Source File: EmissaryServer.java    From emissary with Apache License 2.0 5 votes vote down vote up
private ConstraintSecurityHandler buildSecurityHandler() {
    ConstraintSecurityHandler handler = new ConstraintSecurityHandler();
    Constraint constraint = new Constraint();
    constraint.setName("auth");
    constraint.setAuthenticate(true);
    constraint.setRoles(new String[] {"everyone", "emissary", "admin", "support", "manager"});
    ConstraintMapping mapping = new ConstraintMapping();
    mapping.setPathSpec("/*");
    mapping.setConstraint(constraint);
    handler.setConstraintMappings(Collections.singletonList(mapping));
    handler.setAuthenticator(new DigestAuthenticator());
    return handler;
}
 
Example #4
Source File: HttpServer.java    From calcite-avatica with Apache License 2.0 5 votes vote down vote up
protected ConstraintSecurityHandler configureDigestAuthentication(Server server,
    AvaticaServerConfiguration config) {
  final String[] allowedRoles = config.getAllowedRoles();
  final String realm = config.getHashLoginServiceRealm();
  final String loginServiceProperties = config.getHashLoginServiceProperties();

  HashLoginService loginService = new HashLoginService(realm, loginServiceProperties);
  server.addBean(loginService);

  return configureCommonAuthentication(Constraint.__DIGEST_AUTH,
      allowedRoles, new DigestAuthenticator(), null, loginService);
}
 
Example #5
Source File: WebServerTask.java    From datacollector with Apache License 2.0 5 votes vote down vote up
private ConstraintSecurityHandler configureDigestBasic(Configuration conf, Server server, String mode) {
  LoginService loginService = getLoginService(conf, mode);
  server.addBean(loginService);

  ConstraintSecurityHandler security = new ConstraintSecurityHandler();
  switch (mode) {
    case "digest":
      security.setAuthenticator(injectActivationCheck(new ProxyAuthenticator(
          new DigestAuthenticator(),
          runtimeInfo,
          conf
      )));
      break;
    case "basic":
      security.setAuthenticator(injectActivationCheck(new ProxyAuthenticator(
          new BasicAuthenticator(),
          runtimeInfo,
          conf
      )));
      break;
    default:
      // no action
      break;
  }
  security.setLoginService(loginService);
  return security;
}
 
Example #6
Source File: DigestAuthSupplierJettyTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
protected void run() {
    server = new Server(PORT);

    HashLoginService loginService = new HashLoginService();
    loginService.setName("My Realm");
    UserStore userStore = new UserStore();
    String[] roles = new String[] {"user"};
    userStore.addUser(USER, Credential.getCredential(PWD), roles);
    loginService.setUserStore(userStore);

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

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

    ConstraintSecurityHandler csh = new ConstraintSecurityHandler();
    csh.setAuthenticator(new DigestAuthenticator());
    csh.addConstraintMapping(cm);
    csh.setLoginService(loginService);

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setSecurityHandler(csh);
    context.setContextPath("/");
    server.setHandler(context);
    context.addServlet(new ServletHolder(new TestServlet()), "/*");

    try {
        server.start();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #7
Source File: TestInvokeHttpCommon.java    From nifi with Apache License 2.0 5 votes vote down vote up
private DigestAuthHandler() throws Exception {
    digestAuthenticator = new DigestAuthenticator();
    ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();

    final HashLoginService hashLoginService = new HashLoginService("realm", "src/test/resources/TestInvokeHttp/realm.properties");
    hashLoginService.start();

    securityHandler.setLoginService(hashLoginService);
    securityHandler.setIdentityService(new DefaultIdentityService());
    digestAuthenticator.setConfiguration(securityHandler);
}
 
Example #8
Source File: TestWebServicesFetcher.java    From datacollector with Apache License 2.0 4 votes vote down vote up
protected void runServer(int port, boolean serverSsl, boolean clientSsl, String httpAuth, Callable<Void> test)
    throws Exception {
  Server server = createServer(port, serverSsl, clientSsl);

  ServletContextHandler contextHandler = new ServletContextHandler();
  if (!httpAuth.equals("none")) {
    File realmFile = new File(getConfDir(), httpAuth + ".properties");
    LoginService loginService = new HashLoginService(httpAuth, realmFile.getAbsolutePath());
    server.addBean(loginService);
    ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
    switch (httpAuth) {
      case "basic":
        securityHandler.setAuthenticator(new BasicAuthenticator());
        break;
      case "digest":
        securityHandler.setAuthenticator(new DigestAuthenticator());
        break;
    }
    securityHandler.setLoginService(loginService);
    Constraint constraint = new Constraint();
    constraint.setName("auth");
    constraint.setAuthenticate(true);
    constraint.setRoles(new String[]{"user"});
    ConstraintMapping mapping = new ConstraintMapping();
    mapping.setPathSpec("/*");
    mapping.setConstraint(constraint);
    securityHandler.addConstraintMapping(mapping);
    contextHandler.setSecurityHandler(securityHandler);
  }

  MockCyberArkServlet servlet = new MockCyberArkServlet();
  contextHandler.addServlet(new ServletHolder(servlet), "/AIMWebService/api/Accounts");
  contextHandler.setContextPath("/");
  server.setHandler(contextHandler);
  try {
    server.start();
    test.call();
  } finally {
    server.stop();
  }
}