Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ELY-2552] / [ELY-2554] Adjustments to mechanism selection and access the config selector. #1905

Merged
merged 3 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ protected AbstractMechanismAuthenticationFactory(final SecurityDomain securityDo
this.factory = factory;
}

public MechanismConfigurationSelector getMechanismConfigurationSelector() {
return mechanismConfigurationSelector;
}

public SecurityDomain getSecurityDomain() {
return securityDomain;
}
Expand Down Expand Up @@ -72,11 +76,30 @@ public M createMechanism(final String name, final UnaryOperator<F> factoryTransf
*/
protected abstract boolean usesCredentials(String mechName);

/**
* Determine whether the given mechanism name is known to WildFly Elytron.
*
* If it is not known we can't filter it out as we can not rely upon the other methods being able to
* return accurate responses about the mechanisms requirements.
*
* As this is a new method and other implementations may not know to override this has a default
* implementation to match the current behaviour i.e. assume we know about all mechanisms.
*
* @param mechName the mechanism name
* @return {@code true} if the mechanism is known to WildFly Elytron, {@code false} if it is not
*/
protected boolean isKnownMechanism(String mechName) {
return true;
};

public Collection<String> getMechanismNames() {
final Collection<String> names = new LinkedHashSet<>();
top: for (String mechName : getAllSupportedMechNames()) {
// if the mech doesn't need credentials, then we support it for sure
if (! usesCredentials(mechName)) {
// If we don't know about the mech we have to support it as it is likely
// a custom mechanism so our filtering rules will not be correct.
if ((! isKnownMechanism(mechName)) ||
// if the mech doesn't need credentials, then we support it for sure
(! usesCredentials(mechName))) {
names.add(mechName);
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,26 @@ protected boolean usesCredentials(final String mechName) {
}
}

@Override
protected boolean isKnownMechanism(String mechName) {
switch (mechName) {
case HttpConstants.BASIC_NAME:
case HttpConstants.CLIENT_CERT_NAME:
case HttpConstants.DIGEST_NAME:
case HttpConstants.DIGEST_SHA256_NAME:
case HttpConstants.DIGEST_SHA512_256_NAME:
case HttpConstants.EXTERNAL_NAME:
case HttpConstants.FORM_NAME:
case HttpConstants.SPNEGO_NAME:
case HttpConstants.BEARER_TOKEN: {
return true;
}
default: {
return false;
}
}
}

public void shutdownAuthenticationMechanismFactory() {
super.getFactory().shutdown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ protected boolean usesCredentials(final String mechName) {
return SaslMechanismInformation.needsServerCredentials(mechName);
}

@Override
protected boolean isKnownMechanism(String mechName) {
return SaslMechanismInformation.isKnownMechanism(mechName);
}

static final Map<String, String> QUERY_ALL = Collections.singletonMap(WildFlySasl.MECHANISM_QUERY_ALL, "true");

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,26 @@ protected boolean usesCredentials(final String mechName) {
}
}

@Override
protected boolean isKnownMechanism(String mechName) {
switch (mechName) {
case HttpConstants.BASIC_NAME:
case HttpConstants.CLIENT_CERT_NAME:
case HttpConstants.DIGEST_NAME:
case HttpConstants.DIGEST_SHA256_NAME:
case HttpConstants.DIGEST_SHA512_256_NAME:
case HttpConstants.EXTERNAL_NAME:
case HttpConstants.FORM_NAME:
case HttpConstants.SPNEGO_NAME:
case HttpConstants.BEARER_TOKEN: {
return true;
}
default: {
return false;
}
}
}

public void shutdownAuthenticationMechanismFactory() {
super.getFactory().shutdown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ protected boolean usesCredentials(final String mechName) {
return SaslMechanismInformation.needsServerCredentials(mechName);
}

@Override
protected boolean isKnownMechanism(String mechName) {
return SaslMechanismInformation.isKnownMechanism(mechName);
}

static final Map<String, String> QUERY_ALL = Collections.singletonMap(WildFlySasl.MECHANISM_QUERY_ALL, "true");

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,45 @@ private Names() {}
Names.SECURID
);

private static final Set<String> KNOWN_MECHS = nSet(
Names.CRAM_MD5,
Names.DIGEST_MD5,
Names.DIGEST_SHA,
Names.DIGEST_SHA_256,
Names.DIGEST_SHA_384,
Names.DIGEST_SHA_512,
Names.DIGEST_SHA_512_256,
Names.SCRAM_SHA_1,
Names.SCRAM_SHA_1_PLUS,
Names.SCRAM_SHA_256,
Names.SCRAM_SHA_256_PLUS,
Names.SCRAM_SHA_384,
Names.SCRAM_SHA_384_PLUS,
Names.SCRAM_SHA_512,
Names.SCRAM_SHA_512_PLUS,
Names.IEC_ISO_9798_M_DSA_SHA1,
Names.IEC_ISO_9798_M_ECDSA_SHA1,
Names.IEC_ISO_9798_M_RSA_SHA1_ENC,
Names.IEC_ISO_9798_U_DSA_SHA1,
Names.IEC_ISO_9798_U_ECDSA_SHA1,
Names.IEC_ISO_9798_U_RSA_SHA1_ENC,
Names.ANONYMOUS,
Names.EAP_AES128,
Names.EAP_AES128_PLUS,
Names.EXTERNAL,
Names.JBOSS_LOCAL_USER,
Names.OAUTH_10_A,
Names.OAUTHBEARER,
Names.OPENID20,
Names.OTP,
Names.SAML20,
Names.SECURID,
Names.PLAIN,
Names.GS2_KRB5,
Names.GS2_KRB5_PLUS,
Names.GSSAPI
);

/**
* A predicate which is true when the mechanism uses MD5.
*/
Expand Down Expand Up @@ -748,6 +787,18 @@ public static boolean doesNotRequireClientCredentials(final String mechName) {
}
}

/**
* Determine whether a mechanism is known by WildFly Elytron.
*
* If the mechanism is not known the other methods in this class can not be relied upon.
*
* @param mechName the mechanism name
* @return {@code true} if the mechanism is known to WildFly Elytron, {@code false} if it is not known
*/
public static boolean isKnownMechanism(final String mechName) {
return KNOWN_MECHS.contains(mechName);
}

@SafeVarargs
private static <T> Set<T> nSet(T... values) {
return unmodifiableSet(new LinkedHashSet<>(asList(values)));
Expand Down