-
Notifications
You must be signed in to change notification settings - Fork 486
JAMES-4210 Generic SASL mechanism extension #3059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
quantranhong1999
wants to merge
29
commits into
apache:master
Choose a base branch
from
quantranhong1999:sasl-modularize
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
8485783
JAMES-4210 Introduce shared SASL SPI
quantranhong1999 7599d28
JAMES-4210 Add IMAP SASL bridge scaffold
quantranhong1999 4adec8f
JAMES-4210 Add SMTP SASL bridge scaffold
quantranhong1999 9b05af7
JAMES-4210 Introduce SASL mechanism registry
quantranhong1999 84cffd0
JAMES-4210 Implement GuiceSaslMechanismLoader
quantranhong1999 963b836
JAMES-4210 Add protocol-neutral SASL mechanisms
quantranhong1999 e214f0a
JAMES-4210 Route IMAP AUTHENTICATE through SASL mechanisms
quantranhong1999 46a64e4
JAMES-4210 Load IMAP SASL mechanisms from configuration
quantranhong1999 52573c6
JAMES-4210 Prepare SMTP SASL bridge reuse for LMTP
quantranhong1999 77cc2b9
JAMES-4210 Allow IMAP SASL provider extensions from configuration
quantranhong1999 cb204cf
JAMES-4210 Add custom IMAP SASL extension example
quantranhong1999 b285452
JAMES-4210 Custom IMAP SASL extension example: add a conditional cont…
quantranhong1999 8bc52cc
JAMES-4210 Custom IMAP SASL extension example: strengthen test case f…
quantranhong1999 542f0b8
JAMES-4210 Simplify SASL SPI around exchanges and credentials
quantranhong1999 5a508bd
JAMES-4210 Add Guice resolver for configured SASL mechanisms
quantranhong1999 b038b9d
JAMES-4210 Adapt IMAP AUTHENTICATE to SASL exchanges
quantranhong1999 cd163dc
JAMES-4210 Wire per-server IMAP SASL mechanism configuration
quantranhong1999 c889aa9
JAMES-4210 Drop obsolete SMTP SASL bridge skeleton
quantranhong1999 9cf926e
JAMES-4210 Update custom IMAP SASL example to the new SPI
quantranhong1999 8eb8150
JAMES-4210 Introduce protocol-neutral SASL authentication SPI
quantranhong1999 6e4e54e
JAMES-4210 Move built-in SASL mechanisms to shared protocol module
quantranhong1999 6bd025c
JAMES-4210 Add Guice SASL mechanism factory resolution
quantranhong1999 ce48137
JAMES-4210 Adapt IMAP authentication to SASL-owned authentication
quantranhong1999 e580849
JAMES-4210 Wire per-server IMAP SASL mechanism configuration
quantranhong1999 6111259
JAMES-4210 Remove IMAP authentication configuration from Netty sessio…
quantranhong1999 3f0a554
JAMES-4210 Update custom IMAP SASL example to factory-based SPI
quantranhong1999 90848da
JAMES-4210 [FIX] IMAP Login/plain authentication should preserve logg…
quantranhong1999 620d567
JAMES-4210 Move JamesSaslAuthenticator initialization out of DefaultP…
quantranhong1999 b30dd7f
JAMES-4210 Merge OAuthSaslMechanism
quantranhong1999 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...imap/src/main/java/org/apache/james/examples/imap/sasl/ExampleTokenSaslConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /**************************************************************** | ||
| * 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.james.examples.imap.sasl; | ||
|
|
||
| import org.apache.commons.configuration2.HierarchicalConfiguration; | ||
| import org.apache.commons.configuration2.ex.ConfigurationException; | ||
| import org.apache.commons.configuration2.tree.ImmutableNode; | ||
| import org.apache.james.core.Username; | ||
|
|
||
| public record ExampleTokenSaslConfiguration(String expectedToken, Username authorizedUser) { | ||
| private static final String EXPECTED_TOKEN_PROPERTY = "auth.exampleToken.expectedToken"; | ||
| private static final String AUTHORIZED_USER_PROPERTY = "auth.exampleToken.authorizedUser"; | ||
|
|
||
| public static ExampleTokenSaslConfiguration from(HierarchicalConfiguration<ImmutableNode> configuration) throws ConfigurationException { | ||
| if (!configuration.containsKey(EXPECTED_TOKEN_PROPERTY)) { | ||
| throw new ConfigurationException(EXPECTED_TOKEN_PROPERTY + " is mandatory"); | ||
| } | ||
| if (!configuration.containsKey(AUTHORIZED_USER_PROPERTY)) { | ||
| throw new ConfigurationException(AUTHORIZED_USER_PROPERTY + " is mandatory"); | ||
| } | ||
|
|
||
| return new ExampleTokenSaslConfiguration( | ||
| configuration.getString(EXPECTED_TOKEN_PROPERTY), | ||
| Username.of(configuration.getString(AUTHORIZED_USER_PROPERTY))); | ||
| } | ||
| } |
99 changes: 99 additions & 0 deletions
99
...tom-imap/src/main/java/org/apache/james/examples/imap/sasl/ExampleTokenSaslMechanism.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| /**************************************************************** | ||
| * 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.james.examples.imap.sasl; | ||
|
|
||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.Optional; | ||
|
|
||
| import org.apache.james.protocols.api.sasl.SaslAuthenticator; | ||
| import org.apache.james.protocols.api.sasl.SaslExchange; | ||
| import org.apache.james.protocols.api.sasl.SaslFailure; | ||
| import org.apache.james.protocols.api.sasl.SaslIdentity; | ||
| import org.apache.james.protocols.api.sasl.SaslInitialRequest; | ||
| import org.apache.james.protocols.api.sasl.SaslMechanism; | ||
| import org.apache.james.protocols.api.sasl.SaslStep; | ||
|
|
||
| public class ExampleTokenSaslMechanism implements SaslMechanism { | ||
| public static final String NAME = "EXAMPLE-TOKEN"; | ||
| public static final String CONTINUATION_PROMPT = "Go ahead"; | ||
| public static final String SUCCESS_DATA_TOKEN_SUFFIX = ":server-data"; | ||
| public static final String SUCCESS_DATA = "Token accepted"; | ||
|
|
||
| private final ExampleTokenSaslConfiguration configuration; | ||
|
|
||
| public ExampleTokenSaslMechanism(ExampleTokenSaslConfiguration configuration) { | ||
| this.configuration = configuration; | ||
| } | ||
|
|
||
| @Override | ||
| public String name() { | ||
| return NAME; | ||
| } | ||
|
|
||
| @Override | ||
| public SaslExchange start(SaslInitialRequest request, SaslAuthenticator authenticator) { | ||
| Optional<byte[]> initialResponse = request.initialResponse(); | ||
| return new ExampleTokenSaslExchange(initialResponse, configuration); | ||
| } | ||
|
|
||
| private static class ExampleTokenSaslExchange implements SaslExchange { | ||
| private final Optional<byte[]> initialResponse; | ||
| private final ExampleTokenSaslConfiguration configuration; | ||
|
|
||
| private ExampleTokenSaslExchange(Optional<byte[]> initialResponse, ExampleTokenSaslConfiguration configuration) { | ||
| this.initialResponse = initialResponse; | ||
| this.configuration = configuration; | ||
| } | ||
|
|
||
| @Override | ||
| public SaslStep firstStep() { | ||
| return initialResponse | ||
| .map(this::authenticate) | ||
| .orElseGet(() -> new SaslStep.Challenge(Optional.of(CONTINUATION_PROMPT | ||
| .getBytes(StandardCharsets.UTF_8)))); | ||
| } | ||
|
|
||
| @Override | ||
| public SaslStep onResponse(byte[] clientResponse) { | ||
| return authenticate(clientResponse); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| } | ||
|
|
||
| private SaslStep authenticate(byte[] clientResponse) { | ||
| String token = new String(clientResponse, StandardCharsets.UTF_8); | ||
| if (configuration.expectedToken().equals(token)) { | ||
| return success(Optional.empty()); | ||
| } | ||
| // allow client to request server to return data on success message, which may be used by Kerberos auth | ||
| if ((configuration.expectedToken() + SUCCESS_DATA_TOKEN_SUFFIX).equals(token)) { | ||
| return success(Optional.of(SUCCESS_DATA.getBytes(StandardCharsets.UTF_8))); | ||
| } | ||
| return new SaslStep.Failure(SaslFailure.authenticationFailed(Optional.empty(), Optional.of(configuration.authorizedUser()), | ||
| "EXAMPLE-TOKEN authentication failed.")); | ||
| } | ||
|
|
||
| private SaslStep success(Optional<byte[]> serverData) { | ||
| return new SaslStep.Success(new SaslIdentity(configuration.authorizedUser(), configuration.authorizedUser()), serverData); | ||
| } | ||
| } | ||
| } | ||
33 changes: 33 additions & 0 deletions
33
...p/src/main/java/org/apache/james/examples/imap/sasl/ExampleTokenSaslMechanismFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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.james.examples.imap.sasl; | ||
|
|
||
| import org.apache.commons.configuration2.HierarchicalConfiguration; | ||
| import org.apache.commons.configuration2.ex.ConfigurationException; | ||
| import org.apache.commons.configuration2.tree.ImmutableNode; | ||
| import org.apache.james.protocols.api.sasl.SaslMechanism; | ||
| import org.apache.james.protocols.api.sasl.SaslMechanismFactory; | ||
|
|
||
| public class ExampleTokenSaslMechanismFactory implements SaslMechanismFactory { | ||
| @Override | ||
| public SaslMechanism create(HierarchicalConfiguration<ImmutableNode> serverConfiguration) throws ConfigurationException { | ||
| return new ExampleTokenSaslMechanism(ExampleTokenSaslConfiguration.from(serverConfiguration)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.