Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit cd3bf8f

Browse files
committed
Compiling version..
Untested as of yet. Also, will return "allowed" for all requests, any responses from the authorization endpoint are not evaluated yet.
1 parent 06184b8 commit cd3bf8f

File tree

2 files changed

+157
-0
lines changed

2 files changed

+157
-0
lines changed

pom.xml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>tech.stackable.nifi</groupId>
8+
<artifactId>webhook-authorizer</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<name>stackable</name>
12+
<!-- FIXME change it to the project's website -->
13+
<url>http://www.example.com</url>
14+
15+
<properties>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
<maven.compiler.source>1.7</maven.compiler.source>
18+
<maven.compiler.target>1.7</maven.compiler.target>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.apache.nifi</groupId>
24+
<artifactId>nifi-framework-api</artifactId>
25+
<version>1.13.2</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>com.google.code.gson</groupId>
29+
<artifactId>gson</artifactId>
30+
<version>2.8.7</version>
31+
</dependency>
32+
<dependency>
33+
<groupId>com.google.guava</groupId>
34+
<artifactId>guava</artifactId>
35+
<version>24.1.1-jre</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>junit</groupId>
39+
<artifactId>junit</artifactId>
40+
<version>4.11</version>
41+
<scope>test</scope>
42+
</dependency>
43+
</dependencies>
44+
45+
<build>
46+
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
47+
<plugins>
48+
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
49+
<plugin>
50+
<artifactId>maven-clean-plugin</artifactId>
51+
<version>3.1.0</version>
52+
</plugin>
53+
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
54+
<plugin>
55+
<artifactId>maven-resources-plugin</artifactId>
56+
<version>3.0.2</version>
57+
</plugin>
58+
<plugin>
59+
<artifactId>maven-compiler-plugin</artifactId>
60+
<version>3.8.0</version>
61+
</plugin>
62+
<plugin>
63+
<artifactId>maven-surefire-plugin</artifactId>
64+
<version>2.22.1</version>
65+
</plugin>
66+
<plugin>
67+
<artifactId>maven-jar-plugin</artifactId>
68+
<version>3.0.2</version>
69+
</plugin>
70+
<plugin>
71+
<artifactId>maven-install-plugin</artifactId>
72+
<version>2.5.2</version>
73+
</plugin>
74+
<plugin>
75+
<artifactId>maven-deploy-plugin</artifactId>
76+
<version>2.8.2</version>
77+
</plugin>
78+
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
79+
<plugin>
80+
<artifactId>maven-site-plugin</artifactId>
81+
<version>3.7.1</version>
82+
</plugin>
83+
<plugin>
84+
<artifactId>maven-project-info-reports-plugin</artifactId>
85+
<version>3.0.0</version>
86+
</plugin>
87+
</plugins>
88+
</pluginManagement>
89+
</build>
90+
</project>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package tech.stackable.nifi;
2+
3+
import com.google.gson.Gson;
4+
import org.apache.nifi.authorization.*;
5+
import org.apache.nifi.authorization.exception.AuthorizationAccessException;
6+
import org.apache.nifi.authorization.exception.AuthorizerCreationException;
7+
import org.apache.nifi.authorization.exception.AuthorizerDestructionException;
8+
import org.apache.nifi.components.PropertyValue;
9+
10+
import java.io.BufferedReader;
11+
import java.io.IOException;
12+
import java.io.InputStreamReader;
13+
import java.io.OutputStream;
14+
import java.net.HttpURLConnection;
15+
import java.net.URL;
16+
import java.util.Map;
17+
18+
public class WebhookAuthorizer implements Authorizer
19+
{
20+
private final Gson gson = new Gson();
21+
22+
private String webhookUrl;
23+
24+
@Override
25+
public AuthorizationResult authorize(AuthorizationRequest authorizationRequest) throws AuthorizationAccessException {
26+
try {
27+
HttpURLConnection conn = (HttpURLConnection) new URL(webhookUrl).openConnection();
28+
29+
conn.setDoOutput(true);
30+
conn.setRequestMethod("POST");
31+
conn.setRequestProperty("Content-Type", "application/json");
32+
33+
String data = gson.toJson(authorizationRequest);
34+
OutputStream os = conn.getOutputStream();
35+
os.write(data.getBytes());
36+
os.flush();
37+
38+
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
39+
Map test = gson.fromJson(br.readLine(), Map.class);
40+
} catch (IOException e) {
41+
e.printStackTrace();
42+
}
43+
44+
return AuthorizationResult.approved();
45+
46+
47+
}
48+
49+
@Override
50+
public void initialize(AuthorizerInitializationContext authorizerInitializationContext) throws AuthorizerCreationException {
51+
52+
}
53+
54+
@Override
55+
public void onConfigured(AuthorizerConfigurationContext authorizerConfigurationContext) throws AuthorizerCreationException {
56+
final PropertyValue authorizationEndpointUrl = authorizerConfigurationContext.getProperty("Authorizaten Endpoint URL");
57+
if (!authorizationEndpointUrl.isSet()) {
58+
throw new AuthorizerCreationException("'Authorizaten Endpoint URL' needs to be set!");
59+
}
60+
webhookUrl = authorizationEndpointUrl.getValue();
61+
}
62+
63+
@Override
64+
public void preDestruction() throws AuthorizerDestructionException {
65+
66+
}
67+
}

0 commit comments

Comments
 (0)