Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keycloak + Spring Security, through local login form

I am trying to integrate keycloak into my spring security layer. I have achieved that, the only issue I have yet to solve is the following:

When an endpoint is hit, that requires the user to be authenticated, the site redirects to my keycloak login page. After login, the user is redirected back to the page they initially requested. What I'm trying to achieve is: I do not want my users redirecting from my app to the keycloak login page, and back again, but better yet, to login through a form on my app and "proxy" those captured details to keycloak and get the login token back.

If anyone can shed light on the above, whether it be possible or not, and if so, some direction to the solution would be smashing.

pom.xml:

<dependency>
    <groupId>org.keycloak</groupId>
    <artifactId>keycloak-spring-boot-adapter</artifactId>
    <version>2.4.0.Final</version>
</dependency>
<dependency>
    <groupId>org.keycloak</groupId>
    <artifactId>keycloak-tomcat8-adapter</artifactId>
    <version>2.4.0.Final</version>
</dependency>

application.properties:

keycloak.realm=MY_REALM
keycloak.realmKey=MY_REALM_KEY
keycloak.auth-server-url=MY_SERVER_URL
keycloak.resource=MY_RESOURCE
keycloak.ssl-required=external
keycloak.public-client=true
keycloak.use-resource-role-mappings=true

keycloak.securityConstraints[0].securityCollections[0].name=static-resources
keycloak.securityConstraints[0].securityCollections[0].patterns[0]=/css/*
keycloak.securityConstraints[0].securityCollections[0].patterns[1]=/fonts/*
keycloak.securityConstraints[0].securityCollections[0].patterns[2]=/js/*

keycloak.securityConstraints[1].securityCollections[0].name=application
keycloak.securityConstraints[1].securityCollections[0].authRoles[0]=MY_ROLE
keycloak.securityConstraints[1].securityCollections[0].patterns[0]=/api/*
like image 683
Tristan.G Avatar asked Mar 28 '17 11:03

Tristan.G


1 Answers

What you are trying to achieve contradicts the generell purpose of keycloak to keep user information separated from the application itself. Therefore there is (as fas a I know) no default/clean way to achieve this.

Instead you could consider styling the login page to fit your applications visual appearance.

like image 92
David Klassen Avatar answered Oct 08 '22 12:10

David Klassen