com.memority.citadel.shared.api.im.ExtraAttributeId Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of citadel-api Show documentation
Show all versions of citadel-api Show documentation
This artifact provides the API classes that are necessary to implement general configuration Rules on the Memority IM platform.
/*
* Copyright (c) 2016-2023 Memority. All Rights Reserved.
*
* This file is part of Memority Citadel API , a Memority project.
*
* This file is released under the Memority Public Artifacts End-User License Agreement,
* see
* Unauthorized copying of this file, via any medium is strictly prohibited.
*/
package com.memority.citadel.shared.api.im;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import static java.util.stream.Collectors.toList;
/**
* This enum lists all the attribute identifiers that are reserved for internal Citadel attributes and cannot
* be used to configure custom attributes.
*/
public enum ExtraAttributeId {
PASSWORD_HISTORY(Values.PASSWORD_HISTORY, List.class),
PLAIN_PASSWORD(Values.PLAIN_PASSWORD, String.class),
HASHED_PASSWORD(Values.HASHED_PASSWORD, String.class)
;
public final static class Values {
//FIXME: extra attribute only necessary when initializing snapshot object with a mobject.
@SuppressWarnings("squid:S2068") // password field name, not value
public final static String PASSWORD_HISTORY = "passwordHistory";
@SuppressWarnings("squid:S2068") // password field name, not value
public final static String PLAIN_PASSWORD = "plainPassword";
@SuppressWarnings("squid:S2068") // password field name, not value
public final static String HASHED_PASSWORD = "hashedPassword";
}
private final static List ID_LIST = Arrays.stream(ExtraAttributeId.values())
.map(ExtraAttributeId::toId)
.collect(toList());
private final Class valueType;
private final String idValue;
ExtraAttributeId(String idValue, Class valueType) {
this.idValue = idValue;
this.valueType = valueType;
}
public Class getValueType() {
return valueType;
}
public String toId() {
return this.idValue;
}
public static boolean contains(String id) {
return ID_LIST.contains(id);
}
public static List getIdList() {
return ID_LIST;
}
public static ExtraAttributeId fromId(String id) {
return fromIdOptional(id)
.orElseThrow(() -> new IllegalArgumentException("Unrecognized extra attribute id '"+id+"'!"));
}
public static Optional fromIdOptional(String id) {
if (id == null || id.isEmpty()) {
return Optional.empty();
}
for (ExtraAttributeId builtinAttributeId: ExtraAttributeId.values()) {
if (builtinAttributeId.toId().equals(id)) {
return Optional.of(builtinAttributeId);
}
}
return Optional.empty();
}
}