-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1860 from petrberan/ELY-489
[ELY-489] Add JavaDoc for the 'org.wildfly.security.mechanism' package and sub packages
- Loading branch information
Showing
22 changed files
with
807 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
import org.wildfly.common.bytes.ByteStringBuilder; | ||
|
||
/** | ||
* Utility class used to convert string to quoted strings | ||
* Utility class used to convert string to quoted strings. | ||
* | ||
* @author <a href="mailto:[email protected]">Peter Skopek</a> | ||
* | ||
|
@@ -33,6 +33,12 @@ public class DigestQuote { | |
private DigestQuote() { | ||
} | ||
|
||
/** | ||
* Checks if a given character needs to be quoted. | ||
* | ||
* @param ch the character to check. | ||
* @return {@code true} if the character needs to be quoted, {@code false} otherwise. | ||
*/ | ||
private static boolean quoteNeeded(char ch) { | ||
return | ||
ch == '"' || // escape char | ||
|
@@ -46,8 +52,8 @@ private static boolean quoteNeeded(char ch) { | |
/** | ||
* Creates new String quoted by SASL rules. | ||
* | ||
* @param inputStr String to be quoted | ||
* @return | ||
* @param inputStr String to be quoted. | ||
* @return new String with quoted characters. | ||
*/ | ||
public static String quote(String inputStr) { | ||
int len = inputStr.length(); | ||
|
@@ -64,6 +70,12 @@ public static String quote(String inputStr) { | |
return sb.toString(); | ||
} | ||
|
||
/** | ||
* Creates new Array quoted by SASL rules. | ||
* | ||
* @param input Byte array to be quoted. | ||
* @return new byte array with quoted bytes. | ||
*/ | ||
public static byte[] quote(byte[] input) { | ||
ByteStringBuilder bsb = new ByteStringBuilder(); | ||
for (int i = 0; i < input.length; i++) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ | |
import static org.wildfly.security.mechanism.digest.DigestUtil.userRealmPasswordDigest; | ||
|
||
/** | ||
* Utility class used to obtain username+realm+password using SASL/HTTP mechanism callbacks | ||
* Utility class used to obtain username+realm+password using SASL/HTTP mechanism callbacks. | ||
* | ||
* @author <a href="mailto:[email protected]">Jan Kalina</a> | ||
*/ | ||
|
@@ -67,6 +67,20 @@ public class PasswordDigestObtainer { | |
private RealmCallback realmCallback; | ||
private NameCallback nameCallback; | ||
|
||
/** | ||
* Constructs a new {@code PasswordDigestObtainer} instance. | ||
* | ||
* @param callbackHandler the callbackHandler to handle the callbacks required to obtain the username and password. | ||
* @param defaultUsername the default username to use if a callback is not provided. | ||
* @param defaultRealm the default realm to use if a callback is not provided. | ||
* @param log the logger to use. | ||
* @param credentialAlgorithm the name of the algorithm for obtaining the credential. | ||
* @param messageDigest the {@link MessageDigest} used for digesting the password. | ||
* @param passwordFactoryProviders the supplier of the providers to use when creating a {@code PasswordFactory} instance. | ||
* @param realms the realms to check for a user and password. | ||
* @param readOnlyRealmUsername {@code true} if the username passed in the callback can be modified, {@code false} otherwise. | ||
* @param skipRealmCallbacks {@code true} if realm callbacks should be skipped, {@code false} otherwise. | ||
*/ | ||
public PasswordDigestObtainer(CallbackHandler callbackHandler, String defaultUsername, String defaultRealm, | ||
ElytronMessages log, String credentialAlgorithm, MessageDigest messageDigest, | ||
Supplier<Provider[]> passwordFactoryProviders, String[] realms, | ||
|
@@ -83,14 +97,30 @@ public PasswordDigestObtainer(CallbackHandler callbackHandler, String defaultUse | |
this.skipRealmCallbacks = skipRealmCallbacks; | ||
} | ||
|
||
/** | ||
* Returns the username obtained from callback or the default one. | ||
* | ||
* @return the username obtained from callback or the default one. | ||
*/ | ||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
/** | ||
* Returns the realm obtained from callback or the default one. | ||
* | ||
* @return the realm obtained from callback or the default one. | ||
*/ | ||
public String getRealm() { | ||
return realm; | ||
} | ||
|
||
/** | ||
* Handles callbacks for user and password information. | ||
* | ||
* @return the salted password. | ||
* @throws AuthenticationMechanismException if the callback handler does not support credential acquisition. | ||
*/ | ||
public byte[] handleUserRealmPasswordCallbacks() throws AuthenticationMechanismException { | ||
|
||
realmChoiceCallBack = skipRealmCallbacks || realms == null || realms.length <= 1 ? null : | ||
|
@@ -115,6 +145,12 @@ public byte[] handleUserRealmPasswordCallbacks() throws AuthenticationMechanismE | |
throw log.mechCallbackHandlerDoesNotSupportCredentialAcquisition(null); | ||
} | ||
|
||
/** | ||
* Obtains the pre-digested salted password for the {@code username} in the {@code realm}. | ||
* | ||
* @return the pre-digested salted password if obtained, {@code null} otherwise. | ||
* @throws AuthenticationMechanismException if an exception occurs while handling the callbacks. | ||
*/ | ||
private byte[] getPredigestedSaltedPassword() throws AuthenticationMechanismException { | ||
if (realmChoiceCallBack != null) { | ||
try { | ||
|
@@ -180,6 +216,12 @@ private byte[] getPredigestedSaltedPassword() throws AuthenticationMechanismExce | |
return null; | ||
} | ||
|
||
/** | ||
* Obtains the salted password from a two-way callback. | ||
* | ||
* @return the byte array of the salted password if obtained, {@code null} otherwise. | ||
* @throws AuthenticationMechanismException if an error occurs during the process of handling callbacks or obtaining the password. | ||
*/ | ||
private byte[] getSaltedPasswordFromTwoWay() throws AuthenticationMechanismException { | ||
if (realmChoiceCallBack != null) { | ||
try { | ||
|
@@ -253,6 +295,12 @@ private byte[] getSaltedPasswordFromTwoWay() throws AuthenticationMechanismExcep | |
return null; | ||
} | ||
|
||
/** | ||
* Obtains the salted password from a password callback. | ||
* | ||
* @return the byte array of the salted password. | ||
* @throws AuthenticationMechanismException if an error occurs during the process of handling callbacks or obtaining the password. | ||
*/ | ||
private byte[] getSaltedPasswordFromPasswordCallback() throws AuthenticationMechanismException { | ||
PasswordCallback passwordCallback = new PasswordCallback("User password: ", false); | ||
|
||
|
Oops, something went wrong.