+ * Please note that custom authentication preferences, if used, need to be updated accordingly + * for the new {@link AuthScheme authentication scheme} to take effect. + *
+ * + * @param name the identifier for this scheme + * @param factory the {@link AuthSchemeFactory} class to register + * + * @see #getAuthScheme + */ + public void register( + final String name, + final AuthSchemeFactory factory) { + if (name == null) { + throw new IllegalArgumentException("Name may not be null"); + } + if (factory == null) { + throw new IllegalArgumentException("Authentication scheme factory may not be null"); + } + registeredSchemes.put(name.toLowerCase(Locale.ENGLISH), factory); + } + + /** + * Unregisters the class implementing an {@link AuthScheme authentication scheme} with + * the given name. + * + * @param name the identifier of the class to unregister + */ + public void unregister(final String name) { + if (name == null) { + throw new IllegalArgumentException("Name may not be null"); + } + registeredSchemes.remove(name.toLowerCase(Locale.ENGLISH)); + } + + /** + * Gets the {@link AuthScheme authentication scheme} with the given name. + * + * @param name the {@link AuthScheme authentication scheme} identifier + * @param params the {@link HttpParams HTTP parameters} for the authentication + * scheme. + * + * @return {@link AuthScheme authentication scheme} + * + * @throws IllegalStateException if a scheme with the given name cannot be found + */ + public AuthScheme getAuthScheme(final String name, final HttpParams params) + throws IllegalStateException { + + if (name == null) { + throw new IllegalArgumentException("Name may not be null"); + } + AuthSchemeFactory factory = registeredSchemes.get(name.toLowerCase(Locale.ENGLISH)); + if (factory != null) { + return factory.newInstance(params); + } else { + throw new IllegalStateException("Unsupported authentication scheme: " + name); + } + } + + /** + * Obtains a list containing the names of all registered {@link AuthScheme authentication + * schemes} + * + * @return list of registered scheme names + */ + public List