fake-keycloak-spring-security-adapter

Keycloak Spring Security Fake adapter

License

License

Categories

Categories

Security KeY Data Data Formats Formal Verification Keycloak
GroupId

GroupId

com.yo1000
ArtifactId

ArtifactId

fake-keycloak-spring-security-adapter
Last Version

Last Version

2.0.0-keycloak-4.2
Release Date

Release Date

Type

Type

jar
Description

Description

fake-keycloak-spring-security-adapter
Keycloak Spring Security Fake adapter
Project URL

Project URL

https://github.com/yo1000/fake-keycloak-spring-security-adapter
Source Code Management

Source Code Management

https://github.com/yo1000/fake-keycloak-spring-security-adapter

Download fake-keycloak-spring-security-adapter

How to add to project

<!-- https://jarcasting.com/artifacts/com.yo1000/fake-keycloak-spring-security-adapter/ -->
<dependency>
    <groupId>com.yo1000</groupId>
    <artifactId>fake-keycloak-spring-security-adapter</artifactId>
    <version>2.0.0-keycloak-4.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.yo1000/fake-keycloak-spring-security-adapter/
implementation 'com.yo1000:fake-keycloak-spring-security-adapter:2.0.0-keycloak-4.2'
// https://jarcasting.com/artifacts/com.yo1000/fake-keycloak-spring-security-adapter/
implementation ("com.yo1000:fake-keycloak-spring-security-adapter:2.0.0-keycloak-4.2")
'com.yo1000:fake-keycloak-spring-security-adapter:jar:2.0.0-keycloak-4.2'
<dependency org="com.yo1000" name="fake-keycloak-spring-security-adapter" rev="2.0.0-keycloak-4.2">
  <artifact name="fake-keycloak-spring-security-adapter" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.yo1000', module='fake-keycloak-spring-security-adapter', version='2.0.0-keycloak-4.2')
)
libraryDependencies += "com.yo1000" % "fake-keycloak-spring-security-adapter" % "2.0.0-keycloak-4.2"
[com.yo1000/fake-keycloak-spring-security-adapter "2.0.0-keycloak-4.2"]

Dependencies

compile (10)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.2.21
org.jetbrains.kotlin : kotlin-reflect jar 1.2.21
javax.servlet : javax.servlet-api jar 3.1.0
org.springframework : spring-core jar 5.0.8.RELEASE
org.springframework : spring-beans jar
org.springframework.security : spring-security-core jar
org.springframework.security : spring-security-config jar
org.springframework.security : spring-security-web jar
org.keycloak : keycloak-adapter-core jar
org.keycloak : keycloak-spring-boot-2-adapter jar

test (7)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-security jar 2.0.4.RELEASE
org.keycloak : keycloak-spring-boot-starter jar
org.jetbrains.kotlin : kotlin-test-junit jar 1.2.21
junit : junit jar 4.12
org.springframework.boot : spring-boot-starter-test jar 2.0.4.RELEASE
org.springframework.security : spring-security-test jar
org.springframework.boot : spring-boot-starter-web jar 2.0.4.RELEASE

Project Modules

There are no modules declared in this project.

Fake Keycloak Spring Security adapter

Keycloak Spring Security Fake adapter

HOW TO USE

<!-- pom.xml -->
<dependency>
    <groupId>com.yo1000</groupId>
    <artifactId>fake-keycloak-spring-security-adapter</artifactId>
    <version>2.0.0-keycloak-4.2</version>
</dependency>
/* KeycloakConfig.kt */
@Configuration
class FakeKeycloakWebSecurityConfiguration : FakeKeycloakWebSecurityConfigurerAdapter() {
    companion object {
        val TEST_USERNAME = "XXXX-XXXX-XXXX-XXXX"
        val TEST_ROLES = arrayOf("ADMIN", "USER")
    }

    override fun fakeToken(): KeycloakAuthenticationToken {
        TEST_ROLES.map {
            "ROLE_$it"
        }.let {
            return KeycloakAuthenticationToken(
                    SimpleKeycloakAccount(
                            KeycloakPrincipal(TEST_USERNAME, KeycloakSecurityContext()),
                            it.toSet(),
                            RefreshableKeycloakSecurityContext()
                    ),
                    false,
                    it.map { KeycloakRole(it) }
            )
        }
    }

    override fun configure(httpSecurity: HttpSecurity) {
        super.configure(httpSecurity)
        httpSecurity
                .authorizeRequests()
                .antMatchers("/**").hasAnyRole(*TEST_ROLES)
                .anyRequest().permitAll()
    }
}

Versions

Version
2.0.0-keycloak-4.2
1.1.1-keycloak-3.4
1.1.0-keycloak-3.4
1.0.0-keycloak-3.4