このコンテンツは選択した言語では利用できません。
Chapter 5. Securing a web application using OpenID Connect
You can secure an application by either updating its deployment configuration or by configuring the elytron-oidc-client subsystem
.
If you use the application created in the procedure, Creating a web application, the value of the Principal comes from the ID token from the OpenID provider. By default, the Principal is the value of the "sub" claim from the token. You can specify which claim value from the ID token to use as the Principal in one of the following:
-
The
elytron-oidc-client
subsystem attributeprincipal-attribute
. -
The oidc.json file
.
Prerequisites
- You have deployed applications on JBoss EAP.
Procedure
Configure the application’s
web.xml
to protect the application resources.Syntax
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example
Copy to Clipboard Copied! Toggle word wrap Toggle overflow In this example, only the users with the role
Admin
can access the application.To secure the application with OpenID Connect, either update the deployment configuration or configure the
elytron-oidc-client
subsystem.NoteIf you configure OpenID Connect in both the deployment configuration and the
elytron-oidc-client
subsystem, the configuration in theelytron-oidc-client
subsystemsecure-deployment
attribute takes precedence over the configuration in the application deployment descriptor.Updating the deployment configuration:
Create a file
oidc.json
in theWEB-INF
directory, like this:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Update the deployment descriptor
web.xml
file with the following text to declare that this application uses OIDC:<login-config> <auth-method>OIDC</auth-method> </login-config>
<login-config> <auth-method>OIDC</auth-method> </login-config>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Configuring the
elytron-oidc-client
subsystem:To secure your application, use the following management CLI command:
/subsystem=elytron-oidc-client/secure-deployment=simple-oidc-example.war/:add(client-id=my_jbeap,provider-url=http://localhost:8180/auth/realms/example_realm,public-client=true,ssl-required=external)
/subsystem=elytron-oidc-client/secure-deployment=simple-oidc-example.war/:add(client-id=my_jbeap,provider-url=http://localhost:8180/auth/realms/example_realm,public-client=true,ssl-required=external)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
In the application root directory, compile your application with the following command:
mvn package
$ mvn package
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Deploy the application.
mvn wildfly:deploy
$ mvn wildfly:deploy
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
In a browser, navigate to
http://localhost:8080/simple-webapp-example/secured
.You are redirected to Red Hat Single Sign-On login page.
Log in with your credentials. For example:
username: user1 password: passwordUser1
username: user1 password: passwordUser1
Copy to Clipboard Copied! Toggle word wrap Toggle overflow You get the following output:
Forbidden
Forbidden
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
The redirection to Red Hat Single Sign-On login page confirms that the OIDC connection succeeds and the output confirms that users without the role Admin
cannot access the application. To add the role Admin
to the user user1
, see Creating and assigning user roles in Red Hat Single Sign-On.