-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KEYCLOAK-1487 Multivalued support for UserAttribute protocol mapper. …
…End-to-end LDAP example test including application
- Loading branch information
Showing
9 changed files
with
216 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...suite/integration/src/test/java/org/keycloak/testsuite/federation/LDAPExampleServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.keycloak.testsuite.federation; | ||
|
||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.keycloak.KeycloakSecurityContext; | ||
import org.keycloak.representations.IDToken; | ||
|
||
/** | ||
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a> | ||
*/ | ||
public class LDAPExampleServlet extends HttpServlet { | ||
|
||
|
||
@Override | ||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { | ||
KeycloakSecurityContext securityContext = (KeycloakSecurityContext) req.getAttribute(KeycloakSecurityContext.class.getName()); | ||
IDToken idToken = securityContext.getIdToken(); | ||
|
||
PrintWriter out = resp.getWriter(); | ||
out.println("<html><head><title>LDAP Portal</title></head><body>"); | ||
out.println("<table border><tr><th>Attribute name</th><th>Attribute values</th></tr>"); | ||
|
||
out.printf("<tr><td>%s</td><td>%s</td></tr>", "preferred_username", idToken.getPreferredUsername()); | ||
out.println(); | ||
out.printf("<tr><td>%s</td><td>%s</td></tr>", "name", idToken.getName()); | ||
out.println(); | ||
out.printf("<tr><td>%s</td><td>%s</td></tr>", "email", idToken.getEmail()); | ||
out.println(); | ||
|
||
for (Map.Entry<String, Object> claim : idToken.getOtherClaims().entrySet()) { | ||
Object value = claim.getValue(); | ||
|
||
if (value instanceof List) { | ||
List<String> asList = (List<String>) value; | ||
StringBuilder result = new StringBuilder(); | ||
for (String item : asList) { | ||
result.append(item + "<br>"); | ||
} | ||
value = result.toString(); | ||
} | ||
|
||
out.printf("<tr><td>%s</td><td>%s</td></tr>", claim.getKey(), value); | ||
out.println(); | ||
} | ||
|
||
out.println("</table></body></html>"); | ||
out.flush(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
testsuite/integration/src/test/resources/ldap/ldap-app-keycloak.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"realm": "test", | ||
"resource": "ldap-portal", | ||
"realm-public-key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCrVrCuTtArbgaZzL1hvh0xtL5mc7o0NqPVnYXkLvgcwiC3BjLGw1tGEGoJaXDuSaRllobm53JBhjx33UNv+5z/UMG4kytBWxheNVKnL6GgqlNabMaFfPLPCF8kAgKnsi79NMo+n6KnSY8YeUmec/p2vjO2NjsSAVcWEQMVhJ31LwIDAQAB", | ||
"auth-server-url": "http://localhost:8081/auth", | ||
"ssl-required" : "external", | ||
"credentials": { | ||
"secret": "password" | ||
} | ||
} |
Oops, something went wrong.