Skip to content

Commit

Permalink
security validation (#23)
Browse files Browse the repository at this point in the history
Signed-off-by: Maxim Nesen <maxim.nesen@oracle.com>
  • Loading branch information
senivam authored Jan 12, 2024
1 parent 54ff894 commit 9a20967
Show file tree
Hide file tree
Showing 64 changed files with 269 additions and 245 deletions.
2 changes: 1 addition & 1 deletion examples/config/changes/conf/secrets/password
Original file line number Diff line number Diff line change
@@ -1 +1 @@
^ery$ecretP&ssword
changeit
2 changes: 1 addition & 1 deletion examples/config/sources/conf/secrets/password
Original file line number Diff line number Diff line change
@@ -1 +1 @@
^ery$ecretP&ssword
changeit
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2023 Oracle and/or its affiliates.
* Copyright (c) 2017, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -50,7 +50,7 @@ public static void main(String... args) {

String password = secrets.get("password").asString().get();
System.out.println("Password: " + password);
assert password.equals("^ery$ecretP&ssword");
assert password.equals("changeit");
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2023 Oracle and/or its affiliates.
* Copyright (c) 2019, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,7 +44,7 @@ final class EmployeeRepositoryImplDB implements EmployeeRepository {
String driver = "oracle.jdbc.driver.OracleDriver";

String dbUserName = config.get("app.user").asString().orElse("sys as SYSDBA");
String dbUserPassword = config.get("app.password").asString().orElse("password");
String dbUserPassword = config.get("app.password").asString().orElse("changeit");
String dbHostURL = config.get("app.hosturl").asString().orElse("localhost:1521/xe");

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2023 Oracle and/or its affiliates.
* Copyright (c) 2019, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -57,7 +57,7 @@ public static void main(String[] args) {
// setting the properties used by the basic auth provider for user name and password
GrpcClientSecurity clientSecurity = GrpcClientSecurity.builder(security.createContext("test.client"))
.property(EndpointConfig.PROPERTY_OUTBOUND_ID, "Bob")
.property(EndpointConfig.PROPERTY_OUTBOUND_SECRET, "password")
.property(EndpointConfig.PROPERTY_OUTBOUND_SECRET, "changeit")
.build();

// create the GreetService client stub and use the GrpcClientSecurity call credentials
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2019, 2023 Oracle and/or its affiliates.
# Copyright (c) 2019, 2024 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,7 +30,7 @@ http-basic-auth:
password: "secret"
roles: ["user", "admin"]
- login: "Bob"
password: "password"
password: "changeit"
roles: ["user"]
outbound:
- name: propagate_all
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2023 Oracle and/or its affiliates.
* Copyright (c) 2019, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -52,7 +52,7 @@ public static void main(String[] args) {

// Obtain the user name and password from the program arguments
String user = args.length >= 2 ? args[0] : "Ted";
String password = args.length >= 2 ? args[1] : "secret";
String password = args.length >= 2 ? args[1] : "changeit";

Config config = Config.create();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2023 Oracle and/or its affiliates.
* Copyright (c) 2019, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -53,7 +53,7 @@ public static void main(String[] args) {

// Obtain the user name and password from the program arguments
String user = args.length >= 2 ? args[0] : "Ted";
String password = args.length >= 2 ? args[1] : "secret";
String password = args.length >= 2 ? args[1] : "changeit";

Config config = Config.create();

Expand Down
6 changes: 3 additions & 3 deletions examples/grpc/security/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2019, 2023 Oracle and/or its affiliates.
# Copyright (c) 2019, 2024 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,8 +27,8 @@ webserver:
http-basic-auth:
users:
- login: "Ted"
password: "secret"
password: "changeit"
roles: ["user", "admin"]
- login: "Bob"
password: "password"
password: "changeit"
roles: ["user"]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2018, 2022 Oracle and/or its affiliates.
# Copyright (c) 2018, 2024 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,7 +29,7 @@ security:
# This is a nice way to be able to override this with local properties or env-vars
idcs-uri: "https://tenant-id.identity.oracle.com"
idcs-client-id: "client-id"
idcs-client-secret: "client-secret"
idcs-client-secret: "changeit"
# Used as a base for redirects back to us
frontend-uri: "http://localhost:7987"
proxy-host: "if you need proxy"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2018, 2020 Oracle and/or its affiliates.
# Copyright (c) 2018, 2024 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,13 +27,13 @@ security:
realm: "helidon"
users:
- login: "jack"
password: "password"
password: "changeit"
roles: ["user", "admin"]
- login: "jill"
password: "password"
password: "changeit"
roles: ["user"]
- login: "john"
password: "password"
password: "changeit"
web-server:
paths:
- path: "/static-cp[/{*}]"
Expand Down
10 changes: 10 additions & 0 deletions examples/microprofile/tls/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ This examples shows how to configure server TLS using Helidon MP.

Note: This example uses self-signed server certificate!

### How to generate self-signed certificate (optional)
In this example the certificate is bundled so no special certificate is required.
Required tools: keytool
```bash
keytool -genkeypair -keyalg RSA -keysize 2048 -alias server -dname "CN=localhost" -validity 21650 -keystore server.jks -storepass changeit -keypass changeit -deststoretype pkcs12
keytool -exportcert -keystore server.jks -storepass changeit -alias server -rfc -file server.cer
keytool -certreq -keystore server.jks -alias server -keypass changeit -storepass changeit -keyalg rsa -file server.csr
keytool -importkeystore -srckeystore server.jks -destkeystore server.p12 -srcstoretype jks -deststoretype pkcs12 -srcstorepass changeit -deststorepass changeit
```

## Build and run

```bash
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2020 Oracle and/or its affiliates.
# Copyright (c) 2020, 2024 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -20,9 +20,9 @@ server.host=0.0.0.0

#Truststore setup
server.tls.trust.keystore.resource.resource-path=server.p12
server.tls.trust.keystore.passphrase=password
server.tls.trust.keystore.passphrase=changeit
server.tls.trust.keystore.trust-store=true

#Keystore with private key and server certificate
server.tls.private-key.keystore.resource.resource-path=server.p12
server.tls.private-key.keystore.passphrase=password
server.tls.private-key.keystore.passphrase=changeit
Binary file modified examples/microprofile/tls/src/main/resources/server.p12
Binary file not shown.
10 changes: 5 additions & 5 deletions examples/security/basic-auth-with-static-content/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ Try the application:
The application starts on a random port, the following assumes it is `56551`
```bash
curl http://localhost:[PORT]/public
curl -u "jill:password" http://localhost:[PORT]/noRoles
curl -u "john:password" http://localhost:[PORT]/user
curl -u "jack:password" http://localhost:[PORT]/admin
curl -v -u "john:password" http://localhost:[PORT]/deny
curl -u "jack:password" http://localhost:[PORT]/noAuthn
curl -u "jill:changeit" http://localhost:[PORT]/noRoles
curl -u "john:changeit" http://localhost:[PORT]/user
curl -u "jack:changeit" http://localhost:[PORT]/admin
curl -v -u "john:changeit" http://localhost:[PORT]/deny
curl -u "jack:changeit" http://localhost:[PORT]/noAuthn
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2023 Oracle and/or its affiliates.
* Copyright (c) 2020, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,9 +42,9 @@ public final class BasicExampleBuilderMain {
private static final Map<String, MyUser> USERS = new HashMap<>();

static {
USERS.put("jack", new MyUser("jack", "password".toCharArray(), Set.of("user", "admin")));
USERS.put("jill", new MyUser("jill", "password".toCharArray(), Set.of("user")));
USERS.put("john", new MyUser("john", "password".toCharArray(), Set.of()));
USERS.put("jack", new MyUser("jack", "changeit".toCharArray(), Set.of("user", "admin")));
USERS.put("jill", new MyUser("jill", "changeit".toCharArray(), Set.of("user")));
USERS.put("john", new MyUser("john", "changeit".toCharArray(), Set.of()));
}

private BasicExampleBuilderMain() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2023 Oracle and/or its affiliates.
* Copyright (c) 2020, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,9 +35,9 @@ static void startAndPrintEndpoints(Supplier<WebServer> startMethod) {
System.out.printf("Started server on localhost:%d%n", webServer.port());
System.out.println();
System.out.println("Users:");
System.out.println("Jack/password in roles: user, admin");
System.out.println("Jill/password in roles: user");
System.out.println("John/password in no roles");
System.out.println("jack/changeit in roles: user, admin");
System.out.println("jill/changeit in roles: user");
System.out.println("john/changeit in no roles");
System.out.println();
System.out.println("***********************");
System.out.println("** Endpoints: **");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2020, 2023 Oracle and/or its affiliates.
# Copyright (c) 2020, 2024 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,13 +27,13 @@ security:
realm: "helidon"
users:
- login: "jack"
password: "${CLEAR=password}"
password: "${CLEAR=changeit}"
roles: [ "user", "admin" ]
- login: "jill"
password: "${CLEAR=password}"
password: "${CLEAR=changeit}"
roles: [ "user" ]
- login: "john"
password: "${CLEAR=password}"
password: "${CLEAR=changeit}"
roles: [ ]
web-server:
# Configuration of integration with web server
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2023 Oracle and/or its affiliates.
* Copyright (c) 2020, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -87,9 +87,9 @@ public void testNoRoles() {
testNotAuthorized(url);

//Must be accessible with authentication - to everybody
testProtected(url, "jack", "password", Set.of("admin", "user"), Set.of());
testProtected(url, "jill", "password", Set.of("user"), Set.of("admin"));
testProtected(url, "john", "password", Set.of(), Set.of("admin", "user"));
testProtected(url, "jack", "changeit", Set.of("admin", "user"), Set.of());
testProtected(url, "jill", "changeit", Set.of("user"), Set.of("admin"));
testProtected(url, "john", "changeit", Set.of(), Set.of("admin", "user"));
}

@Test
Expand All @@ -99,9 +99,9 @@ public void testUserRole() {
testNotAuthorized(url);

//Jack and Jill allowed (user role)
testProtected(url, "jack", "password", Set.of("admin", "user"), Set.of());
testProtected(url, "jill", "password", Set.of("user"), Set.of("admin"));
testProtectedDenied(url, "john", "password");
testProtected(url, "jack", "changeit", Set.of("admin", "user"), Set.of());
testProtected(url, "jill", "changeit", Set.of("user"), Set.of("admin"));
testProtectedDenied(url, "john", "changeit");
}

@Test
Expand All @@ -111,9 +111,9 @@ public void testAdminRole() {
testNotAuthorized(url);

//Only jack is allowed - admin role...
testProtected(url, "jack", "password", Set.of("admin", "user"), Set.of());
testProtectedDenied(url, "jill", "password");
testProtectedDenied(url, "john", "password");
testProtected(url, "jack", "changeit", Set.of("admin", "user"), Set.of());
testProtectedDenied(url, "jill", "changeit");
testProtectedDenied(url, "john", "changeit");
}

@Test
Expand All @@ -123,9 +123,9 @@ public void testDenyRole() {
testNotAuthorized(url);

// nobody has the correct role
testProtectedDenied(url, "jack", "password");
testProtectedDenied(url, "jill", "password");
testProtectedDenied(url, "john", "password");
testProtectedDenied(url, "jack", "changeit");
testProtectedDenied(url, "jill", "changeit");
testProtectedDenied(url, "john", "changeit");
}

@Test
Expand Down
6 changes: 3 additions & 3 deletions examples/security/jersey/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Try the endpoints:
```bash
curl http://localhost:8080/rest
curl -v http://localhost:8080/rest/protected
curl -u "jack:password" http://localhost:8080/rest/protected
curl -u "jack:password" http://localhost:8080/rest/protected
curl -v -u "john:password" http://localhost:8080/rest/protected
curl -u "jack:changeit" http://localhost:8080/rest/protected
curl -u "jack:changeit" http://localhost:8080/rest/protected
curl -v -u "john:changeit" http://localhost:8080/rest/protected
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2023 Oracle and/or its affiliates.
* Copyright (c) 2018, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,9 +44,9 @@ public final class JerseyBuilderMain {
private static volatile WebServer server;

static {
addUser("jack", "password", List.of("user", "admin"));
addUser("jill", "password", List.of("user"));
addUser("john", "password", List.of());
addUser("jack", "changeit", List.of("user", "admin"));
addUser("jill", "changeit", List.of("user"));
addUser("john", "changeit", List.of());
}

private JerseyBuilderMain() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2023 Oracle and/or its affiliates.
* Copyright (c) 2018, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -55,9 +55,9 @@ static WebServer startIt(Supplier<? extends Routing> routing, int port) {
System.out.printf("Started server on localhost:%d%n", webServer.port());
System.out.println();
System.out.println("Users:");
System.out.println("jack/password in roles: user, admin");
System.out.println("jill/password in roles: user");
System.out.println("john/password in no roles");
System.out.println("jack/changeit in roles: user, admin");
System.out.println("jill/changeit in roles: user");
System.out.println("john/changeit in no roles");
System.out.println();
System.out.println("***********************");
System.out.println("** Endpoints: **");
Expand Down
Loading

0 comments on commit 9a20967

Please sign in to comment.