-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect if a txt file contains Json - closes #468
- Loading branch information
Showing
9 changed files
with
233 additions
and
42 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
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
82 changes: 82 additions & 0 deletions
82
...lorer-web/src/main/java/org/royllo/explorer/web/configuration/LnurlAuthConfiguration.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,82 @@ | ||
package org.royllo.explorer.web.configuration; | ||
|
||
import jakarta.servlet.ServletContext; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.SneakyThrows; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.security.core.userdetails.User; | ||
import org.springframework.security.core.userdetails.UserDetailsService; | ||
import org.springframework.security.provisioning.InMemoryUserDetailsManager; | ||
import org.springframework.stereotype.Controller; | ||
import org.tbk.lnurl.auth.InMemoryLnurlAuthPairingService; | ||
import org.tbk.lnurl.auth.K1Manager; | ||
import org.tbk.lnurl.auth.LnurlAuthFactory; | ||
import org.tbk.lnurl.auth.LnurlAuthPairingService; | ||
import org.tbk.lnurl.auth.SimpleK1Manager; | ||
import org.tbk.lnurl.auth.SimpleLnurlAuthFactory; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
/** | ||
* Configuration for LNURL-auth. | ||
*/ | ||
@Controller | ||
@RequiredArgsConstructor | ||
@SuppressWarnings({"checkstyle:DesignForExtension"}) | ||
public class LnurlAuthConfiguration { | ||
|
||
/** | ||
* This factory creates a LNURL-auth callback url for the given k1. | ||
* | ||
* @param k1Manager k1 manager | ||
* @param servletContext servlet context | ||
* @return lnurl auth factory | ||
*/ | ||
@Bean | ||
@SneakyThrows(URISyntaxException.class) | ||
LnurlAuthFactory lnurlAuthFactory(final K1Manager k1Manager, | ||
final ServletContext servletContext) { | ||
URI callbackUrl = new URI(servletContext.getContextPath() + "/api/v1/lnurl/auth/callback"); | ||
return new SimpleLnurlAuthFactory(callbackUrl, k1Manager); | ||
} | ||
|
||
/** | ||
* This service acts like a user detail service for LNURL-auth. | ||
* It has two methods to see if a k1 is paired with a linking key and to find a linking key by k1. | ||
* boolean pairK1WithLinkingKey(K1 k1, LinkingKey linkingKey); | ||
* Optional<LinkingKey> findPairedLinkingKeyByK1(K1 k1); | ||
* | ||
* @return lnurl auth security service | ||
*/ | ||
@Bean | ||
LnurlAuthPairingService lnurlAuthSecurityService() { | ||
// TODO Implement this. | ||
return new InMemoryLnurlAuthPairingService(); | ||
} | ||
|
||
/** | ||
* K1 manager. "k1" refers to a one-time, randomly generated key or token. | ||
* | ||
* @return k1 manager | ||
*/ | ||
@Bean | ||
SimpleK1Manager k1Manager() { | ||
return new SimpleK1Manager(); | ||
} | ||
|
||
@Bean | ||
public UserDetailsService userDetailsService() { | ||
// The primary purpose of the UserDetailsService is to load user-specific data. | ||
// It is used by the AuthenticationManager to authenticate a user during the login process. | ||
// When a username and password are submitted (e.g., via a login form), Spring Security's AuthenticationManager | ||
// uses the UserDetailsService to load the user details. | ||
InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); | ||
manager.createUser(User.withUsername("user") | ||
.password("{bcrypt}$2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG") | ||
.roles("USER") | ||
.build()); | ||
return manager; | ||
} | ||
|
||
} |
Oops, something went wrong.