You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/11/09 09:59:53 UTC

[camel] branch main updated: [CAMEL-18684]: Add Microsoft Exchange Online OAuth2 Mail Authenticator (#8691)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new baddc933a7d [CAMEL-18684]: Add Microsoft Exchange Online OAuth2 Mail Authenticator (#8691)
baddc933a7d is described below

commit baddc933a7d3efead688985ad77e47b9600728f5
Author: Luigi De Masi <55...@users.noreply.github.com>
AuthorDate: Wed Nov 9 10:59:45 2022 +0100

    [CAMEL-18684]: Add Microsoft Exchange Online OAuth2 Mail Authenticator (#8691)
    
    moved authenticator to a new module
---
 catalog/camel-allcomponents/pom.xml                |  4 ++
 components/camel-mail-microsoft-oauth/pom.xml      | 52 ++++++++++++++++++++
 .../src/main/docs/mail-microsoft-oauth.adoc        | 57 ++++++++++++++++++++++
 ...osoftExchangeOnlineOAuth2MailAuthenticator.java |  7 ++-
 components/camel-mail/pom.xml                      |  6 ---
 .../camel-mail/src/main/docs/mail-component.adoc   | 26 ----------
 components/pom.xml                                 |  1 +
 parent/pom.xml                                     |  5 ++
 8 files changed, 125 insertions(+), 33 deletions(-)

diff --git a/catalog/camel-allcomponents/pom.xml b/catalog/camel-allcomponents/pom.xml
index 1dfce784027..a6de09655bd 100644
--- a/catalog/camel-allcomponents/pom.xml
+++ b/catalog/camel-allcomponents/pom.xml
@@ -929,6 +929,10 @@
 			<groupId>org.apache.camel</groupId>
 			<artifactId>camel-lzf</artifactId>
 		</dependency>
+		<dependency>
+			<groupId>org.apache.camel</groupId>
+			<artifactId>camel-mail-microsoft-oauth</artifactId>
+		</dependency>
 		<dependency>
 			<groupId>org.apache.camel</groupId>
 			<artifactId>camel-mail</artifactId>
diff --git a/components/camel-mail-microsoft-oauth/pom.xml b/components/camel-mail-microsoft-oauth/pom.xml
new file mode 100644
index 00000000000..e7857dfbc1a
--- /dev/null
+++ b/components/camel-mail-microsoft-oauth/pom.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <parent>
+        <groupId>org.apache.camel</groupId>
+        <artifactId>components</artifactId>
+        <version>3.20.0-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>camel-mail-microsoft-oauth</artifactId>
+    <packaging>jar</packaging>
+    <name>Camel :: Mail :: Microsoft OAuth</name>
+    <description>Camel Mail OAuth2 Authenticator for Microsoft Exchange Online</description>
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <properties>
+        <firstVersion>3.18.4</firstVersion>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-mail</artifactId>
+        </dependency>
+
+        <!--Microsoft Authentication Library for Java  -->
+        <dependency>
+            <groupId>com.microsoft.azure</groupId>
+            <artifactId>msal4j</artifactId>
+        </dependency>
+    </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/components/camel-mail-microsoft-oauth/src/main/docs/mail-microsoft-oauth.adoc b/components/camel-mail-microsoft-oauth/src/main/docs/mail-microsoft-oauth.adoc
new file mode 100644
index 00000000000..b1481478d68
--- /dev/null
+++ b/components/camel-mail-microsoft-oauth/src/main/docs/mail-microsoft-oauth.adoc
@@ -0,0 +1,57 @@
+= Mail Microsoft Oauth Component
+:doctitle: Mail Microsoft Oauth
+:shortname: mail-microsoft-oauth
+:artifactid: camel-mail-microsoft-oauth
+:description: Camel Mail OAuth2 Authenticator for Microsoft Exchange Online
+:since: 3.18.4
+:supportlevel: Stable
+
+//Manually maintained attributes
+:camel-spring-boot-name: mail-microsoft-oauth
+
+*Since Camel {since}*
+
+
+The Mail Microsoft OAuth2 provides an implementation of `org.apache.camel.component.mail.MailAuthenticator` to authenticate IMAP/POP/SMTP connections and access to Email via Spring's Mail support and the underlying JavaMail system.
+
+Maven users will need to add the following dependency to their `pom.xml`
+for this component:
+
+[source,xml]
+------------------------------------------------------------
+<dependency>
+    <groupId>org.apache.camel</groupId>
+    <artifactId>camel-mail-microsoft-oauth</artifactId>
+    <version>x.x.x</version>
+    <!-- use the same version as your Camel core version -->
+</dependency>
+------------------------------------------------------------
+
+Importing `camel-mail-microsoft-oauth` it will automatically import camel-mail component.
+
+
+== Microsoft Exchange Online OAuth2 Mail Authenticator IMAP sample
+To use OAuth, an application must be registered with Azure Active Directory.
+Follow the instructions listed in https://learn.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app[Register an application with the Microsoft identity platform] guide to register a new application. +
+Enable application to access Exchange mailboxes via client credentials flow. Instructions https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth[here] +
+Once everything is set up, declare and register in the registry, an instance of `+org.apache.camel.component.mail.MicrosoftExchangeOnlineOAuth2MailAuthenticator+`. +
+For Example in a Spring Boot application:
+
+[source,java]
+---------------------------------------------------------------------------------
+@BindToRegistry("auth")
+public MicrosoftExchangeOnlineOAuth2MailAuthenticator exchangeAuthenticator(){
+    return new MicrosoftExchangeOnlineOAuth2MailAuthenticator(tenantId, clientId, clientSecret, "jon@doe.com");
+}
+---------------------------------------------------------------------------------
+
+and then reference it in the Camel URI:
+
+[source,java]
+---------------------------------------------------------------------------------------
+ from("imaps://outlook.office365.com:993"
+                    +  "?authenticator=#auth"
+                    +  "&mail.imaps.auth.mechanisms=XOAUTH2"
+                    +  "&debugMode=true"
+                    +  "&delete=false")
+---------------------------------------------------------------------------------------
diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MicrosoftExchangeOnlineOAuth2MailAuthenticator.java b/components/camel-mail-microsoft-oauth/src/main/java/org/apache/camel/component/mail/microsoft/authenticator/MicrosoftExchangeOnlineOAuth2MailAuthenticator.java
similarity index 95%
rename from components/camel-mail/src/main/java/org/apache/camel/component/mail/MicrosoftExchangeOnlineOAuth2MailAuthenticator.java
rename to components/camel-mail-microsoft-oauth/src/main/java/org/apache/camel/component/mail/microsoft/authenticator/MicrosoftExchangeOnlineOAuth2MailAuthenticator.java
index 6aaded69117..c94e62d1753 100644
--- a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MicrosoftExchangeOnlineOAuth2MailAuthenticator.java
+++ b/components/camel-mail-microsoft-oauth/src/main/java/org/apache/camel/component/mail/microsoft/authenticator/MicrosoftExchangeOnlineOAuth2MailAuthenticator.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.component.mail;
+package org.apache.camel.component.mail.microsoft.authenticator;
 
 import java.net.MalformedURLException;
 import java.util.Collections;
@@ -28,7 +28,12 @@ import com.microsoft.aad.msal4j.ConfidentialClientApplication;
 import com.microsoft.aad.msal4j.IAuthenticationResult;
 import com.microsoft.aad.msal4j.IClientCredential;
 import com.microsoft.aad.msal4j.IConfidentialClientApplication;
+import org.apache.camel.component.mail.MailAuthenticator;
 
+/**
+ * This Mail Authenticator is intended for users of Microsoft Exchange Online that use an Azure Active Directory
+ * instance as Identity Provider and OAuth2 Client Credential Flow as Authentication protocol.
+ */
 public class MicrosoftExchangeOnlineOAuth2MailAuthenticator extends MailAuthenticator {
 
     /**
diff --git a/components/camel-mail/pom.xml b/components/camel-mail/pom.xml
index d3cda7bcc9b..25e49ca9cea 100644
--- a/components/camel-mail/pom.xml
+++ b/components/camel-mail/pom.xml
@@ -59,12 +59,6 @@
             </exclusions>
         </dependency>
 
-        <!--Microsoft Authentication Library for Java  -->
-        <dependency>
-            <groupId>com.microsoft.azure</groupId>
-            <artifactId>msal4j</artifactId>
-        </dependency>
-
         <!-- testing -->
         <dependency>
             <groupId>org.apache.camel</groupId>
diff --git a/components/camel-mail/src/main/docs/mail-component.adoc b/components/camel-mail/src/main/docs/mail-component.adoc
index b1cd4b23f13..d0f5fcfd9b2 100644
--- a/components/camel-mail/src/main/docs/mail-component.adoc
+++ b/components/camel-mail/src/main/docs/mail-component.adoc
@@ -445,32 +445,6 @@ As you can see the API to handle attachments is a bit clunky but it's
 there so you can get the `javax.activation.DataHandler` so you can
 handle the attachments using standard API.
 
-== Microsoft Exchange Online OAuth2 Mail Authenticator sample
-To use OAuth, an application must be registered with Azure Active Directory.
-Follow the instructions listed in https://learn.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app[Register an application with the Microsoft identity platform] guide to register a new application. +
-Enable application to access Exchange mailboxes via client credentials flow. Instructions https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth[here] +
-Once everything is set up, declare and register in the registry, an instance of `+org.apache.camel.component.mail.MicrosoftExchangeOnlineOAuth2MailAuthenticator+`. +
-For Example in a Spring Boot application:
-
-[source,java]
----------------------------------------------------------------------------------
-@Bean("auth")
-public MicrosoftExchangeOnlineOAuth2MailAuthenticator exchangeAuthenticator(){
-    return new MicrosoftExchangeOnlineOAuth2MailAuthenticator(tenantId, clientId, clientSecret, "jon@doe.com");
-}
----------------------------------------------------------------------------------
-
-and then reference it in the Camel URI:
-
-[source,java]
----------------------------------------------------------------------------------------
- from("imaps://outlook.office365.com:993"
-                    +  "?authenticator=#auth"
-                    +  "&mail.imaps.auth.mechanisms=XOAUTH2"
-                    +  "&debugMode=true"
-                    +  "&delete=false")
----------------------------------------------------------------------------------------
-
 == How to split a mail message with attachments
 
 In this example we consume mail messages which may have a number of
diff --git a/components/pom.xml b/components/pom.xml
index cd488fed7f5..e2c788c1d47 100644
--- a/components/pom.xml
+++ b/components/pom.xml
@@ -219,6 +219,7 @@
         <module>camel-lumberjack</module>
         <module>camel-lzf</module>
         <module>camel-mail</module>
+        <module>camel-mail-microsoft-oauth</module>
         <module>camel-mapstruct</module>
         <module>camel-metrics</module>
         <module>camel-micrometer</module>
diff --git a/parent/pom.xml b/parent/pom.xml
index 679e9943882..1bd4f9ddd62 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -1976,6 +1976,11 @@
 				<artifactId>camel-lzf</artifactId>
 				<version>${project.version}</version>
 			</dependency>
+			<dependency>
+				<groupId>org.apache.camel</groupId>
+				<artifactId>camel-mail-microsoft-oauth</artifactId>
+				<version>${project.version}</version>
+			</dependency>
 			<dependency>
 				<groupId>org.apache.camel</groupId>
 				<artifactId>camel-mail</artifactId>