keycloak-scim/authorization_services/topics/getting-started/hello-world/deploy.adoc

105 lines
5.9 KiB
Text
Raw Normal View History

2016-11-29 15:30:53 +00:00
[[_getting_started_hello_world_deploy]]
2016-12-02 15:25:43 +00:00
=== Build, Deploy, and Test Your Application
2016-06-17 00:14:05 +00:00
Now that the *app-authz-vanilla* resource server (or client) is properly configured and authorization services are enabled, it can be deployed to the server.
2017-02-15 07:53:07 +00:00
The project and code for the application you are going to deploy is available in link:{{book.quickstartRepo.link}}[{{book.quickstartRepo.name}}]. You will need the following
installed on your machine and available in your PATH before you can continue:
* Java JDK 8
* Apache Maven 3.1.1 or higher
* Git
2017-02-15 07:53:07 +00:00
You can obtain the code by cloning the repository at {{book.quickstartRepo.link}}. Use the branch matching the version of Red Hat Single Sign-On in use. Follow these steps to download the code.
.Clone Project
[source, subs="attributes"]
----
2017-02-15 07:53:07 +00:00
$ git clone {{book.quickstartRepo.link}}
----
The application we are about to build and deploy is located at
----
2017-02-15 07:53:07 +00:00
$ cd {{book.quickstartRepo.dir}}/app-authz-jee-vanilla
----
2016-06-17 00:14:05 +00:00
==== Obtaining the Adapter Configuration
2016-06-17 00:14:05 +00:00
You must first obtain the adapter configuration before building and deploying the application.
To obtain the adapter configuration from the {{book.project.name}} Administration Console, complete the following steps.
. Click *Clients*. In the client listing, click the *app-authz-vanilla* client application. The Client Details page opens.
2016-11-29 15:30:53 +00:00
+
2016-06-17 00:14:05 +00:00
.Client Details
2017-01-05 16:54:31 +00:00
image:../../../{{book.images}}/getting-started/hello-world/enable-authz.png[alt="Client Details"]
2016-06-17 00:14:05 +00:00
2016-11-29 15:30:53 +00:00
. Click the *Installation* tab. From the Format Option dropdown list, select *Keycloak OIDC JSON*. The adapter configuration is displayed in JSON format. Click *Download*.
+
2016-06-17 00:14:05 +00:00
.Adapter Configuration
2017-01-05 16:54:31 +00:00
image:../../../{{book.images}}/getting-started/hello-world/adapter-config.png[alt="Adapter Configuration"]
2016-06-17 00:14:05 +00:00
. Move the file `keycloak.json` to the `app-authz-jee-vanilla/config` directory.
2016-06-17 00:14:05 +00:00
2016-11-29 15:30:53 +00:00
. (optional) By default, the policy enforcer responds with a `403` status code when the user lacks permission to access protected resources on the resource server. However, you can also specify a redirection URL for unauthorized users. To specify a redirection URL, edit the *keycloak.json* file you updated in step 3 and replace the `policy-enforcer` configuration with the following:
2016-06-23 03:16:11 +00:00
```json
"policy-enforcer": {
"on-deny-redirect-to" : "/app-authz-vanilla/error.jsp"
2016-06-23 03:16:11 +00:00
}
```
This change specifies to the policy enforcer to redirect users to a `/app-authz-vanilla/error.jsp` page if a user does not have the necessary permissions to access a protected resource, rather than an unhelpful `403 Unauthorized` message.
2016-06-23 03:16:11 +00:00
==== Building and Deploying the Application
2016-06-17 00:14:05 +00:00
To build and deploy the application execute the following command:
2016-06-17 00:14:05 +00:00
```bash
$ cd redhat-sso-quickstarts/app-authz-jee-vanilla
$ mvn clean package wildfly:deploy
2016-06-17 00:14:05 +00:00
```
==== Testing the Application
2016-06-17 00:14:05 +00:00
If your application was successfully deployed you can access it at http://localhost:8080/app-authz-vanilla[http://localhost:8080/app-authz-vanilla]. The {{book.project.name}} Login page opens.
2016-06-17 00:14:05 +00:00
.Login Page
2017-01-05 16:54:31 +00:00
image:../../../{{book.images}}/getting-started/hello-world/login-page.png[alt="Login Page"]
2016-06-17 00:14:05 +00:00
Log in as *alice* using the password you specified for that user. After authenticating, the following page is displayed:
2016-06-17 00:14:05 +00:00
.Hello World Authz Main Page
2017-01-05 16:54:31 +00:00
image:../../../{{book.images}}/getting-started/hello-world/main-page.png[alt="Hello World Authz Main Page"]
2016-06-17 00:14:05 +00:00
2016-11-29 15:30:53 +00:00
The <<fake/../../../resource-server/default-config.adoc#_resource_server_default_config, default settings>> defined by {{book.project.name}} when you enable authorization services for a client application provide a simple
policy that always grants access to the resources protected by this policy.
2016-06-17 00:14:05 +00:00
You can start by changing the default permissions and policies and test how your application responds, or even create new policies using the different
2016-11-29 15:30:53 +00:00
<<fake/../../../policy/overview.adoc#_policy_overview, policy types>> provided by {{book.project.name}}.
2016-07-26 21:34:49 +00:00
There are a plenty of things you can do now to test this application. For example, you can change the default policy by clicking the Authorization tab for the client, then `Policies` tab, then click on `Default Policy` in the list to allow you to change it as follows:
2016-07-26 21:34:49 +00:00
```js
// The default value is $evaluation.grant(),
// let's see what happens when we change it to $evaluation.deny()
$evaluation.deny();
2016-07-26 21:34:49 +00:00
```
Now, log out of the demo application and log in again. You can no longer access the application.
2016-07-26 21:34:49 +00:00
2017-01-05 16:54:31 +00:00
image:../../../{{book.images}}/getting-started/hello-world/access-denied-page.png[alt="Access Denied Page"]
2016-07-26 21:34:49 +00:00
Let's fix that now, but instead of changing the `Default Policy` code we are going to change the `Logic` to `Negative` using the dropdown list below the policy code text area.
That re-enables access to the application as we are negating the result of that policy, which is by default denying all requests for access. Again, before testing this change, be sure to log out and log in again.
2016-07-26 21:34:49 +00:00
==== Next Steps
2016-07-26 21:34:49 +00:00
There are additional things you can do, such as:
2016-07-26 21:34:49 +00:00
* Create a scope, define a policy and permission for it, and test it on the application side. Can the user perform an action (or anything else represented by the scope you created)?
2016-11-29 15:30:53 +00:00
* Create different types of policies such as <<fake/../../../policy/role-policy.adoc#_policy_rbac, role-based>>, <<fake/../../../policy/user-policy.adoc#_policy_user, user-based>>, <<fake/../../../policy/time-policy.adoc#_policy_time, time-based>>, <<fake/../../../policy/aggregated-policy.adoc#_policy_aggregated, aggregated policies>>, or <<fake/../../../policy/drools-policy.adoc#_policy_drools, rule-based>>, and associate these policies with the `Default Permission`.
* Apply multiple policies to the `Default Permission` and test the behavior. For example, combine multiple policies and change the `Decision Strategy` accordingly.
2016-11-29 15:30:53 +00:00
* For more information about how to view and test permissions inside your application see <<fake/../../../enforcer/authorization-context.adoc#_enforcer_authorization_context, Obtaining the Authorization Context>>.