-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MRESOLVER-495] Improve Authentication to work based on realm/host
WIP
- Loading branch information
Showing
5 changed files
with
136 additions
and
6 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
maven-resolver-api/src/main/java/org/eclipse/aether/repository/AuthenticationScope.java
This file contains 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,53 @@ | ||
package org.eclipse.aether.repository; | ||
|
||
import java.net.URI; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Allows to restrict authentication information to certain URIs (optionally considering additional attributes). | ||
* This class encapsulates the restrictions in terms of | ||
* <ol> | ||
* <li>mandatory host pattern</li> | ||
* <li>optional port</li> | ||
* <li>optional protocol</li> | ||
* <li>optional scheme</li> | ||
* <li>optional realm</li> | ||
* <ol> | ||
*/ | ||
public class AuthenticationScope { | ||
|
||
private final Pattern hostPattern; // mandatory | ||
private final int port; // optional, -1 if not relevant | ||
private final String protocol; // protocol, null of not relevant | ||
private final String scheme; // scheme, null of not relevant | ||
private final String realm; // realm, null of not relevant | ||
|
||
public AuthenticationScope(Pattern hostPattern, int port, String protocol, String scheme, String realm) { | ||
this.hostPattern = hostPattern; | ||
this.port = port; | ||
this.protocol = protocol; | ||
this.scheme = scheme; | ||
this.realm = realm; | ||
} | ||
|
||
public boolean isMatching(URI uri, String scheme, String realm) { | ||
Matcher hostMatcher = hostPattern.matcher(uri.getHost()); | ||
if (!hostMatcher.matches()) { | ||
return false; | ||
} | ||
if (port != -1 && uri.getPort() != port) { | ||
return false; | ||
} | ||
if (protocol != null && !uri.getScheme().equals(protocol)) { | ||
return false; | ||
} | ||
if (this.scheme != null && !this.scheme.equals(scheme)) { | ||
return false; | ||
} | ||
if (this.realm != null && !this.realm.equals(realm)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
This file contains 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
40 changes: 40 additions & 0 deletions
40
maven-resolver-api/src/main/java/org/eclipse/aether/repository/AuthenticationSelectorV2.java
This file contains 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,40 @@ | ||
/* | ||
* 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.eclipse.aether.repository; | ||
|
||
import java.net.URI; | ||
|
||
/** | ||
* Selects authentication for a given remote repository. | ||
* | ||
* @see org.eclipse.aether.RepositorySystemSession#getAuthenticationSelector() | ||
*/ | ||
public interface AuthenticationSelectorV2 { | ||
|
||
/** | ||
* Selects authentication for the specified URI, scheme and realm. | ||
* | ||
* @param uri the URI of the request for which to select the authentication, must not be {@code null}. | ||
* @param scheme the authentication scheme being requested (may be {@code null}), for HTTP one of the names outlined at <a href="https://www.iana.org/assignments/http-authschemes/http-authschemes.xhtml">Hypertext Transfer Protocol (HTTP) Authentication Scheme Registry</a> | ||
* @param realm the authentication realm being requested (may be {@code null}) | ||
* | ||
* @return The selected authentication or {@code null} if none. | ||
*/ | ||
Authentication getAuthentication(URI uri, String scheme, String realm); | ||
} |
This file contains 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
7 changes: 7 additions & 0 deletions
7
...-resolver-util/src/main/java/org/eclipse/aether/util/repository/DefaultAuthenticator.java
This file contains 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,7 @@ | ||
package org.eclipse.aether.util.repository; | ||
|
||
import javax.naming.AuthenticationException; | ||
|
||
public class DefaultAuthenticator extends Authenticator { | ||
|
||
} |