com.canoo.dp.impl.server.security.UserKeycloakImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dolphin-platform-security-server Show documentation
Show all versions of dolphin-platform-security-server Show documentation
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.
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