forked from oktadev/auth0-java-rest-api-examples
-
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.
From oktadev#43
- Loading branch information
Showing
16 changed files
with
119 additions
and
230 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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
56 changes: 46 additions & 10 deletions
56
helidon/src/main/java/com/okta/rest/HelloApplication.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 |
---|---|---|
@@ -1,19 +1,55 @@ | ||
package com.okta.rest; | ||
|
||
import java.net.URI; | ||
|
||
import com.okta.rest.controller.HelloResource; | ||
import org.eclipse.microprofile.auth.LoginConfig; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.ws.rs.core.Application; | ||
import io.helidon.common.configurable.Resource; | ||
import io.helidon.config.Config; | ||
import io.helidon.security.Security; | ||
import io.helidon.security.providers.jwt.JwtProvider; | ||
import io.helidon.webserver.WebServer; | ||
import io.helidon.webserver.context.ContextFeature; | ||
import io.helidon.webserver.http.HttpRouting; | ||
import io.helidon.webserver.security.SecurityFeature; | ||
|
||
public class HelloApplication { | ||
|
||
public static void main(String[] args) { | ||
|
||
import java.util.Set; | ||
var config = Config.global(); | ||
var oauth = | ||
JwtProvider.builder() | ||
.issuer(config.get("se.jwt.verify.issuer").asString().get()) | ||
.verifyJwk( | ||
Resource.create( | ||
config | ||
.get("se.jwt.verify.publickey.location") | ||
.asString() | ||
.map(URI::create) | ||
.orElseThrow())) | ||
.build(); | ||
|
||
@LoginConfig(authMethod = "MP-JWT") | ||
@ApplicationScoped | ||
public class HelloApplication extends Application { | ||
Security security = Security.builder().addProvider(oauth).build(); | ||
var securityFeature = | ||
SecurityFeature.create( | ||
sfb -> | ||
sfb.security(security) | ||
.addPath(p -> p.path("/hello").handler(h -> h.authenticate(true)))); | ||
|
||
WebServer.builder() | ||
.config(config.get("server")) | ||
.routing(HelloApplication::routing) | ||
.addFeature(ContextFeature.create()) | ||
.addFeature(securityFeature) | ||
.build() | ||
.start(); | ||
} | ||
|
||
@Override | ||
public Set<Class<?>> getClasses() { | ||
return Set.of(HelloResource.class); | ||
/** | ||
* Updates HTTP Routing. | ||
*/ | ||
static void routing(HttpRouting.Builder routing) { | ||
routing.addFeature(new HelloResource()); | ||
} | ||
} |
Oops, something went wrong.