All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.canoo.dp.impl.server.security.UserKeycloakImpl Maven / Gradle / Ivy

Go to download

The Dolphin Platform is a framework that implements the presentation model pattern and provides amodern way to create enterprise applications. The Platform provides several client implementations that all canbe used in combination with a general sever API.

There is a newer version: 1.0.0.CR5
Show newest version
package com.canoo.dp.impl.server.security;

import com.canoo.dp.impl.platform.core.Assert;
import com.canoo.platform.server.security.User;
import org.keycloak.KeycloakSecurityContext;

import java.util.stream.Stream;

public class UserKeycloakImpl implements User {

    private final KeycloakSecurityContext keycloakSecurityContext;

    public UserKeycloakImpl(KeycloakSecurityContext keycloakSecurityContext) {
        this.keycloakSecurityContext = Assert.requireNonNull(keycloakSecurityContext, "keycloakSecurityContext");
    }

    @Override
    public Stream getRoles() {
        return keycloakSecurityContext.getToken().getRealmAccess().getRoles().stream();
    }

    @Override
    public String getEmail() {
        return keycloakSecurityContext.getToken().getEmail();
    }

    @Override
    public String getUserName() {
        return keycloakSecurityContext.getToken().getPreferredUsername();
    }

    @Override
    public String getFirstName() {
        return keycloakSecurityContext.getToken().getGivenName();
    }

    @Override
    public String getLastName() {
        return keycloakSecurityContext.getToken().getFamilyName();
    }

    @Override
    public String toString() {
        return "User " + getUserName() + " [first name:" + getFirstName() + ", last name:" + getLastName() + ", mail:" + getEmail() + "] Roles:" + getRoles().reduce("", (a,b) -> a+ ", " +b);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy