Skip to content

Commit 98b449c

Browse files
committed
Fix #12 login endpoint in backend
1 parent e5d80e5 commit 98b449c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1798
-21
lines changed

.sdkmanrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Enable auto-env through the sdkman_auto_env config
2+
# Add key=value pairs of SDKs to use below
3+
java=11.0.15-tem
4+
maven=3.8.2

pom.xml

+69-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,24 @@
3434

3535
<dependencies>
3636
<!--
37-
Quarkus general dependencies
37+
RESTEasy Reactive is a JAX-RS implementation written from the
38+
ground up to work on Vert.x layer.
39+
-->
40+
<dependency>
41+
<groupId>io.quarkus</groupId>
42+
<artifactId>quarkus-resteasy-reactive</artifactId>
43+
</dependency>
44+
<!--
45+
Jackson has been known as "the Java JSON library" or "the best JSON parser
46+
for Java". Or simply as "JSON for Java".
47+
-->
48+
<dependency>
49+
<groupId>io.quarkus</groupId>
50+
<artifactId>quarkus-resteasy-reactive-jackson</artifactId>
51+
</dependency>
52+
<!--
53+
Automatically generate Kubernetes resources based on sane
54+
defaults and user-supplied configuration using dekorate.
3855
-->
3956
<dependency>
4057
<groupId>io.quarkus</groupId>
@@ -44,14 +61,63 @@
4461
<groupId>io.quarkus</groupId>
4562
<artifactId>quarkus-container-image-jib</artifactId>
4663
</dependency>
64+
<!--
65+
Quarkus DI solution (also called ArC) is based on the Contexts
66+
and Dependency Injection for Java 2.0 specification. However,
67+
it is not a full CDI implementation verified by the TCK.
68+
Only a subset of the CDI features is implemented.
69+
-->
4770
<dependency>
4871
<groupId>io.quarkus</groupId>
49-
<artifactId>quarkus-resteasy-reactive</artifactId>
72+
<artifactId>quarkus-arc</artifactId>
5073
</dependency>
74+
<!--
75+
Quarkus application can expose its API description through an OpenAPI
76+
specification and how you can test it via a user-friendly UI named Swagger UI.
77+
SmallRye OpenAPI Implementation extends the MicroProfile OpenAPI which is
78+
primarily used for adding OpenAPI to JAX-RS Endpoints
79+
-->
5180
<dependency>
5281
<groupId>io.quarkus</groupId>
53-
<artifactId>quarkus-arc</artifactId>
82+
<artifactId>quarkus-smallrye-openapi</artifactId>
83+
</dependency>
84+
<!--
85+
Quarkus application can utilize SmallRye JWT to verify JSON Web Tokens,
86+
represent them as MicroProfile JWT org.eclipse.microprofile.jwt.JsonWebToken
87+
and provide secured access to the Quarkus HTTP endpoints using Bearer Token
88+
Authorization and Role-Based Access Control.
89+
-->
90+
<dependency>
91+
<groupId>io.quarkus</groupId>
92+
<artifactId>quarkus-smallrye-jwt</artifactId>
5493
</dependency>
94+
<dependency>
95+
<groupId>io.quarkus</groupId>
96+
<artifactId>quarkus-smallrye-jwt-build</artifactId>
97+
</dependency>
98+
99+
100+
<dependency>
101+
<groupId>io.quarkus</groupId>
102+
<artifactId>quarkus-hibernate-orm-panache</artifactId>
103+
</dependency>
104+
<dependency>
105+
<groupId>io.quarkus</groupId>
106+
<artifactId>quarkus-jdbc-postgresql </artifactId>
107+
</dependency>
108+
<dependency>
109+
<groupId>io.quarkus</groupId>
110+
<artifactId>quarkus-hibernate-validator</artifactId>
111+
</dependency>
112+
<dependency>
113+
<groupId>io.quarkus</groupId>
114+
<artifactId>quarkus-security-jpa</artifactId>
115+
</dependency>
116+
<dependency>
117+
<groupId>io.quarkus</groupId>
118+
<artifactId>quarkus-smallrye-health</artifactId>
119+
</dependency>
120+
55121
<dependency>
56122
<groupId>io.quarkus</groupId>
57123
<artifactId>quarkus-junit5</artifactId>

src/main/java/org/acme/GreetingResource.java

-16
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.kubernetesbigdataeg.tamer;
2+
3+
import io.quarkus.runtime.ShutdownEvent;
4+
import io.quarkus.runtime.StartupEvent;
5+
import org.kubernetesbigdataeg.tamer.bootstrap.FirstBootDatabaseInit;
6+
import org.jboss.logging.Logger;
7+
8+
import javax.enterprise.context.ApplicationScoped;
9+
import javax.enterprise.event.Observes;
10+
import javax.transaction.Transactional;
11+
12+
@ApplicationScoped
13+
public class AppLifecycleBean {
14+
private static final Logger LOGGER = Logger.getLogger("ListenerBean");
15+
16+
void onStart(@Observes StartupEvent ev) {
17+
System.out.println("Tamer Application starting...");
18+
19+
firstBootInitializeTables();
20+
21+
LOGGER.info("The application is starting...");
22+
}
23+
24+
@Transactional
25+
void firstBootInitializeTables(){
26+
FirstBootDatabaseInit firstBootDatabaseInit = new FirstBootDatabaseInit();
27+
firstBootDatabaseInit.initializeTables();
28+
}
29+
30+
void onStop(@Observes ShutdownEvent ev) {
31+
System.out.println("Tamer Application stopping...");
32+
LOGGER.info("The application is stopping...");
33+
}
34+
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.kubernetesbigdataeg.tamer;
2+
3+
import io.quarkus.runtime.Quarkus;
4+
import io.quarkus.runtime.QuarkusApplication;
5+
import io.quarkus.runtime.annotations.QuarkusMain;
6+
7+
@QuarkusMain
8+
public class Main {
9+
public static void main(String... args) {
10+
Quarkus.run(MyApp.class, args);
11+
}
12+
13+
public static class MyApp implements QuarkusApplication {
14+
@Override
15+
public int run(String... args) throws Exception {
16+
System.out.println("Tamer Application bootstrapping ...");
17+
/*
18+
This method will wait until a shutdown is requested
19+
(either from an external signal like when you press
20+
Ctrl+C or because a thread has called Quarkus.asyncExit().
21+
*/
22+
Quarkus.waitForExit();
23+
return 0;
24+
}
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package org.kubernetesbigdataeg.tamer.bootstrap;
2+
3+
import org.jboss.logging.Logger;
4+
import org.kubernetesbigdataeg.tamer.entities.catalog.Catalog;
5+
import org.kubernetesbigdataeg.tamer.entities.catalog.CatalogRepository;
6+
import org.kubernetesbigdataeg.tamer.entities.user.User;
7+
import org.kubernetesbigdataeg.tamer.entities.user.UsersRepository;
8+
import org.kubernetesbigdataeg.tamer.entities.userRole.UserRole;
9+
import org.kubernetesbigdataeg.tamer.entities.userRole.UserRoleRepository;
10+
11+
import java.util.Enumeration;
12+
import java.util.Properties;
13+
14+
public class FirstBootDatabaseInit {
15+
private static final Logger LOGGER = Logger.getLogger("ListenerBean");
16+
LoadInitTablesCustomProperties customProperties;
17+
18+
public FirstBootDatabaseInit() {
19+
customProperties = new LoadInitTablesCustomProperties();
20+
}
21+
22+
public void initializeTables() {
23+
initializeUsersTable();
24+
initializeUsersRoleTable();
25+
initializeCatalogTable();
26+
}
27+
28+
private void initializeUsersTable(){
29+
new Properties();
30+
Properties p;
31+
p = customProperties.getInitValuesUsersTable();
32+
33+
UsersRepository usersRepository = new UsersRepository();
34+
35+
if (usersRepository.count() == 0) {
36+
LOGGER.info("Initializing Table -> Users");
37+
Enumeration<?> e = p.propertyNames();
38+
39+
while (e.hasMoreElements()) {
40+
User users = new User();
41+
String key = (String) e.nextElement();
42+
String[] parts = p.getProperty(key).split(",");
43+
users.setUsername(parts[0]);
44+
users.setPassword(parts[1]);
45+
users.addRole(parts[2]);
46+
users.persist();
47+
}
48+
} else {
49+
LOGGER.info("Table -> Users already initializated");
50+
}
51+
}
52+
53+
private void initializeUsersRoleTable(){
54+
new Properties();
55+
Properties p;
56+
p = customProperties.getInitValuesUsersRoleTable();
57+
58+
UserRoleRepository usersRoleRepository = new UserRoleRepository();
59+
60+
if (usersRoleRepository.count() == 0) {
61+
LOGGER.info("Initializing Table -> Users Role");
62+
Enumeration<?> e = p.propertyNames();
63+
64+
while (e.hasMoreElements()) {
65+
UserRole userRole = new UserRole();
66+
String key = (String) e.nextElement();
67+
String[] parts = p.getProperty(key).split(",");
68+
userRole.setName(parts[0]);
69+
userRole.setDesc(parts[1]);
70+
userRole.persist();
71+
}
72+
} else {
73+
LOGGER.info("Table -> Users Role already initializated");
74+
}
75+
}
76+
77+
private void initializeCatalogTable(){
78+
new Properties();
79+
Properties p;
80+
p = customProperties.getInitValuesCatalogTable();
81+
82+
CatalogRepository catalogRepository = new CatalogRepository();
83+
84+
if (catalogRepository.count() == 0) {
85+
LOGGER.info("Initializing Table -> Layers");
86+
Enumeration<?> e = p.propertyNames();
87+
88+
while (e.hasMoreElements()) {
89+
Catalog catalog = new Catalog();
90+
91+
String key = (String) e.nextElement();
92+
String[] parts = p.getProperty(key).split(",");
93+
catalog.setName(parts[0]);
94+
catalog.setDesc(parts[1]);
95+
catalog.setManifest(parts[2]);
96+
catalog.persist();
97+
}
98+
} else {
99+
LOGGER.info("Table -> Catalog already initializated");
100+
}
101+
}
102+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package org.kubernetesbigdataeg.tamer.bootstrap;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.util.Enumeration;
6+
import java.util.Properties;
7+
8+
public class LoadInitTablesCustomProperties {
9+
private Properties properties;
10+
11+
public LoadInitTablesCustomProperties() {
12+
properties = new Properties();
13+
properties = loadPropertiesFile();
14+
}
15+
16+
// This method is used to load the properties file
17+
private Properties loadPropertiesFile(){
18+
InputStream iStream = null;
19+
try {
20+
// Loading properties file from resources internal folder
21+
iStream = getClass().getClassLoader().getResourceAsStream("inittables.properties");
22+
properties.load(iStream);
23+
} catch (IOException e) {
24+
e.printStackTrace();
25+
}finally {
26+
try {
27+
if(iStream != null){
28+
iStream.close();
29+
}
30+
} catch (IOException e) {
31+
e.printStackTrace();
32+
}
33+
}
34+
35+
return properties;
36+
}
37+
38+
public Properties getInitValuesUsersTable() {
39+
Properties typesProperties = new Properties();
40+
Enumeration<?> e = properties.propertyNames();
41+
42+
while (e.hasMoreElements()) {
43+
String key = (String) e.nextElement();
44+
if (key.startsWith("users.init")) {
45+
typesProperties.setProperty(key, properties.getProperty(key));
46+
}
47+
}
48+
return typesProperties;
49+
}
50+
51+
public Properties getInitValuesUsersRoleTable() {
52+
Properties usersRoleProperties = new Properties();
53+
Enumeration<?> e = properties.propertyNames();
54+
55+
while (e.hasMoreElements()) {
56+
String key = (String) e.nextElement();
57+
if (key.startsWith("user_roles.init")) {
58+
usersRoleProperties.setProperty(key, properties.getProperty(key));
59+
}
60+
}
61+
return usersRoleProperties;
62+
}
63+
64+
public Properties getInitValuesCatalogTable() {
65+
Properties servicesProperties = new Properties();
66+
Enumeration<?> e = properties.propertyNames();
67+
68+
while (e.hasMoreElements()) {
69+
String key = (String) e.nextElement();
70+
if (key.startsWith("catalog.init")) {
71+
servicesProperties.setProperty(key, properties.getProperty(key));
72+
}
73+
}
74+
return servicesProperties;
75+
}
76+
77+
public void printProperties() {
78+
Enumeration<?> e = properties.propertyNames();
79+
80+
while (e.hasMoreElements()) {
81+
String key = (String) e.nextElement();
82+
System.out.println(key + " -- " + properties.getProperty(key));
83+
}
84+
}
85+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.kubernetesbigdataeg.tamer.bootstrap;
2+
3+
import io.vertx.ext.web.Router;
4+
5+
import javax.enterprise.context.ApplicationScoped;
6+
import javax.enterprise.event.Observes;
7+
import java.util.function.Predicate;
8+
import java.util.regex.Pattern;
9+
import java.util.stream.Stream;
10+
11+
@ApplicationScoped
12+
public class SPARouting {
13+
private static final String[] PATH_PREFIXES = { "/api/", "/q/" };
14+
private static final Predicate<String> FILE_NAME_PREDICATE = Pattern.compile(".*[.][a-zA-Z\\d]+").asMatchPredicate();
15+
16+
public void init(@Observes Router router) {
17+
router.get("/*").handler(rc -> {
18+
final String path = rc.normalizedPath();
19+
if (!path.equals("/")
20+
&& Stream.of(PATH_PREFIXES).noneMatch(path::startsWith)
21+
&& !FILE_NAME_PREDICATE.test(path)) {
22+
rc.reroute("/");
23+
} else {
24+
rc.next();
25+
}
26+
});
27+
}
28+
}

0 commit comments

Comments
 (0)