<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %> <%@ page import="org.keycloak.KeycloakSecurityContext" %> <%@ page import="org.keycloak.common.util.KeycloakUriBuilder" %> <%@ page import="org.keycloak.constants.ServiceUrlConstants" %> <%@ page import="org.keycloak.representations.AccessToken" %> <%@ page import="org.keycloak.representations.AccessToken.Access" %> <%@ page import="org.keycloak.representations.IDToken" %> <%@ page import="java.util.Map" %> <%@ page session="false" %> LDAP Example

LDAP Example


<% String logoutUri = KeycloakUriBuilder.fromUri("/auth").path(ServiceUrlConstants.TOKEN_SERVICE_LOGOUT_PATH) .queryParam("redirect_uri", "/ldap-portal").build("ldap-demo").toString(); KeycloakSecurityContext securityContext = (KeycloakSecurityContext) request.getAttribute(KeycloakSecurityContext.class.getName()); IDToken idToken = securityContext.getIdToken(); AccessToken accessToken = securityContext.getToken(); %> Logout

ID Token - basic claims

Username: <%=idToken.getPreferredUsername()%>

Email: <%=idToken.getEmail()%>

Full Name: <%=idToken.getName()%>

First: <%=idToken.getGivenName()%>

Last: <%=idToken.getFamilyName()%>


ID Token - other claims

<% for (Map.Entry claim : idToken.getOtherClaims().entrySet()) { %>

<%= claim.getKey() %>: <%= claim.getValue().toString() %> <% } %>


Access Token - roles

Realm roles: <%= accessToken.getRealmAccess().getRoles().toString() %>

<% for (Map.Entry acc : accessToken.getResourceAccess().entrySet()) { %>

Resource: <%= acc.getKey() %>, Roles: <%= acc.getValue().getRoles().toString() %>

<% } %>