[java-identity-provider] branch main updated: Add HTTP method override to CLI.
Scott Cantor
cantor.2 at osu.edu
Mon Mar 21 18:01:26 UTC 2022
This is an automated email from the git hooks/post-receive script.
scantor pushed a commit to branch main
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=31a3ed7577b7aeb5b44ea1993768cf7bc49d7d07
The following commit(s) were added to refs/heads/main by this push:
new 31a3ed757 Add HTTP method override to CLI.
31a3ed757 is described below
commit 31a3ed7577b7aeb5b44ea1993768cf7bc49d7d07
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Mar 21 14:01:22 2022 -0400
Add HTTP method override to CLI.
---
.../idp/cli/AbstractCommandLineArguments.java | 17 ++++++++++++++++-
idp-core/src/main/java/net/shibboleth/idp/cli/CLI.java | 10 +++++++---
.../net/shibboleth/idp/cli/CommandLineArguments.java | 14 +++++++++++++-
3 files changed, 36 insertions(+), 5 deletions(-)
diff --git a/idp-core/src/main/java/net/shibboleth/idp/cli/AbstractCommandLineArguments.java b/idp-core/src/main/java/net/shibboleth/idp/cli/AbstractCommandLineArguments.java
index 4d2061438..29cec69b5 100644
--- a/idp-core/src/main/java/net/shibboleth/idp/cli/AbstractCommandLineArguments.java
+++ b/idp-core/src/main/java/net/shibboleth/idp/cli/AbstractCommandLineArguments.java
@@ -89,6 +89,10 @@ public abstract class AbstractCommandLineArguments implements CommandLineArgumen
description = "Password to be used in HTTP-Basic Auth")
@Nullable private String password;
+ /** HTTP method to use, GET by default. */
+ @Parameter(names = {"--method"}, required = false, description = "")
+ @Nullable @NotEmpty private String method;
+
/** HTTP header name/value pair(s). */
@Parameter(names = {"--header"}, required = false, arity = 2, description = "HTTP header name and value")
@Nullable private List<String> headers;
@@ -188,6 +192,17 @@ public abstract class AbstractCommandLineArguments implements CommandLineArgumen
return password;
}
+ /**
+ * Value of "method" parameter.
+ *
+ * @return method
+ *
+ * @since 4.2.0
+ */
+ @Nullable @NotEmpty public String getMethod() {
+ return StringSupport.trimOrNull(method);
+ }
+
/** {@inheritDoc} */
@Nullable @NonnullElements @NotLive @Unmodifiable public Map<String,String> getHeaders() {
if (headers != null) {
@@ -262,7 +277,7 @@ public abstract class AbstractCommandLineArguments implements CommandLineArgumen
}
/** {@inheritDoc} */
- @Nullable public String getBasicAuthHeader() {
+ @Nullable @NotEmpty public String getBasicAuthHeader() {
if (StringSupport.trimOrNull(username) == null || StringSupport.trimOrNull(password) == null) {
return null;
}
diff --git a/idp-core/src/main/java/net/shibboleth/idp/cli/CLI.java b/idp-core/src/main/java/net/shibboleth/idp/cli/CLI.java
index 3b76b49ba..4dc3643b9 100644
--- a/idp-core/src/main/java/net/shibboleth/idp/cli/CLI.java
+++ b/idp-core/src/main/java/net/shibboleth/idp/cli/CLI.java
@@ -24,9 +24,8 @@ import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
+import java.net.ProtocolException;
import java.net.URL;
-import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import javax.annotation.Nonnull;
@@ -106,6 +105,11 @@ public final class CLI {
try {
url = args.buildURL();
final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+
+ if (args.getMethod() != null) {
+ connection.setRequestMethod(args.getMethod());
+ }
+
final String authorization = args.getBasicAuthHeader();
if (authorization != null) {
connection.setRequestProperty("Authorization", authorization);
@@ -128,7 +132,7 @@ public final class CLI {
}
}
}
- } catch (final MalformedURLException e) {
+ } catch (final MalformedURLException|ProtocolException e) {
errorAndExit(e.getMessage());
} catch (final IOException e) {
errorAndExit((url != null ? "(" + url.toString() + ") " : "") + e.getMessage());
diff --git a/idp-core/src/main/java/net/shibboleth/idp/cli/CommandLineArguments.java b/idp-core/src/main/java/net/shibboleth/idp/cli/CommandLineArguments.java
index fa8e31c39..1bff221f0 100644
--- a/idp-core/src/main/java/net/shibboleth/idp/cli/CommandLineArguments.java
+++ b/idp-core/src/main/java/net/shibboleth/idp/cli/CommandLineArguments.java
@@ -25,6 +25,7 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
import net.shibboleth.utilities.java.support.annotation.constraint.NotLive;
import net.shibboleth.utilities.java.support.annotation.constraint.Unmodifiable;
@@ -63,7 +64,7 @@ public interface CommandLineArguments {
*
* @since 4.2.0
*/
- @Nullable public default String getBasicAuthHeader() {
+ @Nullable @NotEmpty public default String getBasicAuthHeader() {
return null;
}
@@ -77,5 +78,16 @@ public interface CommandLineArguments {
@Nullable @NonnullElements @NotLive @Unmodifiable public default Map<String,String> getHeaders() {
return null;
}
+
+ /**
+ * Value of method parameter.
+ *
+ * @return HTTP method
+ *
+ * @since 4.2.0
+ */
+ @Nullable @NotEmpty public default String getMethod() {
+ return null;
+ }
}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list