All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.onegini.sdk.model.SamlAttributes Maven / Gradle / Ivy

There is a newer version: 5.92.0
Show newest version
/*
 * Copyright 2013-2020 Onegini b.v.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.onegini.sdk.model;

import static com.onegini.sdk.saml.SamlConstants.NAME_FORMAT_URI;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;

import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

import com.onegini.sdk.saml.SamlAttributeDefinition;
import lombok.Getter;

/**
 * Enum for SAML Attributes. A SAML Attribute consists of a friendly name and a name. The name attribute is in the
 * form of urn:oid:... These are X.500 attribute types registered under the oid namespace.
 * Additional attributes can be found here:
 * - https://wiki.umn.edu/ShibAuth/AttributeList
 * - http://www.alvestrand.no/objectid/2.5.4.html
 * - http://www.terena.org/activities/tf-emc2/docs/schac/schac-20061017-1.3.0b2.schema.txt
 * Onegini has registered it's own oid namespace with IANA under the following number:
 * - urn:oid:1.3.6.1.4.1.44976
 * Information regarding the submission can be found here:
 * - http://www.iana.org/assignments/enterprise-numbers
 * The registration can be modified here:
 * http://pen.iana.org/pen/PenModification.page
 */
@Getter
public enum SamlAttributes implements SamlAttributeDefinition {
  UID("uid", "urn:oid:0.9.2342.19200300.100.1.1", NAME_FORMAT_URI),
  SN("sn", "urn:oid:2.5.4.4", NAME_FORMAT_URI),
  GIVEN_NAME("givenName", "urn:oid:2.5.4.42", NAME_FORMAT_URI),
  INITIALS("initials", "urn:oid:2.5.4.43", NAME_FORMAT_URI),
  /**
   * @deprecated Use EMAIL instead.
   */
  @Deprecated
  MAIL("mail", "urn:oid:0.9.2342.19200300.100.1.3", NAME_FORMAT_URI),
  TELEPHONE_NUMBER("telephoneNumber", "urn:oid:2.5.4.20", NAME_FORMAT_URI),
  DISPLAY_NAME("displayName", "urn:oid:2.16.840.1.113730.3.1.241", NAME_FORMAT_URI),
  PREFERRED_LANGUAGE("preferredLanguage", "urn:oid:2.16.840.1.113730.3.1.39", NAME_FORMAT_URI),
  STREET_ADDRESS("streetAddress", "urn:oid:2.5.4.9", NAME_FORMAT_URI),
  CITY("localityName", "urn:oid:2.5.4.7", NAME_FORMAT_URI),
  STATE_OR_PROVINCE("stateOrProvinceName", "urn:oid:2.5.4.8", NAME_FORMAT_URI),
  POSTAL_CODE("postalCode", "urn:oid:2.5.4.17", NAME_FORMAT_URI),
  COUNTRY("countryName", "urn:oid:2.5.4.6", NAME_FORMAT_URI),
  POSTAL_ADDRESS("postalAddress", "urn:oid:2.5.4.16", NAME_FORMAT_URI),
  HOUSE_NUMBER("houseNumber", "urn:oid:2.5.4.51", NAME_FORMAT_URI),
  HOUSE_NUMBER_ADDITION("houseNumberAddition", "urn:oid:2.5.4.98", NAME_FORMAT_URI),
  GENDER("schacGender", "urn:oid:1.3.6.1.4.1.1466.115.121.1.27", NAME_FORMAT_URI),
  DATE_OF_BIRTH("schacDateOfBirth", "urn:oid:1.3.6.1.4.1.1466.115.121.1.36", NAME_FORMAT_URI),
  PLACE_OF_BIRTH("schacPlaceOfBirth", "urn:oid:1.3.6.1.4.1.1466.115.121.1.15", NAME_FORMAT_URI),
  NATIONALITY("schacCountryOfCitizenship", "urn:oid:1.3.6.1.4.1.1466.115.121.1.15", NAME_FORMAT_URI),
  CONTACT_METHOD("mailPreferenceOption", "urn:oid:0.9.2342.19200300.100.1.47", NAME_FORMAT_URI),
  AUTHENTICATION_LEVEL("authenticationLevel", "urn:oid:1.3.6.1.4.1.44976.1.1", NAME_FORMAT_URI),
  IDENTITY_ASSURANCE_LEVEL("identityAssuranceLevel", "urn:com:onegini:saml:IdentityAssuranceLevel", NAME_FORMAT_URI),
  PREVIOUS_SUCCESSFUL_AUTHENTICATION_ATTEMPT("previousSuccessfulAuthenticationAttemptTimeMillis", "urn:oid:1.3.6.1.4.1.44976.1.2", NAME_FORMAT_URI),
  EMAIL("email", asList("urn:oid:1.2.840.113549.1.9.1", "1.2.840.113549.1.9.1"), NAME_FORMAT_URI);

  private final String friendlyName;
  private final List names;
  private final String nameFormat;

  SamlAttributes(final String friendlyName, final String name, final String nameFormat) {
    this(friendlyName, singletonList(name), nameFormat);
  }

  SamlAttributes(final String friendlyName, final List names, final String nameFormat) {
    this.friendlyName = friendlyName;
    this.names = names;
    this.nameFormat = nameFormat;
  }

  public String getName() {
    return names.get(0);
  }

  public static Optional byFriendlyName(final String friendlyName) {
    return Stream.of(SamlAttributes.values())
        .filter(attr -> attr.friendlyName.equalsIgnoreCase(friendlyName))
        .findFirst();
  }

  public static Optional getByName(final String name) {
    try {
      return Optional.of(SamlAttributes.valueOf(name));
    } catch (final IllegalArgumentException e) {
      return Optional.empty();
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy