com.onegini.sdk.saml.ManageableAttribute Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of idp-sdk Show documentation
Show all versions of idp-sdk Show documentation
Java SDK to connect to the Onegini platform
/*
* 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.saml;
import static com.google.common.collect.Maps.newHashMap;
import static com.onegini.sdk.model.SamlAttributes.CITY;
import static com.onegini.sdk.model.SamlAttributes.COUNTRY;
import static com.onegini.sdk.model.SamlAttributes.DATE_OF_BIRTH;
import static com.onegini.sdk.model.SamlAttributes.DISPLAY_NAME;
import static com.onegini.sdk.model.SamlAttributes.GIVEN_NAME;
import static com.onegini.sdk.model.SamlAttributes.HOUSE_NUMBER;
import static com.onegini.sdk.model.SamlAttributes.HOUSE_NUMBER_ADDITION;
import static com.onegini.sdk.model.SamlAttributes.INITIALS;
import static com.onegini.sdk.model.SamlAttributes.POSTAL_ADDRESS;
import static com.onegini.sdk.model.SamlAttributes.POSTAL_CODE;
import static com.onegini.sdk.model.SamlAttributes.PREFERRED_LANGUAGE;
import static com.onegini.sdk.model.SamlAttributes.SN;
import static com.onegini.sdk.model.SamlAttributes.STATE_OR_PROVINCE;
import static com.onegini.sdk.model.SamlAttributes.STREET_ADDRESS;
import static com.onegini.sdk.model.SamlAttributes.TELEPHONE_NUMBER;
import static java.util.Arrays.stream;
import static java.util.Locale.ENGLISH;
import static java.util.Optional.empty;
import static java.util.Optional.of;
import static java.util.Optional.ofNullable;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.commons.lang3.EnumUtils;
import com.onegini.sdk.model.AttributeTypes;
import com.onegini.sdk.model.SamlAttributes;
public enum ManageableAttribute {
UID(SamlAttributes.UID),
NAME(AttributeTypes.NAME, SN, GIVEN_NAME, INITIALS, DISPLAY_NAME),
GENDER(AttributeTypes.GENDER, SamlAttributes.GENDER),
EMAIL(AttributeTypes.EMAIL, SamlAttributes.EMAIL),
PHONE(AttributeTypes.PHONE, TELEPHONE_NUMBER),
ADDRESS(AttributeTypes.ADDRESS, STREET_ADDRESS, CITY, STATE_OR_PROVINCE, POSTAL_CODE, COUNTRY, POSTAL_ADDRESS, HOUSE_NUMBER, HOUSE_NUMBER_ADDITION),
ADDRESS_ALT(AttributeTypes.ADDRESS_ALT),
BIRTH_DATE(AttributeTypes.BIRTH_DATE, DATE_OF_BIRTH),
PREFERRED_LOCALE(AttributeTypes.PREFERRED_LOCALE, PREFERRED_LANGUAGE),
CUSTOM_ATTRIBUTES(AttributeTypes.CUSTOM_ATTRIBUTES),
AUTHENTICATION_LEVEL(SamlAttributes.AUTHENTICATION_LEVEL),
PREVIOUS_SUCCESSFUL_AUTHENTICATION_ATTEMPT(SamlAttributes.PREVIOUS_SUCCESSFUL_AUTHENTICATION_ATTEMPT);
private static final Map SAML_ATTRIBUTES_MAP = createSamlAttributesMap();
private final AttributeTypes profileAttribute;
private final List samlAttributes;
ManageableAttribute(final SamlAttributes... samlAttributes) {
this.profileAttribute = null;
this.samlAttributes = Arrays.asList(samlAttributes);
}
ManageableAttribute(final AttributeTypes profileAttribute, final SamlAttributes... samlAttributes) {
this.profileAttribute = profileAttribute;
this.samlAttributes = Arrays.asList(samlAttributes);
}
public AttributeTypes getProfileAttribute() {
return profileAttribute;
}
private static Map createSamlAttributesMap() {
final Map map = newHashMap();
stream(values())
.forEach(attribute -> attribute.getSamlAttributes()
.forEach(a -> map.put(a, attribute)));
return map;
}
public List getSamlAttributes() {
return samlAttributes;
}
public boolean isRelatedToProfileAttribute() {
return profileAttribute != null;
}
public boolean isRelatedToSamlAttributes() {
return samlAttributes != null && !samlAttributes.isEmpty();
}
public boolean isExtendedFieldsApplicable() {
return this == ADDRESS || this == ADDRESS_ALT;
}
public static Optional fromString(final String name) {
if (EnumUtils.getEnumIgnoreCase(ManageableAttribute.class, name) != null) {
return of(Enum.valueOf(ManageableAttribute.class, name.toUpperCase(ENGLISH)));
} else {
return empty();
}
}
public static Optional getForSamlAttribute(final SamlAttributes samlAttribute) {
return ofNullable(SAML_ATTRIBUTES_MAP.getOrDefault(samlAttribute, null));
}
}