-->

Login to adfs through openam using java applicatio

2019-07-22 19:24发布

问题:

I have configured adfs as identity provider and openam as service provider but how to test whether login is working fine with adfs throght openam.

Can anyone help me to do login to adfs server through openam using java application.

Thanks,

回答1:

Refer OpenAM and ADFS2 configuration.

The article covers all your questions.

Update:

The way I normally do this is to use the OpenSSO / OpenAM Java Fedlet.

Refer Using Fedlets in Java Web Applications (Chapter 8).

The code (as per the fedlet) to display the contents of the token looks like:

Response samlResp = (Response) map.get(SAML2Constants.RESPONSE); 
Assertion assertion = (Assertion) map.get(SAML2Constants.ASSERTION);
Subject subject = (Subject) map.get(SAML2Constants.SUBJECT);
String entityID = (String) map.get(SAML2Constants.IDPENTITYID);
String spEntityID = (String) map.get(SAML2Constants.SPENTITYID);
NameID nameId = (NameID) map.get(SAML2Constants.NAMEID);
String value = nameId.getValue();
String format = nameId.getFormat();
out.println("<br><br><b>Single Sign-On successful with IDP " 
    + entityID + ".</b>");
out.println("<br><br>");
out.println("<table border=0>");
if (format != null) {
    out.println("<tr>");
    out.println("<td valign=top><b>Name ID format: </b></td>");
    out.println("<td>" + format + "</td>");
    out.println("</tr>");
}
if (value != null) {
    out.println("<tr>");
    out.println("<td valign=top><b>Name ID value: </b></td>");
    out.println("<td>" + value + "</td>");
    out.println("</tr>");
}    
String sessionIndex = (String) map.get(SAML2Constants.SESSION_INDEX);
if (sessionIndex != null) {
    out.println("<tr>");
    out.println("<td valign=top><b>SessionIndex: </b></td>");
    out.println("<td>" + sessionIndex + "</td>");
    out.println("</tr>");
}    

Map attrs = (Map) map.get(SAML2Constants.ATTRIBUTE_MAP);
if (attrs != null) {
    out.println("<tr>");
    out.println("<td valign=top><b>Attributes: </b></td>");
    Iterator iter = attrs.keySet().iterator();
    out.println("<td>");
    while (iter.hasNext()) {
        String attrName = (String) iter.next();
        Set attrVals = (HashSet) attrs.get(attrName);
        if ((attrVals != null) && !attrVals.isEmpty()) {
            Iterator it = attrVals.iterator();
            while (it.hasNext()) {
                out.println(attrName + "=" + it.next() + "<br>");
            }
        }
    }
    out.println("</td>");
    out.println("</tr>");
}
out.println("</table>");