You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by jo...@apache.org on 2015/08/16 21:59:05 UTC
[49/53] [abbrv] [partial] nifi git commit: NIFI-850 removed nifi
parent, updated nifi pom, moved all nifi subdirs up one level, fixed readme.
http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnShutdown.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnShutdown.java b/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnShutdown.java
new file mode 100644
index 0000000..44098ff
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnShutdown.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.annotation.lifecycle;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.processor.ProcessContext;
+
+/**
+ * <p>
+ * Marker annotation a {@link org.apache.nifi.processor.Processor Processor},
+ * {@link org.apache.nifi.controller.ControllerService ControllerService}, or
+ * {@link org.apache.nifi.reporting.ReportingTask ReportingTask} implementation
+ * can use to indicate a method should be called whenever the flow is being
+ * shutdown. This will be called at most once for each component in a JVM
+ * lifetime. It is not, however, guaranteed that this method will be called on
+ * shutdown, as the service may be killed suddenly.
+ * </p>
+ *
+ * <p>
+ * Methods with this annotation are permitted to take either 0 or 1 argument. If
+ * an argument is used, it must be of type {@link ConfigurationContext} if the
+ * component is a ReportingTask or Controller Service, or of type
+ * {@link ProcessContext} if the component is a Processor.
+ * </p>
+ *
+ */
+@Documented
+@Target({ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@Inherited
+public @interface OnShutdown {
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnStopped.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnStopped.java b/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnStopped.java
new file mode 100644
index 0000000..622f158
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnStopped.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.annotation.lifecycle;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.processor.ProcessContext;
+
+/**
+ * <p>
+ * Marker annotation a {@link org.apache.nifi.processor.Processor Processor} or
+ * {@link org.apache.nifi.reporting.ReportingTask ReportingTask} implementation
+ * can use to indicate that a method should be called whenever the component is
+ * no longer scheduled to run. Methods marked with this annotation will be
+ * invoked each time the component is stopped and will be invoked only after the
+ * last thread has returned from the <code>onTrigger</code> method.
+ * </p>
+ *
+ * <p>
+ * This means that the thread executing in this method will be the only thread
+ * executing in any part of the Processor. However, since other threads may
+ * later execute other parts of the code, member variables must still be
+ * protected appropriately. However, access to multiple variables need not be
+ * atomic.
+ * </p>
+ *
+ * <p>
+ * To indicate that a method should be called immediately when a component is no
+ * longer scheduled to run (as opposed to after all threads have returned from
+ * the <code>onTrigger</code> method), see the {@link OnUnscheduled} annotation.
+ * </p>
+ *
+ * <p>
+ * Methods with this annotation are permitted to take either 0 or 1 argument. If
+ * an argument is used, it must be of type {@link ConfigurationContext} if the
+ * component is a ReportingTask or of type {@link ProcessContext} if the
+ * component is a Processor.
+ * </p>
+ *
+ */
+@Documented
+@Target({ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@Inherited
+public @interface OnStopped {
+
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnUnscheduled.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnUnscheduled.java b/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnUnscheduled.java
new file mode 100644
index 0000000..b7d5027
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnUnscheduled.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.annotation.lifecycle;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * <p>
+ * Marker annotation a {@link org.apache.nifi.processor.Processor Processor} or
+ * {@link org.apache.nifi.reporting.ReportingTask ReportingTask} should be
+ * called whenever the component is no longer scheduled to run. Methods marked
+ * with this annotation will be invoked each time the framework is notified to
+ * stop scheduling the component. This method is invoked as other threads are
+ * potentially running. To invoke a method after all threads have finished
+ * processing, see the {@link OnStopped} annotation.
+ * </p>
+ *
+ * <p>
+ * Methods using this annotation must take either 0 arguments or a single
+ * argument.
+ * </p>
+ *
+ * <p>
+ * If using 1 argument and the component using the annotation is a Processor,
+ * that argument must be of type
+ * {@link org.apache.nifi.processor.ProcessContext ProcessContext}.
+ * </p>
+ *
+ * <p>
+ * If using 1 argument and the component using the annotation is a Reporting
+ * Task, that argument must be of type
+ * {@link org.apache.nifi.controller.ConfigurationContext ConfigurationContext}.
+ * </p>
+ */
+@Documented
+@Target({ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@Inherited
+public @interface OnUnscheduled {
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/annotation/notification/OnPrimaryNodeStateChange.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/annotation/notification/OnPrimaryNodeStateChange.java b/nifi-api/src/main/java/org/apache/nifi/annotation/notification/OnPrimaryNodeStateChange.java
new file mode 100644
index 0000000..4ea2170
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/annotation/notification/OnPrimaryNodeStateChange.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.annotation.notification;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * <p>
+ * Marker annotation that a component can use to indicate that a method should be
+ * called whenever the state of the Primary Node in a cluster has changed.
+ * </p>
+ *
+ * <p>
+ * Methods with this annotation should take either no arguments or one argument of type
+ * {@link PrimaryNodeState}. The {@link PrimaryNodeState} provides context about what changed
+ * so that the component can take appropriate action.
+ * </p>
+ */
+@Documented
+@Target({ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@Inherited
+public @interface OnPrimaryNodeStateChange {
+
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/annotation/notification/PrimaryNodeState.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/annotation/notification/PrimaryNodeState.java b/nifi-api/src/main/java/org/apache/nifi/annotation/notification/PrimaryNodeState.java
new file mode 100644
index 0000000..0d65b65
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/annotation/notification/PrimaryNodeState.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.annotation.notification;
+
+/**
+ * Represents a state change that occurred for the Primary Node of a NiFi cluster.
+ */
+public enum PrimaryNodeState {
+ /**
+ * The node receiving this state has been elected the Primary Node of the NiFi cluster.
+ */
+ ELECTED_PRIMARY_NODE,
+
+ /**
+ * The node receiving this state was the Primary Node but has now had its Primary Node
+ * role revoked.
+ */
+ PRIMARY_NODE_REVOKED;
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/authorization/Authority.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/authorization/Authority.java b/nifi-api/src/main/java/org/apache/nifi/authorization/Authority.java
new file mode 100644
index 0000000..4502c11
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/authorization/Authority.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.authorization;
+
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+/**
+ * Authorities that can be assigned to NiFi users.
+ */
+public enum Authority {
+
+ ROLE_MONITOR,
+ ROLE_DFM,
+ ROLE_ADMIN,
+ ROLE_PROVENANCE,
+ ROLE_PROXY,
+ ROLE_NIFI;
+
+ /**
+ * @param rawAuthority string form of authority
+ * @return the matching role or null if the specified role does not match
+ * any roles
+ */
+ public static Authority valueOfAuthority(String rawAuthority) {
+ Authority desiredAuthority = null;
+
+ for (Authority authority : values()) {
+ if (authority.toString().equals(rawAuthority)) {
+ desiredAuthority = authority;
+ break;
+ }
+ }
+
+ return desiredAuthority;
+ }
+
+ /**
+ * @return the string value of each authority
+ */
+ public static Set<String> getRawAuthorities() {
+ Set<String> authorities = new LinkedHashSet<>();
+ for (Authority authority : values()) {
+ authorities.add(authority.toString());
+ }
+ return authorities;
+ }
+
+ public static Set<String> convertAuthorities(Set<Authority> authorities) {
+ if (authorities == null) {
+ throw new IllegalArgumentException("No authorities have been specified.");
+ }
+
+ // convert the set
+ Set<String> rawAuthorities = new HashSet<>(authorities.size());
+ for (Authority authority : authorities) {
+ rawAuthorities.add(authority.toString());
+ }
+ return rawAuthorities;
+ }
+
+ public static EnumSet<Authority> convertRawAuthorities(Set<String> rawAuthorities) {
+ if (rawAuthorities == null) {
+ throw new IllegalArgumentException("No authorities have been specified.");
+ }
+
+ // convert the set
+ EnumSet<Authority> authorities = EnumSet.noneOf(Authority.class);
+ for (String rawAuthority : rawAuthorities) {
+ Authority authority = Authority.valueOfAuthority(rawAuthority);
+ if (authority != null) {
+ authorities.add(authority);
+ }
+ }
+ return authorities;
+ }
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/authorization/AuthorityProvider.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/authorization/AuthorityProvider.java b/nifi-api/src/main/java/org/apache/nifi/authorization/AuthorityProvider.java
new file mode 100644
index 0000000..723ec33
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/authorization/AuthorityProvider.java
@@ -0,0 +1,182 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.authorization;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.nifi.authorization.exception.AuthorityAccessException;
+import org.apache.nifi.authorization.exception.IdentityAlreadyExistsException;
+import org.apache.nifi.authorization.exception.ProviderCreationException;
+import org.apache.nifi.authorization.exception.ProviderDestructionException;
+import org.apache.nifi.authorization.exception.UnknownIdentityException;
+
+/**
+ * This class allows clients to retrieve the authorities for a given DN.
+ */
+public interface AuthorityProvider {
+
+ /**
+ * @param dn of the user
+ * @return whether the user with the specified DN is known to this authority
+ * provider. It is not necessary for the user to have any authorities
+ */
+ boolean doesDnExist(String dn) throws AuthorityAccessException;
+
+ /**
+ * Get the authorities for the specified user. If the specified user exists
+ * but does not have any authorities, an empty set should be returned.
+ *
+ * @param dn of the user to lookup
+ * @return the authorities for the specified user. If the specified user
+ * exists but does not have any authorities, an empty set should be returned
+ * @throws UnknownIdentityException if identity is not known
+ * @throws AuthorityAccessException if unable to access authorities
+ */
+ Set<Authority> getAuthorities(String dn) throws UnknownIdentityException, AuthorityAccessException;
+
+ /**
+ * Sets the specified authorities for the specified user.
+ *
+ * @param dn the specified user
+ * @param authorities the new authorities for the user
+ * @throws UnknownIdentityException if identity is not known
+ * @throws AuthorityAccessException if unable to access authorities
+ */
+ void setAuthorities(String dn, Set<Authority> authorities) throws UnknownIdentityException, AuthorityAccessException;
+
+ /**
+ * Gets the users for the specified authority.
+ *
+ * @param authority for which to determine membership of
+ * @return all users with the specified authority
+ * @throws AuthorityAccessException if unable to access authorities
+ */
+ Set<String> getUsers(Authority authority) throws AuthorityAccessException;
+
+ /**
+ * Revokes the specified user. Its up to the implementor to determine the
+ * semantics of revocation.
+ *
+ * @param dn the dn of the user
+ * @throws UnknownIdentityException if the user is not known
+ * @throws AuthorityAccessException if unable to access the authorities
+ */
+ void revokeUser(String dn) throws UnknownIdentityException, AuthorityAccessException;
+
+ /**
+ * Add the specified user.
+ *
+ * @param dn of the user
+ * @param group Optional
+ * @throws UnknownIdentityException if the user is not known
+ * @throws AuthorityAccessException if unable to access the authorities
+ */
+ void addUser(String dn, String group) throws IdentityAlreadyExistsException, AuthorityAccessException;
+
+ /**
+ * Gets the group for the specified user. Return null if the user does not
+ * belong to a group.
+ *
+ * @param dn the user
+ * @return the group of the given user
+ * @throws UnknownIdentityException if the user is not known
+ * @throws AuthorityAccessException if unable to access the authorities
+ */
+ String getGroupForUser(String dn) throws UnknownIdentityException, AuthorityAccessException;
+
+ /**
+ * Revokes all users for a specified group. Its up to the implementor to
+ * determine the semantics of revocation.
+ *
+ * @param group to revoke the users of
+ * @throws UnknownIdentityException if the user is not known
+ * @throws AuthorityAccessException if unable to access the authorities
+ */
+ void revokeGroup(String group) throws UnknownIdentityException, AuthorityAccessException;
+
+ /**
+ * Adds the specified users to the specified group.
+ *
+ * @param dn the set of users to add to the group
+ * @param group to add users to
+ * @throws UnknownIdentityException if the user is not known
+ * @throws AuthorityAccessException if unable to access the authorities
+ */
+ void setUsersGroup(Set<String> dn, String group) throws UnknownIdentityException, AuthorityAccessException;
+
+ /**
+ * Ungroups the specified user.
+ *
+ * @param dn of the user
+ * @throws UnknownIdentityException if the user is not known
+ * @throws AuthorityAccessException if unable to access the authorities
+ */
+ void ungroupUser(String dn) throws UnknownIdentityException, AuthorityAccessException;
+
+ /**
+ * Ungroups the specified group. Since the semantics of revocation is up to
+ * the implementor, this method should do nothing if the specified group
+ * does not exist. If an admin revoked this group before calling ungroup, it
+ * may or may not exist.
+ *
+ * @param group to ungroup
+ * @throws AuthorityAccessException if unable to access the authorities
+ */
+ void ungroup(String group) throws AuthorityAccessException;
+
+ /**
+ * Determines whether the user in the specified dnChain should be able to
+ * download the content for the flowfile with the specified attributes.
+ *
+ * The first dn in the chain is the end user that the request was issued on
+ * behalf of. The subsequent dn's in the chain represent entities proxying
+ * the user's request with the last being the proxy that sent the current
+ * request.
+ *
+ * @param dnChain of the user
+ * @param attributes of the flowfile being requested
+ * @return the authorization result
+ * @throws UnknownIdentityException if the user is not known
+ * @throws AuthorityAccessException if unable to access the authorities
+ */
+ DownloadAuthorization authorizeDownload(List<String> dnChain, Map<String, String> attributes) throws UnknownIdentityException, AuthorityAccessException;
+
+ /**
+ * Called immediately after instance creation for implementers to perform
+ * additional setup
+ *
+ * @param initializationContext in which to initialize
+ */
+ void initialize(AuthorityProviderInitializationContext initializationContext) throws ProviderCreationException;
+
+ /**
+ * Called to configure the AuthorityProvider.
+ *
+ * @param configurationContext at the time of configuration
+ * @throws ProviderCreationException for any issues configuring the provider
+ */
+ void onConfigured(AuthorityProviderConfigurationContext configurationContext) throws ProviderCreationException;
+
+ /**
+ * Called immediately before instance destruction for implementers to
+ * release resources.
+ *
+ * @throws ProviderDestructionException If pre-destruction fails.
+ */
+ void preDestruction() throws ProviderDestructionException;
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/authorization/AuthorityProviderConfigurationContext.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/authorization/AuthorityProviderConfigurationContext.java b/nifi-api/src/main/java/org/apache/nifi/authorization/AuthorityProviderConfigurationContext.java
new file mode 100644
index 0000000..c1ba5df
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/authorization/AuthorityProviderConfigurationContext.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.authorization;
+
+import java.util.Map;
+
+/**
+ *
+ */
+public interface AuthorityProviderConfigurationContext {
+
+ /**
+ * @return identifier for the authority provider
+ */
+ String getIdentifier();
+
+ /**
+ * Retrieves all properties the component currently understands regardless
+ * of whether a value has been set for them or not. If no value is present
+ * then its value is null and thus any registered default for the property
+ * descriptor applies.
+ *
+ * @return Map of all properties
+ */
+ Map<String, String> getProperties();
+
+ /**
+ * @param property to lookup the descriptor and value of
+ * @return the value the component currently understands for the given
+ * PropertyDescriptor. This method does not substitute default
+ * PropertyDescriptor values, so the value returned will be null if not set
+ */
+ String getProperty(String property);
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/authorization/AuthorityProviderInitializationContext.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/authorization/AuthorityProviderInitializationContext.java b/nifi-api/src/main/java/org/apache/nifi/authorization/AuthorityProviderInitializationContext.java
new file mode 100644
index 0000000..7b2f89f
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/authorization/AuthorityProviderInitializationContext.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.authorization;
+
+/**
+ *
+ */
+public interface AuthorityProviderInitializationContext {
+
+ public String getIdentifier();
+
+ public AuthorityProviderLookup getAuthorityProviderLookup();
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/authorization/AuthorityProviderLookup.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/authorization/AuthorityProviderLookup.java b/nifi-api/src/main/java/org/apache/nifi/authorization/AuthorityProviderLookup.java
new file mode 100644
index 0000000..dc30967
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/authorization/AuthorityProviderLookup.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.authorization;
+
+/**
+ *
+ */
+public interface AuthorityProviderLookup {
+
+ AuthorityProvider getAuthorityProvider(String identifier);
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/authorization/DownloadAuthorization.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/authorization/DownloadAuthorization.java b/nifi-api/src/main/java/org/apache/nifi/authorization/DownloadAuthorization.java
new file mode 100644
index 0000000..416f3cf
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/authorization/DownloadAuthorization.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.authorization;
+
+/**
+ * Represents a decision whether authorization is granted to download content.
+ */
+public class DownloadAuthorization {
+
+ private static enum Result {
+
+ Approved,
+ Denied;
+ }
+
+ private static final DownloadAuthorization APPROVED = new DownloadAuthorization(Result.Approved, null);
+
+ private final Result result;
+ private final String explanation;
+
+ /**
+ * Creates a new DownloadAuthorization with the specified result and
+ * explanation.
+ *
+ * @param result of the authorization
+ * @param explanation for the authorization attempt
+ */
+ private DownloadAuthorization(Result result, String explanation) {
+ if (Result.Denied.equals(result) && explanation == null) {
+ throw new IllegalArgumentException("An explanation is required when the download request is denied.");
+ }
+
+ this.result = result;
+ this.explanation = explanation;
+ }
+
+ /**
+ * @return Whether or not the download request is approved
+ */
+ public boolean isApproved() {
+ return Result.Approved.equals(result);
+ }
+
+ /**
+ * @return If the download request is denied, the reason why. Null otherwise
+ */
+ public String getExplanation() {
+ return explanation;
+ }
+
+ /**
+ * @return a new approved DownloadAuthorization
+ */
+ public static DownloadAuthorization approved() {
+ return APPROVED;
+ }
+
+ /**
+ * Creates a new denied DownloadAuthorization with the specified
+ * explanation.
+ *
+ * @param explanation for why it was denied
+ * @return a new denied DownloadAuthorization with the specified explanation
+ * @throws IllegalArgumentException if explanation is null
+ */
+ public static DownloadAuthorization denied(String explanation) {
+ return new DownloadAuthorization(Result.Denied, explanation);
+ }
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/authorization/annotation/AuthorityProviderContext.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/authorization/annotation/AuthorityProviderContext.java b/nifi-api/src/main/java/org/apache/nifi/authorization/annotation/AuthorityProviderContext.java
new file mode 100644
index 0000000..5ac2af7
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/authorization/annotation/AuthorityProviderContext.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.authorization.annotation;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ *
+ *
+ */
+@Documented
+@Target({ElementType.FIELD, ElementType.METHOD})
+@Retention(RetentionPolicy.RUNTIME)
+@Inherited
+public @interface AuthorityProviderContext {
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/authorization/exception/AuthorityAccessException.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/authorization/exception/AuthorityAccessException.java b/nifi-api/src/main/java/org/apache/nifi/authorization/exception/AuthorityAccessException.java
new file mode 100644
index 0000000..be64767
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/authorization/exception/AuthorityAccessException.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.authorization.exception;
+
+/**
+ * Represents the case when the DN could not be confirmed because it was unable
+ * to access the data store.
+ */
+public class AuthorityAccessException extends RuntimeException {
+
+ public AuthorityAccessException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public AuthorityAccessException(String message) {
+ super(message);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/authorization/exception/IdentityAlreadyExistsException.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/authorization/exception/IdentityAlreadyExistsException.java b/nifi-api/src/main/java/org/apache/nifi/authorization/exception/IdentityAlreadyExistsException.java
new file mode 100644
index 0000000..ba80b6e
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/authorization/exception/IdentityAlreadyExistsException.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.authorization.exception;
+
+/**
+ * Represents the case when the user identity already exists.
+ */
+public class IdentityAlreadyExistsException extends RuntimeException {
+
+ public IdentityAlreadyExistsException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public IdentityAlreadyExistsException(String message) {
+ super(message);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/authorization/exception/ProviderCreationException.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/authorization/exception/ProviderCreationException.java b/nifi-api/src/main/java/org/apache/nifi/authorization/exception/ProviderCreationException.java
new file mode 100644
index 0000000..24ac793
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/authorization/exception/ProviderCreationException.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.authorization.exception;
+
+/**
+ * Represents the exceptional case when an AuthorityProvider fails instantiated.
+ *
+ */
+public class ProviderCreationException extends RuntimeException {
+
+ public ProviderCreationException() {
+ }
+
+ public ProviderCreationException(String msg) {
+ super(msg);
+ }
+
+ public ProviderCreationException(Throwable cause) {
+ super(cause);
+ }
+
+ public ProviderCreationException(String msg, Throwable cause) {
+ super(msg, cause);
+ }
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/authorization/exception/ProviderDestructionException.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/authorization/exception/ProviderDestructionException.java b/nifi-api/src/main/java/org/apache/nifi/authorization/exception/ProviderDestructionException.java
new file mode 100644
index 0000000..985d3fb
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/authorization/exception/ProviderDestructionException.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.authorization.exception;
+
+/**
+ * Represents the exceptional case when an AuthorityProvider fails destruction.
+ *
+ */
+public class ProviderDestructionException extends RuntimeException {
+
+ public ProviderDestructionException() {
+ }
+
+ public ProviderDestructionException(String msg) {
+ super(msg);
+ }
+
+ public ProviderDestructionException(Throwable cause) {
+ super(cause);
+ }
+
+ public ProviderDestructionException(String msg, Throwable cause) {
+ super(msg, cause);
+ }
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/authorization/exception/UnknownIdentityException.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/authorization/exception/UnknownIdentityException.java b/nifi-api/src/main/java/org/apache/nifi/authorization/exception/UnknownIdentityException.java
new file mode 100644
index 0000000..2ada1c7
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/authorization/exception/UnknownIdentityException.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.authorization.exception;
+
+/**
+ * Represents the case when an identity cannot be confirmed.
+ */
+public class UnknownIdentityException extends RuntimeException {
+
+ public UnknownIdentityException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public UnknownIdentityException(String message) {
+ super(message);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/components/AbstractConfigurableComponent.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/components/AbstractConfigurableComponent.java b/nifi-api/src/main/java/org/apache/nifi/components/AbstractConfigurableComponent.java
new file mode 100644
index 0000000..1d4e0c2
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/components/AbstractConfigurableComponent.java
@@ -0,0 +1,220 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.components;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+public abstract class AbstractConfigurableComponent implements ConfigurableComponent {
+
+ /**
+ * Allows subclasses to perform their own validation on the already set
+ * properties. Since each property is validated as it is set this allows
+ * validation of groups of properties together. Default return is an empty
+ * set.
+ *
+ * This method will be called only when it has been determined that all
+ * property values are valid according to their corresponding
+ * PropertyDescriptor's validators.
+ *
+ * @param validationContext provides a mechanism for obtaining externally
+ * managed values, such as property values and supplies convenience methods
+ * for operating on those values
+ *
+ * @return Collection of ValidationResult objects that will be added to any
+ * other validation findings - may be null
+ */
+ protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) {
+ return Collections.emptySet();
+ }
+
+ /**
+ * @param descriptorName to lookup the descriptor
+ * @return a PropertyDescriptor for the name specified that is fully
+ * populated
+ */
+ @Override
+ public final PropertyDescriptor getPropertyDescriptor(final String descriptorName) {
+ final PropertyDescriptor specDescriptor = new PropertyDescriptor.Builder().name(descriptorName).build();
+ return getPropertyDescriptor(specDescriptor);
+ }
+
+ private PropertyDescriptor getPropertyDescriptor(final PropertyDescriptor specDescriptor) {
+ PropertyDescriptor descriptor = null;
+ //check if property supported
+ final List<PropertyDescriptor> supportedDescriptors = getSupportedPropertyDescriptors();
+ if (supportedDescriptors != null) {
+ for (final PropertyDescriptor desc : supportedDescriptors) { //find actual descriptor
+ if (specDescriptor.equals(desc)) {
+ return desc;
+ }
+ }
+ }
+
+ descriptor = getSupportedDynamicPropertyDescriptor(specDescriptor.getName());
+ if (descriptor != null && !descriptor.isDynamic()) {
+ descriptor = new PropertyDescriptor.Builder().fromPropertyDescriptor(descriptor).dynamic(true).build();
+ }
+
+ if (descriptor == null) {
+ descriptor = new PropertyDescriptor.Builder().fromPropertyDescriptor(specDescriptor).addValidator(Validator.INVALID).dynamic(true).build();
+ }
+ return descriptor;
+ }
+
+ @Override
+ public final Collection<ValidationResult> validate(final ValidationContext context) {
+ // goes through supported properties
+ final Collection<ValidationResult> results = new ArrayList<>();
+ final List<PropertyDescriptor> supportedDescriptors = getSupportedPropertyDescriptors();
+ if (null != supportedDescriptors) {
+ for (final PropertyDescriptor descriptor : supportedDescriptors) {
+ String value = context.getProperty(descriptor).getValue();
+ if (value == null) {
+ value = descriptor.getDefaultValue();
+ }
+ if (value == null && descriptor.isRequired()) {
+ results.add(new ValidationResult.Builder().valid(false).input(null).subject(descriptor.getName()).explanation(descriptor.getName() + " is required").build());
+ continue;
+ } else if (value == null) {
+ continue;
+ }
+
+ final ValidationResult result = descriptor.validate(value, context);
+ if (!result.isValid()) {
+ results.add(result);
+ }
+ }
+ }
+
+ // validate any dynamic properties
+ for (final Map.Entry<PropertyDescriptor, String> entry : context.getProperties().entrySet()) {
+ final PropertyDescriptor descriptor = entry.getKey();
+ final String value = entry.getValue();
+
+ if (supportedDescriptors != null && !supportedDescriptors.contains(descriptor)) {
+ final ValidationResult result = descriptor.validate(value, context);
+ if (!result.isValid()) {
+ results.add(result);
+ }
+ }
+ }
+
+ // only run customValidate if regular validation is successful. This allows Processor developers to not have to check
+ // if values are null or invalid so that they can focus only on the interaction between the properties, etc.
+ if (results.isEmpty()) {
+ final Collection<ValidationResult> customResults = customValidate(context);
+ if (null != customResults) {
+ for (final ValidationResult result : customResults) {
+ if (!result.isValid()) {
+ results.add(result);
+ }
+ }
+ }
+ }
+
+ return results;
+ }
+
+ /**
+ * Hook method allowing subclasses to eagerly react to a configuration
+ * change for the given property descriptor. As an alternative to using this
+ * method a processor may simply get the latest value whenever it needs it
+ * and if necessary lazily evaluate it.
+ *
+ * @param descriptor of the modified property
+ * @param oldValue non-null property value (previous)
+ * @param newValue the new property value or if null indicates the property
+ * was removed
+ */
+ @Override
+ public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) {
+ }
+
+ /**
+ * <p>
+ * Used to allow subclasses to determine what PropertyDescriptor if any to
+ * use when a property is requested for which a descriptor is not already
+ * registered. By default this method simply returns a null descriptor. By
+ * overriding this method processor implementations can support dynamic
+ * properties since this allows them to register properties on demand. It is
+ * acceptable for a dynamically generated property to indicate it is
+ * required so long as it is understood it is only required once set.
+ * Dynamic properties by definition cannot be required until used.</p>
+ *
+ * <p>
+ * This method should be side effect free in the subclasses in terms of how
+ * often it is called for a given property name because there is guarantees
+ * how often it will be called for a given property name.</p>
+ *
+ * <p>
+ * Default is null.
+ *
+ * @param propertyDescriptorName used to lookup if any property descriptors exist for that name
+ * @return new property descriptor if supported
+ */
+ protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String propertyDescriptorName) {
+ return null;
+ }
+
+ /**
+ * Allows subclasses to register which property descriptor objects are
+ * supported. Default return is an empty set.
+ *
+ * @return PropertyDescriptor objects this processor currently supports
+ */
+ @SuppressWarnings("unchecked")
+ protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
+ return Collections.EMPTY_LIST;
+ }
+
+ @Override
+ public final List<PropertyDescriptor> getPropertyDescriptors() {
+ final List<PropertyDescriptor> supported = getSupportedPropertyDescriptors();
+ return supported == null ? Collections.<PropertyDescriptor>emptyList() : new ArrayList<>(supported);
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (!(obj instanceof ConfigurableComponent)) {
+ return false;
+ }
+
+ final ConfigurableComponent other = (ConfigurableComponent) obj;
+ return getIdentifier().equals(other.getIdentifier());
+ }
+
+ @Override
+ public int hashCode() {
+ return 235 + getIdentifier().hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + "[id=" + getIdentifier() + "]";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/components/AllowableValue.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/components/AllowableValue.java b/nifi-api/src/main/java/org/apache/nifi/components/AllowableValue.java
new file mode 100644
index 0000000..a480961
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/components/AllowableValue.java
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.components;
+
+import java.util.Objects;
+
+/**
+ * <p>
+ * Represents a valid value for a {@link PropertyDescriptor}
+ * </p>
+ */
+public class AllowableValue {
+
+ private final String value;
+ private final String displayName;
+ private final String description;
+
+ /**
+ * Constructs a new AllowableValue with the given value and and the same
+ * display name and no description.
+ *
+ * @param value that is allowed
+ */
+ public AllowableValue(final String value) {
+ this(value, value);
+ }
+
+ /**
+ * Constructs a new AllowableValue with the given value and display name and
+ * no description
+ *
+ * @param value that is allowed
+ * @param displayName to display for the value
+ *
+ * @throws NullPointerException if either argument is null
+ */
+ public AllowableValue(final String value, final String displayName) {
+ this(value, displayName, null);
+ }
+
+ /**
+ * Constructs a new AllowableValue with the given value, display name, and
+ * description
+ *
+ * @param value that is valid
+ * @param displayName to show for the value
+ * @param description of the value
+ *
+ * @throws NullPointerException if identifier or value is null
+ */
+ public AllowableValue(final String value, final String displayName, final String description) {
+ this.value = Objects.requireNonNull(value);
+ this.displayName = Objects.requireNonNull(displayName);
+ this.description = description;
+ }
+
+ /**
+ * @return the value of this AllowableValue
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * @return a human-readable name for this AllowableValue
+ */
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ /**
+ * @return a description for this value, or <code>null</code> if no
+ * description was provided
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * @return true if <code>this</code> is equal to <code>obj</code> of <code>obj</code> is the
+ * same object as <code>this</code> or if <code>obj</code> is an instance of
+ * <code>AllowableValue</code> and both have the same value, or if
+ * <code>obj</code> is a String and is equal to
+ * {@link #getValue() this.getValue()}.
+ */
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj == this) {
+ return true;
+ }
+
+ if (obj instanceof AllowableValue) {
+ final AllowableValue other = (AllowableValue) obj;
+ return (this.value.equals(other.getValue()));
+ } else if (obj instanceof String) {
+ return this.value.equals(obj);
+ }
+
+ return false;
+ }
+
+ /**
+ * @return based solely off of the value
+ */
+ @Override
+ public int hashCode() {
+ return 23984731 + 17 * value.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return value;
+ }
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/components/ConfigurableComponent.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/components/ConfigurableComponent.java b/nifi-api/src/main/java/org/apache/nifi/components/ConfigurableComponent.java
new file mode 100644
index 0000000..8b56f48
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/components/ConfigurableComponent.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.components;
+
+import java.util.Collection;
+import java.util.List;
+
+public interface ConfigurableComponent {
+
+ /**
+ * Validates a set of properties, returning ValidationResults for any
+ * invalid properties. All defined properties will be validated. If they are
+ * not included in the in the purposed configuration, the default value will
+ * be used.
+ *
+ * @param context of validation
+ * @return Collection of validation result objects for any invalid findings
+ * only. If the collection is empty then the component is valid. Guaranteed
+ * non-null
+ */
+ Collection<ValidationResult> validate(ValidationContext context);
+
+ /**
+ * @param name to lookup the descriptor
+ * @return the PropertyDescriptor with the given name, if it exists;
+ * otherwise, returns <code>null</code>
+ */
+ PropertyDescriptor getPropertyDescriptor(String name);
+
+ /**
+ * Hook method allowing subclasses to eagerly react to a configuration
+ * change for the given property descriptor. This method will be invoked
+ * regardless of property validity. As an alternative to using this method,
+ * a component may simply get the latest value whenever it needs it and if
+ * necessary lazily evaluate it. Any throwable that escapes this method will
+ * simply be ignored.
+ *
+ * @param descriptor the descriptor for the property being modified
+ * @param oldValue the value that was previously set, or null if no value
+ * was previously set for this property
+ * @param newValue the new property value or if null indicates the property
+ * was removed
+ */
+ void onPropertyModified(PropertyDescriptor descriptor, String oldValue, String newValue);
+
+ /**
+ * Returns a {@link List} of all {@link PropertyDescriptor}s that this
+ * component supports.
+ *
+ * @return PropertyDescriptor objects this component currently supports
+ */
+ List<PropertyDescriptor> getPropertyDescriptors();
+
+ /**
+ * @return the unique identifier that the framework assigned to this
+ * component
+ */
+ String getIdentifier();
+}
http://git-wip-us.apache.org/repos/asf/nifi/blob/aa998847/nifi-api/src/main/java/org/apache/nifi/components/PropertyDescriptor.java
----------------------------------------------------------------------
diff --git a/nifi-api/src/main/java/org/apache/nifi/components/PropertyDescriptor.java b/nifi-api/src/main/java/org/apache/nifi/components/PropertyDescriptor.java
new file mode 100644
index 0000000..acda6c4
--- /dev/null
+++ b/nifi-api/src/main/java/org/apache/nifi/components/PropertyDescriptor.java
@@ -0,0 +1,556 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.nifi.components;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.nifi.controller.ControllerService;
+
+/**
+ * An immutable object for holding information about a type of processor
+ * property.
+ *
+ */
+public final class PropertyDescriptor implements Comparable<PropertyDescriptor> {
+
+ public static final PropertyDescriptor NULL_DESCRIPTOR = new PropertyDescriptor.Builder().name("").build();
+
+ /**
+ * The proper name for the property. This is the primary mechanism of
+ * comparing equality.
+ */
+ private final String name;
+
+ /**
+ * The name that should be displayed to user when referencing this property
+ */
+ private final String displayName;
+
+ /**
+ * And explanation of the meaning of the given property. This description is
+ * meant to be displayed to a user or simply provide a mechanism of
+ * documenting intent.
+ */
+ private final String description;
+ /**
+ * The default value for this property
+ */
+ private final String defaultValue;
+ /**
+ * The allowable values for this property. If empty then the allowable
+ * values are not constrained
+ */
+ private final List<AllowableValue> allowableValues;
+ /**
+ * Determines whether the property is required for this processor
+ */
+ private final boolean required;
+ /**
+ * indicates that the value for this property should be considered sensitive
+ * and protected whenever stored or represented
+ */
+ private final boolean sensitive;
+ /**
+ * indicates whether this property well-known for this processor or is
+ * user-defined
+ */
+ private final boolean dynamic;
+ /**
+ * indicates whether or not this property supports the Attribute Expression
+ * Language
+ */
+ private final boolean expressionLanguageSupported;
+
+ /**
+ * the interface of the {@link ControllerService} that this Property refers
+ * to; will be null if not identifying a ControllerService.
+ */
+ private final Class<? extends ControllerService> controllerServiceDefinition;
+
+ /**
+ * The validators that should be used whenever an attempt is made to set
+ * this property value. Any allowable values specified will be checked first
+ * and any validators specified will be ignored.
+ */
+ private final List<Validator> validators;
+
+ protected PropertyDescriptor(final Builder builder) {
+ this.displayName = builder.displayName == null ? builder.name : builder.displayName;
+ this.name = builder.name;
+ this.description = builder.description;
+ this.defaultValue = builder.defaultValue;
+ this.allowableValues = builder.allowableValues;
+ this.required = builder.required;
+ this.sensitive = builder.sensitive;
+ this.dynamic = builder.dynamic;
+ this.expressionLanguageSupported = builder.expressionLanguageSupported;
+ this.controllerServiceDefinition = builder.controllerServiceDefinition;
+ this.validators = new ArrayList<>(builder.validators);
+ }
+
+ @Override
+ public int compareTo(final PropertyDescriptor o) {
+ if (o == null) {
+ return -1;
+ }
+ return getName().compareTo(o.getName());
+ }
+
+ /**
+ * Validates the given input against this property descriptor's validator.
+ * If this descriptor has a set of allowable values then the given value is
+ * only checked against the allowable values.
+ *
+ * @param input the value to validate
+ * @param context the context of validation
+ * @return the result of validating the input
+ */
+ public ValidationResult validate(final String input, final ValidationContext context) {
+ ValidationResult lastResult = Validator.INVALID.validate(this.name, input, context);
+ if (allowableValues != null && !allowableValues.isEmpty()) {
+ final ConstrainedSetValidator csValidator = new ConstrainedSetValidator(allowableValues);
+ final ValidationResult csResult = csValidator.validate(this.name, input, context);
+ if (csResult.isValid()) {
+ lastResult = csResult;
+ } else {
+ return csResult;
+ }
+ }
+
+ // if the property descriptor identifies a Controller Service, validate that the ControllerService exists, is of the correct type, and is valid
+ if (controllerServiceDefinition != null) {
+ final Set<String> validIdentifiers = context.getControllerServiceLookup().getControllerServiceIdentifiers(controllerServiceDefinition);
+ if (validIdentifiers != null && validIdentifiers.contains(input)) {
+ final ControllerService controllerService = context.getControllerServiceLookup().getControllerService(input);
+ if (!context.isValidationRequired(controllerService)) {
+ return new ValidationResult.Builder()
+ .input(input)
+ .subject(getName())
+ .valid(true)
+ .build();
+ }
+
+ final String serviceId = controllerService.getIdentifier();
+ if (!context.getControllerServiceLookup().isControllerServiceEnabled(serviceId)
+ && !context.getControllerServiceLookup().isControllerServiceEnabling(serviceId)) {
+ return new ValidationResult.Builder()
+ .input(context.getControllerServiceLookup().getControllerServiceName(serviceId))
+ .subject(getName())
+ .valid(false)
+ .explanation("Controller Service " + controllerService + " is disabled")
+ .build();
+ }
+
+ final Collection<ValidationResult> validationResults = controllerService.validate(context.getControllerServiceValidationContext(controllerService));
+ for (final ValidationResult result : validationResults) {
+ if (!result.isValid()) {
+ return new ValidationResult.Builder()
+ .input(input)
+ .subject(getName())
+ .valid(false)
+ .explanation("Controller Service is not valid: "
+ + ((result.getExplanation() == null || result.getExplanation().trim().isEmpty()) ? "(Service does not provide any explanation)" : result.getExplanation()))
+ .build();
+ }
+ }
+
+ return new ValidationResult.Builder()
+ .input(input)
+ .subject(getName())
+ .valid(true)
+ .build();
+ } else {
+ return new ValidationResult.Builder()
+ .input(input)
+ .subject(getName())
+ .valid(false)
+ .explanation("Invalid Controller Service: " + input + " is not a valid Controller Service Identifier or does not reference the correct type of Controller Service")
+ .build();
+ }
+ }
+
+ for (final Validator validator : validators) {
+ lastResult = validator.validate(this.name, input, context);
+ if (!lastResult.isValid()) {
+ break;
+ }
+ }
+ return lastResult;
+ }
+
+ public static final class Builder {
+
+ private String displayName = null;
+ private String name = null;
+ private String description = "";
+ private String defaultValue = null;
+ private List<AllowableValue> allowableValues = null;
+ private boolean required = false;
+ private boolean sensitive = false;
+ private boolean expressionLanguageSupported = false;
+ private boolean dynamic = false;
+ private Class<? extends ControllerService> controllerServiceDefinition;
+ private List<Validator> validators = new ArrayList<>();
+
+ public Builder fromPropertyDescriptor(final PropertyDescriptor specDescriptor) {
+ this.name = specDescriptor.name;
+ this.displayName = specDescriptor.displayName;
+ this.description = specDescriptor.description;
+ this.defaultValue = specDescriptor.defaultValue;
+ this.allowableValues = specDescriptor.allowableValues == null ? null : new ArrayList<>(specDescriptor.allowableValues);
+ this.required = specDescriptor.required;
+ this.sensitive = specDescriptor.sensitive;
+ this.dynamic = specDescriptor.dynamic;
+ this.expressionLanguageSupported = specDescriptor.expressionLanguageSupported;
+ this.controllerServiceDefinition = specDescriptor.getControllerServiceDefinition();
+ this.validators = new ArrayList<>(specDescriptor.validators);
+ return this;
+ }
+
+ /**
+ * Sets a unique id for the property. This field is optional and if not
+ * specified the PropertyDescriptor's name will be used as the
+ * identifying attribute. However, by supplying an id, the
+ * PropertyDescriptor's name can be changed without causing problems.
+ * This is beneficial because it allows a User Interface to represent
+ * the name differently.
+ *
+ * @param displayName of the property
+ * @return the builder
+ */
+ public Builder displayName(final String displayName) {
+ if (null != displayName) {
+ this.displayName = displayName;
+ }
+
+ return this;
+ }
+
+ /**
+ * Sets the property name.
+ *
+ * @param name of the property
+ * @return the builder
+ */
+ public Builder name(final String name) {
+ if (null != name) {
+ this.name = name;
+ }
+ return this;
+ }
+
+ /**
+ * Sets the value indicating whether or not this Property will support
+ * the Attribute Expression Language.
+ *
+ * @param supported true if yes; false otherwise
+ * @return the builder
+ */
+ public Builder expressionLanguageSupported(final boolean supported) {
+ this.expressionLanguageSupported = supported;
+ return this;
+ }
+
+ /**
+ * @param description of the property
+ * @return the builder
+ */
+ public Builder description(final String description) {
+ if (null != description) {
+ this.description = description;
+ }
+ return this;
+ }
+
+ /**
+ * Specifies the initial value and the default value that will be used
+ * if the user does not specify a value. When {@link #build()} is
+ * called, if Allowable Values have been set (see
+ * {@link #allowableValues(AllowableValue...)}) and this value is not
+ * one of those Allowable Values and Exception will be thrown. If the
+ * Allowable Values have been set using the
+ * {@link #allowableValues(AllowableValue...)} method, the default value
+ * should be set to the "Value" of the {@link AllowableValue} object
+ * (see {@link AllowableValue#getValue()}).
+ *
+ * @param value default value
+ * @return the builder
+ */
+ public Builder defaultValue(final String value) {
+ if (null != value) {
+ this.defaultValue = value;
+ }
+ return this;
+ }
+
+ public Builder dynamic(final boolean dynamic) {
+ this.dynamic = dynamic;
+ return this;
+ }
+
+ /**
+ * @param values contrained set of values
+ * @return the builder
+ */
+ public Builder allowableValues(final Set<String> values) {
+ if (null != values) {
+ this.allowableValues = new ArrayList<>();
+
+ for (final String value : values) {
+ this.allowableValues.add(new AllowableValue(value, value));
+ }
+ }
+ return this;
+ }
+
+ public <E extends Enum<E>> Builder allowableValues(final E[] values) {
+ if (null != values) {
+ this.allowableValues = new ArrayList<>();
+ for (final E value : values) {
+ allowableValues.add(new AllowableValue(value.name(), value.name()));
+ }
+ }
+ return this;
+ }
+
+ /**
+ * @param values constrained set of values
+ * @return the builder
+ */
+ public Builder allowableValues(final String... values) {
+ if (null != values) {
+ this.allowableValues = new ArrayList<>();
+ for (final String value : values) {
+ allowableValues.add(new AllowableValue(value, value));
+ }
+ }
+ return this;
+ }
+
+ /**
+ * Sets the Allowable Values for this Property
+ *
+ * @param values contrained set of values
+ * @return the builder
+ */
+ public Builder allowableValues(final AllowableValue... values) {
+ if (null != values) {
+ this.allowableValues = Arrays.asList(values);
+ }
+ return this;
+ }
+
+ /**
+ * @param required true if yes; false otherwise
+ * @return the builder
+ */
+ public Builder required(final boolean required) {
+ this.required = required;
+ return this;
+ }
+
+ /**
+ * @param sensitive true if sensitive; false otherwise
+ * @return the builder
+ */
+ public Builder sensitive(final boolean sensitive) {
+ this.sensitive = sensitive;
+ return this;
+ }
+
+ /**
+ * @param validator for the property
+ * @return the builder
+ */
+ public Builder addValidator(final Validator validator) {
+ if (validator != null) {
+ validators.add(validator);
+ }
+ return this;
+ }
+
+ /**
+ * Specifies that this property provides the identifier of a Controller
+ * Service that implements the given interface
+ *
+ * @param controllerServiceDefinition the interface that is implemented
+ * by the Controller Service
+ * @return the builder
+ */
+ public Builder identifiesControllerService(final Class<? extends ControllerService> controllerServiceDefinition) {
+ if (controllerServiceDefinition != null) {
+ this.controllerServiceDefinition = controllerServiceDefinition;
+ }
+ return this;
+ }
+
+ private boolean isValueAllowed(final String value) {
+ if (allowableValues == null || value == null) {
+ return true;
+ }
+
+ for (final AllowableValue allowableValue : allowableValues) {
+ if (allowableValue.getValue().equals(value)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * @return a PropertyDescriptor as configured
+ *
+ * @throws IllegalStateException if allowable values are configured but
+ * no default value is set, or the default value is not contained within
+ * the allowable values.
+ */
+ public PropertyDescriptor build() {
+ if (name == null) {
+ throw new IllegalStateException("Must specify a name");
+ }
+ if (!isValueAllowed(defaultValue)) {
+ throw new IllegalStateException("Default value [" + defaultValue + "] is not in the set of allowable values");
+ }
+
+ return new PropertyDescriptor(this);
+ }
+ }
+
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getDefaultValue() {
+ return defaultValue;
+ }
+
+ public boolean isRequired() {
+ return required;
+ }
+
+ public boolean isSensitive() {
+ return sensitive;
+ }
+
+ public boolean isDynamic() {
+ return dynamic;
+ }
+
+ public boolean isExpressionLanguageSupported() {
+ return expressionLanguageSupported;
+ }
+
+ public Class<? extends ControllerService> getControllerServiceDefinition() {
+ return controllerServiceDefinition;
+ }
+
+ public List<Validator> getValidators() {
+ return Collections.unmodifiableList(validators);
+ }
+
+ public List<AllowableValue> getAllowableValues() {
+ return allowableValues == null ? null : Collections.unmodifiableList(allowableValues);
+ }
+
+ @Override
+ public boolean equals(final Object other) {
+ if (other == null) {
+ return false;
+ }
+ if (!(other instanceof PropertyDescriptor)) {
+ return false;
+ }
+ if (this == other) {
+ return true;
+ }
+
+ PropertyDescriptor desc = (PropertyDescriptor) other;
+ return this.name.equals(desc.name);
+ }
+
+ @Override
+ public int hashCode() {
+ return 287 + this.name.hashCode() * 47;
+ }
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName() + "[" + displayName + "]";
+ }
+
+ private static final class ConstrainedSetValidator implements Validator {
+
+ private static final String POSITIVE_EXPLANATION = "Given value found in allowed set";
+ private static final String NEGATIVE_EXPLANATION = "Given value not found in allowed set '%1$s'";
+ private static final String VALUE_DEMARCATOR = ", ";
+ private final String validStrings;
+ private final Collection<String> validValues;
+
+ /**
+ * Constructs a validator that will check if the given value is in the
+ * given set.
+ *
+ * @param validValues values which are acceptible
+ * @throws NullPointerException if the given validValues is null
+ */
+ private ConstrainedSetValidator(final Collection<AllowableValue> validValues) {
+ String validVals = "";
+ if (!validValues.isEmpty()) {
+ final StringBuilder valuesBuilder = new StringBuilder();
+ for (final AllowableValue value : validValues) {
+ valuesBuilder.append(value).append(VALUE_DEMARCATOR);
+ }
+ validVals = valuesBuilder.substring(0, valuesBuilder.length() - VALUE_DEMARCATOR.length());
+ }
+ validStrings = validVals;
+
+ this.validValues = new ArrayList<>(validValues.size());
+ for (final AllowableValue value : validValues) {
+ this.validValues.add(value.getValue());
+ }
+ }
+
+ @Override
+ public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
+ final ValidationResult.Builder builder = new ValidationResult.Builder();
+ builder.input(input);
+ builder.subject(subject);
+ if (validValues.contains(input)) {
+ builder.valid(true);
+ builder.explanation(POSITIVE_EXPLANATION);
+ } else {
+ builder.valid(false);
+ builder.explanation(String.format(NEGATIVE_EXPLANATION, validStrings));
+ }
+ return builder.build();
+ }
+ }
+}