Hi Adam,

i'm no JSP expert but since JSP is derived from java i would say a string comparison needs to use the word equals() and not ==. The == would indicate comparison on object level if the argument are objects and not one of the simple type (int, float etc.)

This should probably do the tick:

<c:when test="${attr.value.class.simpleName.equals('String')}">


Regards,

Joachim

On 23.01.2013 17:45, Adam Franco wrote:
I was able to get a work-around operational by testing on the attribute
key, but can anyone shed light on why the following test wouldn't work
in the JSP?

<c:when test="${attr.value.class.simpleName == 'String'}">

When I try this I get a JasperException (stacktrace
<http://community.middlebury.edu/~afranco/notes/attr-value-class-simplename_stacktrace.txt>)
that seems to indicate that the attra.value isn't a string, but rather
an array of characters. Shouldn't the SimplePrinciple be returning typed
attributes? Here's what I'm seeing in SimplePrincipal.getAttributes():
http://community.middlebury.edu/~afranco/notes/SimplePrinciple-attributes.png

Here is the full casServiceValidationSuccess.jsp I'm trying to use, but
is failing:

<%@ page session="false" %><%@ taglib prefix="c"
uri="http://java.sun.com/jsp/jstl/core"; %><%@ taglib
uri="http://java.sun.com/jsp/jstl/functions"; prefix="fn"
%><cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
<cas:authenticationSuccess>
<cas:user>${fn:escapeXml(assertion.chainedAuthentications[fn:length(assertion.chainedAuthentications)-1].principal.id
<http://principal.id>)}</cas:user>
<c:forEach var="auth" items="${assertion.chainedAuthentications}">
<c:forEach var="attr" items="${auth.principal.attributes}" >
<c:choose>
<c:when test="${attr.value.class.simpleName == 'String'}">
<cas:attribute name="${fn:escapeXml(attr.key)}"
value="${fn:escapeXml(attr.value)}"/>
</c:when>
<c:otherwise>
<c:forEach var="attrVal" items="${attr.value}">
<cas:attribute name="${fn:escapeXml(attr.key)}"
value="${fn:escapeXml(attrVal)}"/>
</c:forEach>
</c:otherwise>
</c:choose>
</c:forEach>
</c:forEach>
<c:if test="${not empty pgtIou}">
<cas:proxyGrantingTicket>${pgtIou}</cas:proxyGrantingTicket>
</c:if>
<c:if test="${fn:length(assertion.chainedAuthentications) > 1}">
<cas:proxies>
<c:forEach var="proxy" items="${assertion.chainedAuthentications}"
varStatus="loopStatus" begin="0"
end="${fn:length(assertion.chainedAuthentications)-2}" step="1">
<cas:proxy>${fn:escapeXml(proxy.principal.id
<http://proxy.principal.id>)}</cas:proxy>
</c:forEach>
</cas:proxies>
</c:if>
</cas:authenticationSuccess>
</cas:serviceResponse>

In case there really isn't a way to differentiate the attribute types in
the JSP, I was able to hack around it by testing for certain attribute
keys I know to be multi-valued. It's not elegant, but in case it helps
someone with a similar problem, here it is:

<%@ page session="false" %><%@ taglib prefix="c"
uri="http://java.sun.com/jsp/jstl/core"; %><%@ taglib
uri="http://java.sun.com/jsp/jstl/functions"; prefix="fn"
%><cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
<cas:authenticationSuccess>
<cas:user>${fn:escapeXml(assertion.chainedAuthentications[fn:length(assertion.chainedAuthentications)-1].principal.id
<http://principal.id>)}</cas:user>
<c:forEach var="auth" items="${assertion.chainedAuthentications}">
<c:forEach var="attr" items="${auth.principal.attributes}" >
<c:choose>
<c:when test="${attr.key == 'MemberOf'}">
<c:forEach var="attrVal" items="${attr.value}">
<cas:attribute name="${fn:escapeXml(attr.key)}"
value="${fn:escapeXml(attrVal)}"/>
</c:forEach>
</c:when>
<c:otherwise>
<cas:attribute name="${fn:escapeXml(attr.key)}"
value="${fn:escapeXml(attr.value)}"/>
</c:otherwise>
</c:choose>
</c:forEach>
</c:forEach>
<c:if test="${not empty pgtIou}">
<cas:proxyGrantingTicket>${pgtIou}</cas:proxyGrantingTicket>
</c:if>
<c:if test="${fn:length(assertion.chainedAuthentications) > 1}">
<cas:proxies>
<c:forEach var="proxy" items="${assertion.chainedAuthentications}"
varStatus="loopStatus" begin="0"
end="${fn:length(assertion.chainedAuthentications)-2}" step="1">
<cas:proxy>${fn:escapeXml(proxy.principal.id
<http://proxy.principal.id>)}</cas:proxy>
</c:forEach>
</cas:proxies>
</c:if>
</cas:authenticationSuccess>
</cas:serviceResponse>


Adam

--

Adam Franco
Senior Software Engineer - Web Applications
Library and Information Services
Middlebury College
Middlebury, VT 05753
[email protected] <mailto:[email protected]>
802.443.2244


On Tue, Jan 22, 2013 at 4:11 PM, Franco, Adam S. <[email protected]
<mailto:[email protected]>> wrote:

    Hello all,

    I'm wondering if someone more familiar with JSP might be able to
    help me solve a problem I'm having returning attributes that contain
    commas.

    The DisplayName attribute in my Active Directory is a string that
    happens to be formatted as "Lastname, Firstname MiddleInitial.".
    I've been debugging my CAS server in Eclipse and have verified that
    I'm getting a single value for the attribute that looks like a
    string all the way through SimplePrincipal.getAttributes(). For some
    reason the JSP prints this string as two separate "DisplayName"
    attributes, the first containing just "Lastname" and the second
    containing "Firstname MiddleInitial." rather than a single attribute.

    Some background:

    I'm returning attributes in the CAS 2.0 response with the addition
    of the bold section to my casServiceValidationSuccess.jsp.

    <%@ page session="false" %><%@ taglib prefix="c"
    uri="http://java.sun.com/jsp/jstl/core"; %><%@ taglib
    uri="http://java.sun.com/jsp/jstl/functions"; prefix="fn"
    %><cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
    <cas:authenticationSuccess>
    
<cas:user>${fn:escapeXml(assertion.chainedAuthentications[fn:length(assertion.chainedAuthentications)-1].principal.id
    <http://principal.id><http://principal.id>)}</cas:user>
    <c:forEach var="auth" items="${assertion.chainedAuthentications}">
    <c:forEach var="attr" items="${auth.principal.attributes}" >
    <c:forEach var="attrVal" items="${attr.value}">
    <cas:attribute name="${fn:escapeXml(attr.key)}"
    value="${fn:escapeXml(attrVal)}"/>
    </c:forEach>
    </c:forEach>
    </c:forEach>
    <c:if test="${not empty pgtIou}">
    <cas:proxyGrantingTicket>${pgtIou}</cas:proxyGrantingTicket>
    </c:if>
    <c:if test="${fn:length(assertion.chainedAuthentications) > 1}">
    <cas:proxies>
    <c:forEach var="proxy" items="${assertion.chainedAuthentications}"
    varStatus="loopStatus" begin="0"
    end="${fn:length(assertion.chainedAuthentications)-2}" step="1">
    <cas:proxy>${fn:escapeXml(proxy.principal.id
    <http://proxy.principal.id><http://proxy.principal.id>)}</cas:proxy>
    </c:forEach>
    </cas:proxies>
    </c:if>
    </cas:authenticationSuccess>
    </cas:serviceResponse>

    The inner <c:forEach var="attrVal" items="${attr.value}"> loop was
    added because some attributes (such as "MemberOf") are multi-valued
    collections of strings.

    My problem is that strings that contain commas also get split up
    into multiple attributes. For example, even though my "DisplayName"
    attribute is properly returned as a single 15 character string
    "Franco, Adam S.", it gets split into two separate attributes:

    <cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
    <cas:authenticationSuccess>
    <cas:user>B0F836FCDADFDDFF7A17C02C62CDB227</cas:user>
    <cas:attribute name="Status" value="Staff"/>
    <cas:attribute name="EMail" value="[email protected]
    <mailto:[email protected]><mailto:[email protected]
    <mailto:[email protected]>>"/>
    <cas:attribute name="MemberOf" value="CN=All
    Staff,OU=General,OU=Groups,DC=middlebury,DC=edu"/>
    <cas:attribute name="MemberOf" value="CN=Blog
    Administrators,OU=General,OU=Groups,DC=middlebury,DC=e
             du"/>
    <cas:attribute name="FirstName" value="Adam"/>
    <cas:attribute name="DisplayName" value="Franco"/>
    <cas:attribute name="DisplayName" value=" Adam S."/>
    <cas:attribute name="LastName" value="Franco"/>
    </cas:authenticationSuccess>
    </cas:serviceResponse>

    Can anyone provide insight on how to print multiple attribute
    entries for collections but not for strings that just happen to
    contain a comma?

    Thanks!
    Adam

    --

    Adam Franco
    Senior Software Engineer - Web Applications
    Library and Information Services
    Middlebury College
    Middlebury, VT 05753
    [email protected]
    <mailto:[email protected]><mailto:[email protected]
    <mailto:[email protected]>>
    802.443.2244 <tel:802.443.2244>

    --
    You are currently subscribed to [email protected]
    <mailto:[email protected]> as: [email protected]
    <mailto:[email protected]>
    To unsubscribe, change settings or access archives, see
    http://www.ja-sig.org/wiki/display/JSG/cas-user


--
You are currently subscribed to [email protected] as: 
[email protected]
To unsubscribe, change settings or access archives, see 
http://www.ja-sig.org/wiki/display/JSG/cas-user



--
You are currently subscribed to [email protected] as: 
[email protected]
To unsubscribe, change settings or access archives, see 
http://www.ja-sig.org/wiki/display/JSG/cas-user

Reply via email to