コード例 #1
0
  /**
   * Returns the attribute value configured in the given entity SP or IDP configuration.
   *
   * @param realm realm name.
   * @param entityID hosted <code>EntityID</code>.
   * @param attributeName name of the attribute.
   */
  protected String getAttribute(String realm, String entityID, String attributeName) {

    if (realm == null || entityID == null || attributeName == null) {
      if (debug.messageEnabled()) {
        debug.message("DefaultAccountMapper.getAttribute: " + "null input parameters.");
      }
      return null;
    }

    try {
      BaseConfigType config = null;
      if (role.equals(IDP)) {
        config = WSFederationUtils.getMetaManager().getIDPSSOConfig(realm, entityID);
      } else {
        config = WSFederationUtils.getMetaManager().getSPSSOConfig(realm, entityID);
      }
      Map attributes = WSFederationMetaUtils.getAttributes(config);

      if (attributes == null || attributes.isEmpty()) {
        if (debug.messageEnabled()) {
          debug.message(
              "DefaultAccountMapper.getAttribute:"
                  + " attribute configuration is not defined for "
                  + "Entity "
                  + entityID
                  + " realm ="
                  + realm
                  + " role="
                  + role);
        }
        return null;
      }

      List list = (List) attributes.get(attributeName);
      if (list != null && list.size() > 0) {
        return (String) list.iterator().next();
      }

      if (debug.messageEnabled()) {
        debug.message(
            "DefaultSPAccountMapper.getAttribute: " + attributeName + " is not configured.");
      }
      return null;

    } catch (WSFederationMetaException sme) {
      if (debug.warningEnabled()) {
        debug.warning("DefaultSPAccountMapper.getAttribute:" + "Meta Exception", sme);
      }
    }
    return null;
  }
コード例 #2
0
  public void process() throws WSFederationException, IOException {
    String classMethod = "MetadataRequest.process: ";

    String realm = "/";
    String entityId = null;

    int prefixLength =
        (request.getContextPath() + WSFederationConstants.METADATA_URL_PREFIX).length();
    String suffix = request.getRequestURI().substring(prefixLength);

    WSFederationMetaManager metaManager = WSFederationUtils.getMetaManager();
    if (suffix.equals(WSFederationConstants.METADATA_URL_SUFFIX)) {
      // No entity ID in request - return first defined
      List providers = metaManager.getAllHostedEntities(null);

      if ((providers != null) && !providers.isEmpty()) {
        entityId = (String) providers.iterator().next();
      } else {
        throw new WSFederationException(WSFederationUtils.bundle.getString("noHostedEntities"));
      }
    } else {
      // Request URL is of the form METADATA_URL_PREFIX + metaalias +
      // + METADATA_URL_SUFFIX
      // e.g. /FederationMetadata/2006-12/red/idp/FederationMetadata.xml
      int metaAliasLength = suffix.length() - WSFederationConstants.METADATA_URL_SUFFIX.length();
      String metaAlias = suffix.substring(0, metaAliasLength);

      realm = SAML2MetaUtils.getRealmByMetaAlias(metaAlias);

      entityId = metaManager.getEntityByMetaAlias(metaAlias);

      if (entityId == null || entityId.length() == 0) {
        String[] args = {metaAlias, realm};
        throw new WSFederationException(
            WSFederationConstants.BUNDLE_NAME, "invalidMetaAlias", args);
      }
    }

    FederationElement fedElem = metaManager.getEntityDescriptor(realm, entityId);

    String metaXML = null;
    try {
      metaXML = WSFederationMetaUtils.convertJAXBToString(fedElem);
    } catch (JAXBException ex) {
      throw new WSFederationException(ex);
    }

    response.setContentType("text/xml");
    response.setHeader("Pragma", "no-cache");
    response.getWriter().print(metaXML);
  }