-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #11560 - Implement EIP-4361 Sign-In With Ethereum
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
- Loading branch information
1 parent
bc03176
commit 144710b
Showing
22 changed files
with
2,337 additions
and
3 deletions.
There are no files selected for viewing
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
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
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
152 changes: 152 additions & 0 deletions
152
jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/MultiPartFormFields.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,152 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.server; | ||
|
||
import java.io.File; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import org.eclipse.jetty.http.ComplianceViolation; | ||
import org.eclipse.jetty.http.HttpField; | ||
import org.eclipse.jetty.http.HttpHeader; | ||
import org.eclipse.jetty.http.MimeTypes; | ||
import org.eclipse.jetty.http.MultiPart; | ||
import org.eclipse.jetty.http.MultiPartCompliance; | ||
import org.eclipse.jetty.http.MultiPartFormData; | ||
import org.eclipse.jetty.io.Content; | ||
import org.eclipse.jetty.util.Attributes; | ||
import org.eclipse.jetty.util.StringUtil; | ||
|
||
public class MultiPartFormFields | ||
{ | ||
public static class Config | ||
{ | ||
private final long fileSizeThreshold; | ||
private final long maxFileSize; | ||
private final long maxRequestSize; | ||
private final int maxFormKeys; | ||
private final File tempDir; | ||
private final String location; | ||
|
||
public Config(int maxFormKeys, long maxRequestSize, long maxFileSize, long fileSizeThreshold, String location, File tempDir) | ||
{ | ||
this.location = location; | ||
this.tempDir = tempDir; | ||
this.maxFormKeys = maxFormKeys; | ||
this.maxRequestSize = maxRequestSize; | ||
this.maxFileSize = maxFileSize; | ||
this.fileSizeThreshold = fileSizeThreshold; | ||
} | ||
|
||
public long getFileSizeThreshold() | ||
{ | ||
return fileSizeThreshold; | ||
} | ||
|
||
public long getMaxFileSize() | ||
{ | ||
return maxFileSize; | ||
} | ||
|
||
public long getMaxRequestSize() | ||
{ | ||
return maxRequestSize; | ||
} | ||
|
||
public int getMaxFormKeys() | ||
{ | ||
return maxFormKeys; | ||
} | ||
|
||
public File getTempDirectory() | ||
{ | ||
return tempDir; | ||
} | ||
|
||
public String getLocation() | ||
{ | ||
return location; | ||
} | ||
} | ||
|
||
public static CompletableFuture<MultiPartFormData.Parts> from(Request request, Config config) | ||
{ | ||
return from(request, request, config); | ||
} | ||
|
||
public static CompletableFuture<MultiPartFormData.Parts> from(Request request, Content.Source source, Config config) | ||
{ | ||
String contentType = request.getHeaders().get(HttpHeader.CONTENT_TYPE); | ||
HttpChannel httpChannel = HttpChannel.from(request); | ||
ComplianceViolation.Listener complianceViolationListener = httpChannel.getComplianceViolationListener(); | ||
HttpConfiguration httpConfiguration = request.getConnectionMetaData().getHttpConfiguration(); | ||
return from(source, request, contentType, config, httpConfiguration, complianceViolationListener); | ||
} | ||
|
||
public static CompletableFuture<MultiPartFormData.Parts> from(Content.Source content, Attributes attributes, String contentType, Config config, HttpConfiguration httpConfiguration, ComplianceViolation.Listener violationListener) | ||
{ | ||
// Look for an existing future (we use the future here rather than the parts as it can remember any failure). | ||
CompletableFuture<MultiPartFormData.Parts> futureParts = MultiPartFormData.get(attributes); | ||
if (futureParts == null) | ||
{ | ||
// No existing parts, so we need to try to read them ourselves | ||
|
||
// Are we the right content type to produce our own parts? | ||
if (contentType == null || !MimeTypes.Type.MULTIPART_FORM_DATA.is(HttpField.getValueParameters(contentType, null))) | ||
return CompletableFuture.failedFuture(new IllegalStateException("Not multipart Content-Type")); | ||
|
||
// Do we have a boundary? | ||
String boundary = MultiPart.extractBoundary(contentType); | ||
if (boundary == null) | ||
return CompletableFuture.failedFuture(new IllegalStateException("No multipart boundary parameter in Content-Type")); | ||
|
||
// Get a temporary directory for larger parts. | ||
File filesDirectory; | ||
boolean locationIsBlank = StringUtil.isBlank(config.getLocation()); | ||
if (locationIsBlank && config.getTempDirectory() == null) | ||
filesDirectory = null; | ||
else | ||
{ | ||
filesDirectory = locationIsBlank | ||
? config.getTempDirectory() | ||
: new File(config.getLocation()); | ||
} | ||
|
||
MultiPartCompliance compliance = httpConfiguration.getMultiPartCompliance(); | ||
|
||
// Look for an existing future MultiPartFormData.Parts | ||
futureParts = MultiPartFormData.from(attributes, compliance, violationListener, boundary, parser -> | ||
{ | ||
try | ||
{ | ||
// No existing core parts, so we need to configure the parser. | ||
parser.setMaxParts(config.getMaxFormKeys()); | ||
parser.setMaxMemoryFileSize(config.getFileSizeThreshold()); | ||
parser.setMaxFileSize(config.getMaxFileSize()); | ||
parser.setMaxLength(config.getMaxRequestSize()); | ||
parser.setPartHeadersMaxLength(httpConfiguration.getRequestHeaderSize()); | ||
if (filesDirectory != null) | ||
parser.setFilesDirectory(filesDirectory.toPath()); | ||
|
||
// parse the core parts. | ||
return parser.parse(content); | ||
} | ||
catch (Throwable failure) | ||
{ | ||
return CompletableFuture.failedFuture(failure); | ||
} | ||
}); | ||
} | ||
return futureParts; | ||
} | ||
} |
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
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,118 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-core</artifactId> | ||
<version>12.0.10-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>jetty-siwe</artifactId> | ||
<name>Core :: Sign-In with Ethereum</name> | ||
<description>Jetty Sign-In with Ethereum</description> | ||
|
||
<properties> | ||
<bundle-symbolic-name>${project.groupId}.siwe</bundle-symbolic-name> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib-common</artifactId> | ||
<version>1.9.10</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib-jdk7</artifactId> | ||
<version>1.9.10</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib-jdk8</artifactId> | ||
<version>1.9.10</version> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.bouncycastle</groupId> | ||
<artifactId>bcprov-jdk15to18</artifactId> | ||
<version>1.78.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-client</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-security</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-server</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-util-ajax</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.web3j</groupId> | ||
<artifactId>core</artifactId> | ||
<version>4.12.0</version> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
</exclusion> | ||
<exclusion> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-session</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-slf4j-impl</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty.toolchain</groupId> | ||
<artifactId>jetty-test-helper</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>maven-bundle-plugin</artifactId> | ||
<extensions>true</extensions> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>manifest</goal> | ||
</goals> | ||
<configuration> | ||
<instructions> | ||
<Require-Capability>osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)"</Require-Capability> | ||
<Provide-Capability>osgi.serviceloader;osgi.serviceloader=org.eclipse.jetty.security.Authenticator$Factory</Provide-Capability> | ||
</instructions> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
70 changes: 70 additions & 0 deletions
70
jetty-core/jetty-siwe/src/main/java/org/eclipse/jetty/security/siwe/AnyUserLoginService.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,70 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.security.siwe; | ||
|
||
import java.util.function.Function; | ||
import javax.security.auth.Subject; | ||
|
||
import org.eclipse.jetty.security.DefaultIdentityService; | ||
import org.eclipse.jetty.security.IdentityService; | ||
import org.eclipse.jetty.security.LoginService; | ||
import org.eclipse.jetty.security.UserIdentity; | ||
import org.eclipse.jetty.security.UserPrincipal; | ||
import org.eclipse.jetty.server.Request; | ||
import org.eclipse.jetty.server.Session; | ||
|
||
public class AnyUserLoginService implements LoginService | ||
{ | ||
private IdentityService identityService = new DefaultIdentityService(); | ||
|
||
@Override | ||
public String getName() | ||
{ | ||
return "ANY_USER"; | ||
} | ||
|
||
@Override | ||
public UserIdentity login(String username, Object credentials, Request request, Function<Boolean, Session> getOrCreateSession) | ||
{ | ||
UserPrincipal principal = new UserPrincipal(username, null); | ||
Subject subject = new Subject(); | ||
subject.getPrincipals().add(principal); | ||
subject.setReadOnly(); | ||
return identityService.newUserIdentity(subject, principal, new String[0]); | ||
} | ||
|
||
@Override | ||
public boolean validate(UserIdentity user) | ||
{ | ||
return user != null; | ||
} | ||
|
||
@Override | ||
public IdentityService getIdentityService() | ||
{ | ||
return identityService; | ||
} | ||
|
||
@Override | ||
public void setIdentityService(IdentityService service) | ||
{ | ||
identityService = service; | ||
} | ||
|
||
@Override | ||
public void logout(UserIdentity user) | ||
{ | ||
// Do nothing. | ||
} | ||
} |
Oops, something went wrong.