Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 10. OAuth2-Based Security for OData
10.1. OAuth2-Based Security for OData Link kopierenLink in die Zwischenablage kopiert!
10.1.1. Configuring Your Red Hat SSO Server Link kopierenLink in die Zwischenablage kopiert!
You must have Red Hat SSO installed as a separate web server preferably on a different server machine. Please consult the Red Hat SSO documentation for more information about this.
- Log into the Dashboard at http://localhost:8080/auth/admin/master/console/#/realms/oauth using the default "admin/admin" credentials. (You may have to create a Red Hat SSO administrative account in order to do this.)
- Under the General tab, add a new realm called "oauth-demo".
- Under Manage - Users, click "Add User" and add a new user called "user" with credentials.
- Under Configure - Roles - Realm, click "Add Roles" and add the "odata" and "user" roles to your new user.
- Under Configure - Clients - Settings, add a new client called "odata4-oauth". Add the odata and user roles and then choose scopes "odata" and "user" for this client.
Note
The redirect URI needs to be where the actual service is going to be available. Here is an example: http://[host]:[port]/odata4/*The client web-service defines the roles the logged-in user must have in order to be granted access. In the Red Hat SSO OAuth2 implementation, these roles are used as "scopes". Note that the "odata4-oauth" client must have the scopes that it is going to delegate the access-token for gaining access to bottom data services. In this example Red Hat JBoss Data Virtualization’s OData web services requires the "odata" role. If you are delegating the access-token to the underlying web-service requires the "user" role.Note
The "user" role is suggested as an example role required for the underlying source webservice. You need to replace it with the real role required for the webservice.
10.1.2. Configure the Red Hat JBoss Data Virtualization server Link kopierenLink in die Zwischenablage kopiert!
Red Hat JBoss Data Virtualization server installed.
- Follow the instructions found here in the Red Hat SSO documentation to install the EAP 6 adapter: https://access.redhat.com/documentation/en/red-hat-single-sign-on/7.0/paged/securing-applications-and-services-guide/chapter-2-openid-connect
- Change the OData transport’s "security-domain" section using this CLI script:
/subsystem=teiid/transport=odata:write-attribute(name=authentication-security-domain, value=oauth)
/subsystem=teiid/transport=odata:write-attribute(name=authentication-security-domain, value=oauth)Copy to Clipboard Copied! Toggle word wrap Toggle overflow The code will change to look like this:<transport name="odata"> <authentication security-domain="oauth"/> </transport><transport name="odata"> <authentication security-domain="oauth"/> </transport>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Note that, for this to deploy, you must also have the security domain configured on the server. To do so, run these CLI commands to create oauth and keycloack security domains:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Run the following CLI to undeploy the WAR file:
undeploy teiid-olingo-odata4.war
undeploy teiid-olingo-odata4.warCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Download the Maven project found here: https://github.com/teiid/teiid-web-security
- Replace the "teiid-web-security/teiid-odata-oauth-keycloak/src/main/webapp/WEB-INF/keyclock.json" file’s contents with the "installation" script from the Red Hat SSO admin console’s "odata4-client" client application.
- Run this maven command to build the authentication module:
mvn clean package
mvn clean packageCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Deploy the WAR file using this script:
deploy PATH/teiid-olingo-odata4.war
deploy PATH/teiid-olingo-odata4.warCopy to Clipboard Copied! Toggle word wrap Toggle overflow - To
testusing a browser, go to this address: http://localhost:8180/odata4/keycloak/auth - Confirm that you can see a message that states "Congratulations!!! Login successful..".You can now execute any OData specific URL and that will participate in OAuth2 using OpenID Connect extension in RH-SSO.
Note
Note
curl -k -H "Authorization: Bearer eyJhbGciOiJSUzI1NiJ9.eyJqdGkiOiI0YjI4NDMzYS1.." http://localhost:8180/odata4/oauthdemo/view/message
curl -k -H "Authorization: Bearer eyJhbGciOiJSUzI1NiJ9.eyJqdGkiOiI0YjI4NDMzYS1.." http://localhost:8180/odata4/oauthdemo/view/message
10.1.3. Delegation of an OAuth2 Token to a Data Source Link kopierenLink in die Zwischenablage kopiert!
- Log into the RH-SSO admin console.
- Under the realm “oauth-demo”, and then Clients - Settings, add another client called "database-service" and set the scope to "user". Set the type to "Bearer".
- Follow the instructions in RH-SSO to secure this web service with above realm “oauth-demo”
- Deploy this war into your web server.
- Create a “web service” resource adapter for this service, using “oauth” as the security-domain.
- Use this resource adapter as source in developing your virtual database.
Note
The delegation will occur if the virtual database is accessed through the OData interface. JDBC-based access to this virtual database would fail.