The jkniv-jaas-jetty implements a hybrid realm for authentication and authorization model from JavaTM Authentication and Authorization Service to Jetty server.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency> <groupId>net.sf.jkniv</groupId> <artifactId>jkniv-jaas-jetty</artifactId> <version>0.3.1</version> </dependency>
Create new file jetty-install/etc/login.conf to config the hybridRealm. The name hybridRealm must be the same value for LoginModuleName at Hybrid Realm Properties.
hybridRealm { net.sf.jkniv.jaas.jetty.HybridLoginModule required authe-ldap=false authe-jdbc=true datasource-jndi="jdbc/myDataSource" user-table=AUTH_USER user-name-column =USERNAME user-password-column =PASSWD group-table =AUTH_GROUP group-name-column =GROUP_ID group-table-user-name-column=USERNAME assign-groups=auth; };
Note: Config file from JAAS treat slash as comments, so to config JNDI name from datasource put the key between double quotes like "jdbc/myDataSource"
<Configure id="Server" class="org.eclipse.jetty.server.Server"> ... <Call name="addBean"> <Arg> <New class="org.eclipse.jetty.jaas.JAASLoginService"> <Set name="name">acme-realm</Set> <Set name="LoginModuleName">hybridRealm</Set> </New> </Arg> </Call> <Call name="addBean"> <Arg> <New id="dsWhinstone" class="org.eclipse.jetty.plus.jndi.Resource"> <Arg>jdbc/whinstone</Arg> <Arg> <New class="com.jolbox.bonecp.BoneCPDataSource"> <Set name="driverClass">oracle.jdbc.driver.OracleDriver</Set> <Set name="jdbcUrl">jdbc:oracle:thin:@127.0.0.1:1521:XE</Set> <Set name="username">whinstone</Set> <Set name="password">secret</Set> <Set name="minConnectionsPerPartition">5</Set> <Set name="maxConnectionsPerPartition">50</Set> <Set name="acquireIncrement">5</Set> <Set name="idleConnectionTestPeriod">30</Set> </New> </Arg> </New> </Arg> </Call> </Configure>
Modify web.xml from your application configuring the new realm acme-realm:
Any user authenticated auth
FORM acme-realm /login.html /error.html Exclude from Security /api/* auth
Enable security jaas and jndi for jetty in jetty-install/start.ini file:
--module=plus --module=jaas jetty.jaas.login.conf=etc/login.conf
More information to configure JNDI in Jetty 8 or JNDI in Jetty 9