1) Deploy the Apache CXF STS in docker
Apache CXF ships with a powerful and flexible STS that can issue, renew, validate, cancel tokens of different types via the (SOAP) WS-Trust interface. In addition, it also has a flexible REST interface. I created a sample github project which builds the CXF STS with the REST interface enabled:
- sts-rest: Project to deploy a CXF REST STS web application in docker
- mvn clean install
- docker build -t coheigea/cxf-sts-rest .
- docker run -p 8080:8080 coheigea/cxf-sts-rest
- http://localhost:8080/cxf-sts-rest/SecurityTokenService/token/saml
- http://localhost:8080/cxf-sts-rest/SecurityTokenService/token/jwt
Now we'll look at how to modify the previous tutorial so that the REST API is secured by a token issued by the Apache CXF STS, instead of the Knox token service. To start with, follow the first tutorial to set up Apache Knox as well as the backend Apache Hadoop cluster we are trying to obtain a file from. Then follow part (2) of the previous tutorial to set up the "sandbox-token" topology. Now copy "conf/topologies/sandbox-token.xml" to "conf/topologies/sandbox-token-cxf.xml". We need to make a few changes to the "JWTProvider" to support validating tokens issued by the CXF STS.
Edit "conf/topologies/sandbox-token.xml" and add the following parameters to the "JWTProvider", i.e.:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<topology> | |
<gateway> | |
<provider> | |
<role>federation</role> | |
<name>JWTProvider</name> | |
<enabled>true</enabled> | |
<param> | |
<name>knox.token.verification.pem</name> | |
<value>MIID5...</value> | |
</param> | |
<param> | |
<name>jwt.expected.issuer</name> | |
<value>CXF_STS</value> | |
</param> | |
</provider> | |
... | |
</gateway> | |
... | |
</topology> |
Now save the topology file and we can get a token from CXF STS using curl as follows:
- curl -u alice:security -H "Accept: text/plain" http://localhost:8080/cxf-sts-rest/SecurityTokenService/token/jwt
- curl -kL -H "Authorization: Bearer <access token>" https://localhost:8443/gateway/sandbox-token-cxf/webhdfs/v1/data/LICENSE.txt?op=OPEN
No comments:
Post a Comment