This example project is comprehended by the following:
- HSQLDB in-memory datasource
- Aries (JPA 1.1) + Hibernate (4.2.11) powered persistence
- Shiro-based tailored session-management OSGi service
- Hazelcast (2.6) powered session distributed persistence
- JAX-RS (2.0) filters to deal with HTTP requests and map them to Shiro sessions (maintained by the aforementioned OSGi service)
- CXF endpoint to test them all
- JDK 7
- Maven 3.1.0 or newer
mvn clean install
- Download latest build for
fabric-karaf
and extract it. (tested on fabric8-karaf-1.0.0.redhat-362) - Extract it
cd
to the newly extracted folder- Define default administrative user (login: admin, password:admin) by uncommenting the last line of
etc/user.properties
- Start Fabric
bin/fusefabric
If everything goes well, you should get a Fabric shell that looks like this:
Please wait while Fabric8 is loading...
100% [========================================================================]
______ _ _ _____
| ___| | | (_) | _ |
| |_ __ _| |__ _ __ _ ___ \ V /
| _/ _` | '_ \| '__| |/ __|/ _ \
| || (_| | |_) | | | | (__| |_| |
\_| \__,_|_.__/|_| |_|\___\_____/
Fabric8 Container (1.0.0.redhat-362)
http://fabric8.io/
Type 'help' to get started
and 'help [cmd]' for help on a specific command.
Hit '<ctrl-d>' or 'osgi:shutdown' to shutdown this container.
Open a browser to http://localhost:8181 to access the management console
Create a new Fabric via 'fabric:create'
or join an existing Fabric via 'fabric:join [someUrls]'
Fabric8:karaf@root>
fabric:create --clean --wait-for-provisioning
profile-create --parents feature-dosgi cxf-shiro-example
profile-edit --repositories mvn:org.apache.karaf.cellar/apache-karaf-cellar/2.3.2/xml/features cxf-shiro-example
profile-edit --repositories mvn:com.github.pires.example/feature-persistence/0.1-SNAPSHOT/xml/features cxf-shiro-example
profile-edit --repositories mvn:com.github.pires.example/feature-rest/0.1-SNAPSHOT/xml/features cxf-shiro-example
profile-edit --features hazelcast cxf-shiro-example
profile-edit --features persistence-aries-hibernate cxf-shiro-example
profile-edit --features cxf-shiro cxf-shiro-example
profile-edit --bundles mvn:com.github.pires.example/datasource-hsqldb/0.1-SNAPSHOT cxf-shiro-example
profile-edit --bundles mvn:com.github.pires.example/service/0.1-SNAPSHOT cxf-shiro-example
profile-edit --bundles mvn:com.github.pires.example/service-impl/0.1-SNAPSHOT cxf-shiro-example
profile-edit --bundles mvn:com.github.pires.example/cxf-shiro/0.1-SNAPSHOT cxf-shiro-example
container-create-child --profile cxf-shiro-example root cxf-shiro-example-test1
In Hawt.io UI, go to API
tab (in the parent container), check the host and port where AuthenticationManager
is available and point it down. Test the REST endpoint as you wish!
PUT /demo/auth
POST /demo/auth
Example JSON:
{
"username":"[email protected]",
"password":["1","2","3"]
}
Check the response headers and write down be-token, for usage in authenticated requests.
Set be-token header to the value you've written before.
GET /demo/auth
You should see [email protected] in the response body.