Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GET , POST , PUT , DELETE type based Authentication in keycloak

I have a resource in an API for which URI is /product/{id} and doing three operations VIEW, GET, DELETE basse on HttpMethod.

How can I manage one user is allowed to only VIEW and admin is allowed to VIEW, GET, DELETE i.e. all options.

I had seen Keycloak Adapter Policy Enforcer but, I don't understand how it works. I am not getting methods option in create permission.

Can somebody help me in implementing this or suggest some way to do it.

like image 939
Zenny Avatar asked Apr 25 '19 07:04

Zenny


People also ask

How do you authenticate with a Keycloak?

Configure Keycloak to authenticate your cbioportal instance. Log in to your Keycloak Identity Provider, e.g. http://localhost:8080/auth, as an admin user. ⚠️ when setting this up on something else than localhost (e.g. production), you will need to use/enable https on your Keycloak server.

How do I get authorization code from Keycloak?

You access the keycloak login page using a client id and a redirect url to your application. Once the login is successful, the keycloak server redirects to your app again, providing the authorization code appended in the url itself.

Does Keycloak support basic authentication?

Yes that's possible for clients with Access Type: confidential and Direct Access Grants Enabled . You can find more details on these settings in the documentation. You also need to enable enable-basic-auth and supply your credentials in your application settings.

What is access type in Keycloak?

Access Type. This defines the type of the OIDC client. confidential. Confidential access type is for server-side clients that need to perform a browser login and require a client secret when they turn an access code into an access token, (see Access Token Request in the OAuth 2.0 spec for more details).

How do I use Keycloak and OAuth with Postman?

To use these endpoints with Postman, let's start with creating an Environment called “ Keycloak “. Then we add some key/value entries for the Keycloak authorization server URL, the realm, OAuth 2.0 client id, and client password:

What is Keycloak authentication and authorization?

Keycloak Basic Configuration for Authentication and Authorization. Managing authentication and authorization is an essential task in every good-designed web application or service. Keycloak makes it very easy and practical, letting us focus on the application business logic rather than on the implementation of security features.

Which user can access /member API in Keycloak?

According to our KeyCloak Security Configuration class, the user with the role Member can access /member API, and the user with the role Admin can access /admin API. Let’s test our application using Postman.

How to configure Keycloak?

First, we will do the Keycloak configuration steps which are as follows. After logging in to the Keycloak console, in the top left corner there is an option of adding a new Realm. In the left pane, there is an option for Clients. This will show all the clients in the new realm. Firstly, we will create a new client with the following configurations.


1 Answers

I guess you installed Keycloak for being able to control not just authentication, but also authorization. Then you don't need spring security at all. You need to enable authorization for your client and configure resources, policies and permissions using Keycloak admin console. Here is documentation

To be able to control your resources more granular use policy enforcers and map HTTP methods to scopes like described here: How to add HTTP methods in Keycloak resources for Authorization (Without adapters).

One of the good examples worth to look at is authz-spring-boot. It has complete authorization flow, but without method restriction that can be manually added.

You also can check how does your policy work using "Evalute" tab at Keycloak. This simulates client call to the resource and shows the result

like image 93
Vadim Avatar answered Oct 24 '22 18:10

Vadim