Changeset 5523


Ignore:
Timestamp:
08/05/14 15:41:36 (10 years ago)
Author:
Twan Goosen
Message:

Added reading of shibboleth attributes for display name, organisation and e-mail. Also added these properties to the shhaa filter.
Principal is now dynamically retrieved from the http request.
Refs #595

Location:
VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/gui/ApplicationSession.java

    r5522 r5523  
    66import java.security.Principal;
    77import java.util.regex.Pattern;
    8 import org.apache.http.auth.BasicUserPrincipal;
     8import javax.servlet.http.HttpServletRequest;
    99import org.apache.wicket.Request;
     10import org.apache.wicket.RequestCycle;
    1011import org.apache.wicket.authentication.AuthenticatedWebSession;
    1112import org.apache.wicket.authorization.strategies.role.Roles;
     13import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
    1214import org.slf4j.Logger;
    1315import org.slf4j.LoggerFactory;
     
    6365
    6466    public Principal getPrincipal() {
    65         return new BasicUserPrincipal(getUser());
     67        ServletWebRequest servletWebRequest = (ServletWebRequest) RequestCycle.get().getRequest();
     68        HttpServletRequest request = servletWebRequest.getHttpServletRequest();
     69        return request.getUserPrincipal();
    6670    }
    6771
  • VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/java/eu/clarin/cmdi/virtualcollectionregistry/service/impl/SAMLCreatorProvider.java

    r5522 r5523  
    66import eu.clarin.cmdi.virtualcollectionregistry.service.CreatorProvider;
    77import java.security.Principal;
     8import org.slf4j.Logger;
     9import org.slf4j.LoggerFactory;
    810
    911/**
     
    1315public class SAMLCreatorProvider implements CreatorProvider {
    1416
     17    private final static Logger logger = LoggerFactory.getLogger(SAMLCreatorProvider.class);
     18    public static final String[] DISPLAY_NAME_ATTRIBUTE = new String[]{"cn", "commonName", "displayName"};
     19    public static final String[] ORGANISATION_ATTRIBUTE = new String[]{"o", "organizationName", "schacHomeOrganization"};
     20    public static final String[] MAIL_ATTRIBUTE = new String[]{"mail"};
     21
    1522    @Override
    1623    public Creator getCreator(Principal userPrincipal) {
    17         final Creator creator = new Creator();       
     24        final Creator creator = new Creator();
    1825        if (userPrincipal instanceof AuthPrincipal) {
    1926            final AuthPrincipal principal = (AuthPrincipal) userPrincipal;
    20             creator.setPerson(getAttribute(principal, "cn")); //TODO: configure more properties
    21         } else {
     27            creator.setPerson(getAttribute(principal, DISPLAY_NAME_ATTRIBUTE));
     28            creator.setOrganisation(getAttribute(principal, ORGANISATION_ATTRIBUTE));
     29            creator.setEMail(getAttribute(principal, MAIL_ATTRIBUTE));
     30        }
     31
     32        if (creator.getPerson() == null) {
    2233            creator.setPerson(userPrincipal.getName());
    2334        }
     
    2637    }
    2738
    28     private static String getAttribute(final AuthPrincipal principal, String attr) {
    29 //        logger.trace("Looking for attribute {}", attr);
    30         final AuthAttribute<?> attribute = principal.getAttribues().get(attr);
    31         if (attribute != null) {
     39    private static String getAttribute(final AuthPrincipal principal, String[] attrs) {
     40        for (String attr : attrs) {
     41            final String value = getAttributeValue(principal, attr);
     42            if (value != null) {
     43                return value;
     44            }
     45        }
     46        return null;
     47    }
     48
     49    private static String getAttributeValue(final AuthPrincipal principal, String attr) {
     50        logger.trace("Looking for attribute {}", attr);
     51        final AuthAttribute<?> attribute = principal.getAttribues().get(attr);
     52       if (attribute != null) {
    3253            final Object value = attribute.getValue();
    3354            if (value != null) {
    34 //                logger.trace("Found attribute value: {} = {}", attr, value);
     55                logger.trace("Found attribute value: {} = {}", attr, value);
    3556                return value.toString();
    3657            }
  • VirtualCollectionRegistry/trunk/VirtualCollectionRegistry/src/main/webapp/WEB-INF/shhaa.xml

    r5416 r5523  
    3232        <composition action="rF">
    3333            <shibheader>
     34                <attribute>cn</attribute>
     35                <attribute>commonName</attribute>
    3436                <attribute>displayName</attribute>
    35                 <attribute>commonName</attribute>
     37               
     38                <attribute>mail</attribute>
     39               
     40                <attribute>o</attribute>               
     41                <attribute>organizationName</attribute>
     42                <attribute>schacHomeOrganization</attribute>
     43               
    3644            </shibheader>
    3745        </composition>
Note: See TracChangeset for help on using the changeset viewer.