-- LuisRodriguez - 19-Jan-2012

Current implementation of CernWlsPrincipalMapper

package ch.cern.sso.weblogic.mappers;

import java.security.Principal;
import java.util.ArrayList;
import java.util.Collection;
import weblogic.security.service.ContextHandler;
import ch.cern.sso.weblogic.mappers.attributes.Attribute;
import ch.cern.sso.weblogic.principals.CernWlsPrincipal;
import com.bea.security.saml2.providers.SAML2AttributeInfo;
import com.bea.security.saml2.providers.SAML2AttributeStatementInfo;
import com.bea.security.saml2.providers.SAML2IdentityAsserterAttributeMapper;
import com.bea.security.saml2.providers.SAML2IdentityAsserterNameMapper;
import com.bea.security.saml2.providers.SAML2NameMapperInfo;

public class CernWlsPrincipalMapper implements
      SAML2IdentityAsserterAttributeMapper, SAML2IdentityAsserterNameMapper {

   public CernWlsPrincipalMapper() {
      super();
   }

   @Override
   public Collection<Principal> mapAttributeInfo(
         Collection<SAML2AttributeStatementInfo> attrStmtInfos,
         ContextHandler contextHandler) {

      if (attrStmtInfos == null || attrStmtInfos.size() == 0) {
         return null;
      }

      Collection<Principal> principals = new ArrayList<Principal>();

      CernWlsPrincipal cernWlsPrincipal = new CernWlsPrincipal();

      for (SAML2AttributeStatementInfo stmtInfo : attrStmtInfos) {
         Collection<SAML2AttributeInfo> attrs = stmtInfo.getAttributeInfo();
         if (attrs == null || attrs.size() == 0) {
            System.out
                  .println(this.getClass().getCanonicalName()
                        + ": no attribute in statement: "
                        + stmtInfo.toString());
         } else {
            for (SAML2AttributeInfo attr : attrs) {
               for (Attribute attribute : Attribute.values()) {
                  if (attr.getAttributeName().equals(attribute.getName())) {
                     if(attr.getAttributeValues().size()>1){
                        attribute.setValue(cernWlsPrincipal, attr
                              .getAttributeValues());
                     } else {
                        attribute.setValue(cernWlsPrincipal, attr
                              .getAttributeValues().iterator().next());
                     }
                     break;
                  }
               }
            }
         }
      }

      principals.add(cernWlsPrincipal);

      return principals;
   }

   @Override
   public String mapNameInfo(SAML2NameMapperInfo mapperInfo,
         ContextHandler contextHandler) {
      return mapperInfo.getName();
   }
}
Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r2 - 2012-02-09 - LuisRodriguez
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    DB All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2023 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
or Ideas, requests, problems regarding TWiki? use Discourse or Send feedback