Skip to content

Instantly share code, notes, and snippets.

@imotov
Created April 2, 2012 10:32
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save imotov/2282444 to your computer and use it in GitHub Desktop.
elasticsearch-jetty Basis Auth Configuration
http.type: com.sonian.elasticsearch.http.jetty.JettyHttpServerTransportModule
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id="ESServer" class="org.eclipse.jetty.server.Server">
<New class="com.sonian.elasticsearch.http.jetty.handler.JettyHttpServerTransportHandler"
id="HttpServerAdapterHandler">
</New>
<New class="com.sonian.elasticsearch.http.jetty.error.JettyHttpServerErrorHandler"
id="HttpServerErrorHandler">
</New>
<New class="org.eclipse.jetty.security.HashLoginService"
id="DefaultLoginService">
<Set name="name">DefaultRealm</Set>
<Set name="config"><Property name="es.config"/>/realm.properties</Set>
<Set name="refreshInterval">5</Set>
<Call name="start"/>
</New>
<New class="org.eclipse.jetty.http.security.Constraint"
id="BasicSecurityConstraint">
<Set name="authenticate">true</Set>
<Set name="name">BASIC</Set>
<Set name="roles">
<Array type="java.lang.String">
<Item>user</Item>
</Array>
</Set>
</New>
<New class="com.sonian.elasticsearch.http.jetty.security.RestConstraintSecurityHandler"
id="DefaultSecurityHandler">
<Set name="loginService">
<Ref id="DefaultLoginService"/>
</Set>
<Set name="realmName">DefaultRealm</Set>
<!-- ======================================== -->
<!-- Require password for everything -->
<!-- ======================================== -->
<Call name="addConstraintMapping">
<Arg>
<New class="org.eclipse.jetty.security.ConstraintMapping">
<Set name="pathSpec">*</Set>
<Set name="constraint">
<Ref id="BasicSecurityConstraint"/>
</Set>
</New>
</Arg>
</Call>
</New>
<Call name="addBean">
<Arg>
<Ref id="DefaultLoginService"/>
</Arg>
</Call>
<Call name="addBean">
<Arg>
<Ref id="HttpServerErrorHandler"/>
</Arg>
</Call>
<New id="GzipHandler" class="org.eclipse.jetty.server.handler.GzipHandler">
<Set name="handler">
<Ref id="DefaultSecurityHandler"/>
</Set>
</New>
<Set name="handler">
<Ref id="GzipHandler"/>
</Set>
<Ref id="DefaultSecurityHandler">
<Set name="handler">
<Ref id="HttpServerAdapterHandler"/>
</Set>
</Ref>
<!-- ======================================== -->
<!-- Add HTTP connector -->
<!-- ======================================== -->
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
<Set name="host"><Property name="jetty.bind_host"/></Set>
<Set name="port"><Property name="jetty.port"/></Set>
<Set name="maxIdleTime">600000</Set>
<Set name="Acceptors">2</Set>
</New>
</Arg>
</Call>
</Configure>
user: YouPasswordGoesHere,user
@ulkas
Copy link

ulkas commented Nov 11, 2015

in case of this error:
ClassNotFoundException[org.eclipse.jetty.http.security.Constraint]

simply change the route in the jetty.xml file to
org.eclipse.jetty.util.security.Constraint

tags: elastic, elasticsearch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment