[java-opensaml] branch main updated: Add an entity/regex predicate class.

Scott Cantor cantor.2 at osu.edu
Mon Jan 29 18:48:07 UTC 2024


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch main
in repository java-opensaml.

View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=e2d4dd2ef8f5cfc65985234e3a97a69f65869553

The following commit(s) were added to refs/heads/main by this push:
     new e2d4dd2ef Add an entity/regex predicate class.
e2d4dd2ef is described below

commit e2d4dd2ef8f5cfc65985234e3a97a69f65869553
Author: Scott Cantor <cantor.2 at osu.edu>
AuthorDate: Mon Jan 29 13:48:04 2024 -0500

    Add an entity/regex predicate class.
---
 .../common/profile/logic/EntityRegexPredicate.java | 54 ++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/opensaml-saml-api/src/main/java/org/opensaml/saml/common/profile/logic/EntityRegexPredicate.java b/opensaml-saml-api/src/main/java/org/opensaml/saml/common/profile/logic/EntityRegexPredicate.java
new file mode 100644
index 000000000..4fbbf9337
--- /dev/null
+++ b/opensaml-saml-api/src/main/java/org/opensaml/saml/common/profile/logic/EntityRegexPredicate.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.opensaml.saml.common.profile.logic;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import org.opensaml.saml.saml2.metadata.EntityDescriptor;
+
+import net.shibboleth.shared.annotation.ParameterName;
+import net.shibboleth.shared.logic.Constraint;
+import java.util.function.Predicate;
+import java.util.regex.Pattern;
+
+/**
+ * Predicate that matches {@link EntityDescriptor#getEntityID()} against a regular exression.
+ */
+public class EntityRegexPredicate implements Predicate<EntityDescriptor> {
+    
+    /** Regular expression to test. */
+    @Nonnull private final Pattern pattern;
+    
+    /**
+     * Constructor.
+     * 
+     * @param exp regular expression to check for
+     */
+    public EntityRegexPredicate(@Nonnull @ParameterName(name="exp") final Pattern exp) {
+        pattern = Constraint.isNotNull(exp, "Pattern cannot be null");
+    }
+    
+    /** {@inheritDoc} */
+    public boolean test(@Nullable final EntityDescriptor input) {
+        
+        if (input == null || input.getEntityID() == null) {
+            return false;
+        }
+        
+        return pattern.matcher(input.getEntityID()).matches();
+    }
+
+}
\ 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