JAVA-22211 Upgrade dependencies versions for helidon-se module (#14389)
* JAVA-22211 Upgrade dependencies versions for helidon-se module * JAVA-22211 Add properties for each version --------- Co-authored-by: timis1 <noreplay@yahoo.com>
This commit is contained in:
parent
8553d79655
commit
ad46c3d204
@ -28,13 +28,13 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.helidon.webserver</groupId>
|
<groupId>io.helidon.webserver</groupId>
|
||||||
<artifactId>helidon-webserver-netty</artifactId>
|
<artifactId>helidon-webserver-netty</artifactId>
|
||||||
<version>${helidon.version}</version>
|
<version>${helidon-webserver-netty.version}</version>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.helidon.webserver</groupId>
|
<groupId>io.helidon.webserver</groupId>
|
||||||
<artifactId>helidon-webserver-json</artifactId>
|
<artifactId>helidon-webserver-json</artifactId>
|
||||||
<version>${helidon.version}</version>
|
<version>${helidon-webserver-json.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--Security -->
|
<!--Security -->
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -43,19 +43,26 @@
|
|||||||
<version>${helidon.version}</version>
|
<version>${helidon.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.helidon.security</groupId>
|
<groupId>io.helidon.security.providers</groupId>
|
||||||
<artifactId>helidon-security-provider-http-auth</artifactId>
|
<artifactId>helidon-security-providers-http-auth</artifactId>
|
||||||
<version>${helidon.version}</version>
|
<version>${helidon.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.helidon.security</groupId>
|
<groupId>io.helidon.security.integration</groupId>
|
||||||
<artifactId>helidon-security-integration-webserver</artifactId>
|
<artifactId>helidon-security-integration-webserver</artifactId>
|
||||||
<version>${helidon.version}</version>
|
<version>${helidon.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.helidon.webserver</groupId>
|
||||||
|
<artifactId>helidon-webserver-http2</artifactId>
|
||||||
|
<version>${helidon.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<helidon.version>0.10.4</helidon.version>
|
<helidon.version>3.2.2</helidon.version>
|
||||||
|
<helidon-webserver-netty.version>0.10.6</helidon-webserver-netty.version>
|
||||||
|
<helidon-webserver-json.version>0.11.0</helidon-webserver-json.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -6,7 +6,7 @@ import io.helidon.config.spi.ConfigSource;
|
|||||||
|
|
||||||
public class ConfigApplication {
|
public class ConfigApplication {
|
||||||
|
|
||||||
public static void main(String... args) throws Exception {
|
public static void main(String... args) {
|
||||||
|
|
||||||
ConfigSource configSource = ConfigSources.classpath("application.yaml").build();
|
ConfigSource configSource = ConfigSources.classpath("application.yaml").build();
|
||||||
Config config = Config.builder()
|
Config config = Config.builder()
|
||||||
@ -15,10 +15,10 @@ public class ConfigApplication {
|
|||||||
.sources(configSource)
|
.sources(configSource)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
int port = config.get("server.port").asInt();
|
int port = config.get("server.port").asInt().get();
|
||||||
int pageSize = config.get("web.page-size").asInt();
|
int pageSize = config.get("web.page-size").asInt().get();
|
||||||
boolean debug = config.get("web.debug").asBoolean();
|
boolean debug = config.get("web.debug").asBoolean().get();
|
||||||
String userHome = config.get("user.home").asString();
|
String userHome = config.get("user.home").asString().get();
|
||||||
|
|
||||||
System.out.println("port: " + port);
|
System.out.println("port: " + port);
|
||||||
System.out.println("pageSize: " + pageSize);
|
System.out.println("pageSize: " + pageSize);
|
||||||
|
@ -50,9 +50,7 @@ public class BookResource implements Service {
|
|||||||
|
|
||||||
private JsonArray from(List<Book> books) {
|
private JsonArray from(List<Book> books) {
|
||||||
JsonArrayBuilder jsonArrayBuilder = Json.createArrayBuilder();
|
JsonArrayBuilder jsonArrayBuilder = Json.createArrayBuilder();
|
||||||
books.forEach(book -> {
|
books.forEach(book -> jsonArrayBuilder.add(from(book)));
|
||||||
jsonArrayBuilder.add(from(book));
|
|
||||||
});
|
|
||||||
return jsonArrayBuilder.build();
|
return jsonArrayBuilder.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,21 @@
|
|||||||
package com.baeldung.helidon.se.routing;
|
package com.baeldung.helidon.se.routing;
|
||||||
|
|
||||||
import io.helidon.webserver.Routing;
|
import io.helidon.webserver.Routing;
|
||||||
import io.helidon.webserver.ServerConfiguration;
|
|
||||||
import io.helidon.webserver.WebServer;
|
import io.helidon.webserver.WebServer;
|
||||||
import io.helidon.webserver.json.JsonSupport;
|
import io.helidon.webserver.json.JsonSupport;
|
||||||
|
|
||||||
public class WebApplicationRouting {
|
public class WebApplicationRouting {
|
||||||
|
|
||||||
public static void main(String... args) throws Exception {
|
public static void main(String... args) {
|
||||||
|
|
||||||
ServerConfiguration serverConfig = ServerConfiguration.builder()
|
|
||||||
.port(9080)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Routing routing = Routing.builder()
|
Routing routing = Routing.builder()
|
||||||
.register(JsonSupport.get())
|
.register(JsonSupport.create())
|
||||||
.register("/books", new BookResource())
|
.register("/books", new BookResource())
|
||||||
.get("/greet", (request, response) -> response.send("Hello World !"))
|
.get("/greet", (request, response) -> response.send("Hello World !"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
WebServer.create(serverConfig, routing)
|
WebServer.builder().port(9080).addRouting(routing)
|
||||||
|
.build()
|
||||||
.start()
|
.start()
|
||||||
.thenAccept(ws ->
|
.thenAccept(ws ->
|
||||||
System.out.println("Server started at: http://localhost:" + ws.port())
|
System.out.println("Server started at: http://localhost:" + ws.port())
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
package com.baeldung.helidon.se.security;
|
package com.baeldung.helidon.se.security;
|
||||||
|
|
||||||
import io.helidon.security.provider.httpauth.UserStore;
|
import io.helidon.security.providers.httpauth.SecureUserStore;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
public class MyUser implements UserStore.User {
|
public class MyUser implements SecureUserStore.User {
|
||||||
|
|
||||||
private String login;
|
private String login;
|
||||||
private char[] password;
|
private char[] password;
|
||||||
@ -17,17 +18,17 @@ public class MyUser implements UserStore.User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getLogin() {
|
public String login() {
|
||||||
return login;
|
return login;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public char[] getPassword() {
|
public boolean isPasswordValid(char[] chars) {
|
||||||
return password;
|
return Arrays.equals(chars, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<String> getRoles() {
|
public Collection<String> roles() {
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,30 +3,28 @@ package com.baeldung.helidon.se.security;
|
|||||||
import io.helidon.config.Config;
|
import io.helidon.config.Config;
|
||||||
import io.helidon.security.Security;
|
import io.helidon.security.Security;
|
||||||
import io.helidon.security.SubjectType;
|
import io.helidon.security.SubjectType;
|
||||||
import io.helidon.security.provider.httpauth.HttpBasicAuthProvider;
|
import io.helidon.security.integration.webserver.WebSecurity;
|
||||||
import io.helidon.security.provider.httpauth.UserStore;
|
import io.helidon.security.providers.httpauth.HttpBasicAuthProvider;
|
||||||
import io.helidon.security.webserver.WebSecurity;
|
import io.helidon.security.providers.httpauth.SecureUserStore;
|
||||||
import io.helidon.webserver.Routing;
|
import io.helidon.webserver.Routing;
|
||||||
import io.helidon.webserver.ServerConfiguration;
|
|
||||||
import io.helidon.webserver.WebServer;
|
import io.helidon.webserver.WebServer;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class WebApplicationSecurity {
|
public class WebApplicationSecurity {
|
||||||
|
|
||||||
public static void main(String... args) throws Exception {
|
public static void main(String... args) {
|
||||||
|
|
||||||
Config config = Config.create();
|
Config config = Config.create();
|
||||||
ServerConfiguration serverConfig =
|
|
||||||
ServerConfiguration.fromConfig(config.get("server"));
|
|
||||||
|
|
||||||
Map<String, MyUser> users = new HashMap<>();
|
Map<String, MyUser> users = new HashMap<>();
|
||||||
users.put("user", new MyUser("user", "user".toCharArray(), Arrays.asList("ROLE_USER")));
|
users.put("user", new MyUser("user", "user".toCharArray(), Collections.singletonList("ROLE_USER")));
|
||||||
users.put("admin", new MyUser("admin", "admin".toCharArray(), Arrays.asList("ROLE_USER", "ROLE_ADMIN")));
|
users.put("admin", new MyUser("admin", "admin".toCharArray(), Arrays.asList("ROLE_USER", "ROLE_ADMIN")));
|
||||||
UserStore store = user -> Optional.ofNullable(users.get(user));
|
SecureUserStore store = user -> Optional.ofNullable(users.get(user));
|
||||||
|
|
||||||
HttpBasicAuthProvider httpBasicAuthProvider = HttpBasicAuthProvider.builder()
|
HttpBasicAuthProvider httpBasicAuthProvider = HttpBasicAuthProvider.builder()
|
||||||
.realm("myRealm")
|
.realm("myRealm")
|
||||||
@ -38,13 +36,12 @@ public class WebApplicationSecurity {
|
|||||||
Security security = Security.builder()
|
Security security = Security.builder()
|
||||||
.addAuthenticationProvider(httpBasicAuthProvider)
|
.addAuthenticationProvider(httpBasicAuthProvider)
|
||||||
.build();
|
.build();
|
||||||
//Security security = Security.fromConfig(config);
|
//Security security = Security.create(config);
|
||||||
|
|
||||||
//2. WebSecurity from Security or from Config
|
//2. WebSecurity from Security or from Config
|
||||||
// WebSecurity webSecurity = WebSecurity.from(security)
|
// WebSecurity webSecurity = WebSecurity.create(security).securityDefaults(WebSecurity.authenticate());
|
||||||
// .securityDefaults(WebSecurity.authenticate());
|
|
||||||
|
|
||||||
WebSecurity webSecurity = WebSecurity.from(config);
|
WebSecurity webSecurity = WebSecurity.create(config);
|
||||||
|
|
||||||
Routing routing = Routing.builder()
|
Routing routing = Routing.builder()
|
||||||
.register(webSecurity)
|
.register(webSecurity)
|
||||||
@ -52,7 +49,7 @@ public class WebApplicationSecurity {
|
|||||||
.get("/admin", (request, response) -> response.send("Hello, I'm a Helidon SE user with ROLE_ADMIN"))
|
.get("/admin", (request, response) -> response.send("Hello, I'm a Helidon SE user with ROLE_ADMIN"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
WebServer webServer = WebServer.create(serverConfig, routing);
|
WebServer webServer = WebServer.create(routing, config.get("server"));
|
||||||
|
|
||||||
webServer.start().thenAccept(ws ->
|
webServer.start().thenAccept(ws ->
|
||||||
System.out.println("Server started at: http://localhost:" + ws.port())
|
System.out.println("Server started at: http://localhost:" + ws.port())
|
||||||
|
@ -1,22 +1,18 @@
|
|||||||
package com.baeldung.helidon.se.webserver;
|
package com.baeldung.helidon.se.webserver;
|
||||||
|
|
||||||
import io.helidon.webserver.Routing;
|
import io.helidon.webserver.Routing;
|
||||||
import io.helidon.webserver.ServerConfiguration;
|
|
||||||
import io.helidon.webserver.WebServer;
|
import io.helidon.webserver.WebServer;
|
||||||
|
|
||||||
public class SimpleWebApplication {
|
public class SimpleWebApplication {
|
||||||
|
|
||||||
public static void main(String... args) throws Exception {
|
public static void main(String... args) {
|
||||||
|
|
||||||
ServerConfiguration serverConfig = ServerConfiguration.builder()
|
|
||||||
.port(9001)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
Routing routing = Routing.builder()
|
Routing routing = Routing.builder()
|
||||||
.get("/greet", (request, response) -> response.send("Hello World !"))
|
.get("/greet", (request, response) -> response.send("Hello World !"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
WebServer.create(serverConfig, routing)
|
WebServer.builder(routing)
|
||||||
|
.port(9001).addRouting(routing).build()
|
||||||
.start()
|
.start()
|
||||||
.thenAccept(ws ->
|
.thenAccept(ws ->
|
||||||
System.out.println("Server started at: http://localhost:" + ws.port())
|
System.out.println("Server started at: http://localhost:" + ws.port())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user