Initialer commit
This commit is contained in:
29
user-service/.classpath
Normal file
29
user-service/.classpath
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="bin/main" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/main" path="src/main/webapp">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/main" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17/"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
|
||||
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer">
|
||||
<attributes>
|
||||
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="bin/default"/>
|
||||
</classpath>
|
||||
33
user-service/.project
Normal file
33
user-service/.project
Normal file
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>user-service</name>
|
||||
<comment></comment>
|
||||
<projects/>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||
</natures>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments/>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments/>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<arguments/>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||
<arguments/>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<linkedResources/>
|
||||
<filteredResources/>
|
||||
</projectDescription>
|
||||
2
user-service/.settings/org.eclipse.buildship.core.prefs
Normal file
2
user-service/.settings/org.eclipse.buildship.core.prefs
Normal file
@@ -0,0 +1,2 @@
|
||||
connection.project.dir=..
|
||||
eclipse.preferences.version=1
|
||||
13
user-service/.settings/org.eclipse.jdt.core.prefs
Normal file
13
user-service/.settings/org.eclipse.jdt.core.prefs
Normal file
@@ -0,0 +1,13 @@
|
||||
#
|
||||
#Sat Apr 01 12:17:23 CEST 2023
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
|
||||
org.eclipse.jdt.core.compiler.source=17
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.compliance=17
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
10
user-service/.settings/org.eclipse.wst.common.component
Normal file
10
user-service/.settings/org.eclipse.wst.common.component
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project-modules id="moduleCoreId" project-version="1.5.0">
|
||||
<wb-module deploy-name="user-service">
|
||||
<property name="context-root" value="user-service"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/resources"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/webapp"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/java"/>
|
||||
<wb-resource deploy-path="/" source-path="src/main/webapp"/>
|
||||
</wb-module>
|
||||
</project-modules>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<fixed facet="jst.java"/>
|
||||
<fixed facet="jst.web"/>
|
||||
<installed facet="jst.web" version="2.4"/>
|
||||
<installed facet="jst.java" version="17"/>
|
||||
</faceted-project>
|
||||
13
user-service/bin/main/META-INF/hibernate.cfg.xml
Normal file
13
user-service/bin/main/META-INF/hibernate.cfg.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE hibernate-configuration PUBLIC
|
||||
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
||||
|
||||
<hibernate-configuration>
|
||||
<session-factory>
|
||||
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
|
||||
|
||||
<!-- Validate the database schema on startup -->
|
||||
<property name="hbm2ddl.auto">validate</property>
|
||||
</session-factory>
|
||||
</hibernate-configuration>
|
||||
20
user-service/bin/main/META-INF/persistence.xml
Normal file
20
user-service/bin/main/META-INF/persistence.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
|
||||
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
|
||||
version="1.0" >
|
||||
|
||||
<persistence-unit name="registration"
|
||||
transaction-type="JTA">
|
||||
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
||||
<jta-data-source>java:/User</jta-data-source>
|
||||
<properties>
|
||||
<property name="hibernate.dialect"
|
||||
value="org.hibernate.dialect.MySQLDialect" />
|
||||
<!--property
|
||||
name="javax.persistence.schema-generation.database.action"
|
||||
value="drop-and-create" /-->
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
||||
6
user-service/bin/main/WEB-INF/web.xml
Normal file
6
user-service/bin/main/WEB-INF/web.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><web-app version="5.0"
|
||||
xmlns="https://jakarta.ee/xml/ns/jakartaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd">
|
||||
|
||||
</web-app>
|
||||
BIN
user-service/bin/main/de/oaa/xxx/user/LoginService.class
Normal file
BIN
user-service/bin/main/de/oaa/xxx/user/LoginService.class
Normal file
Binary file not shown.
BIN
user-service/bin/main/de/oaa/xxx/user/Registration.class
Normal file
BIN
user-service/bin/main/de/oaa/xxx/user/Registration.class
Normal file
Binary file not shown.
BIN
user-service/bin/main/de/oaa/xxx/user/User.class
Normal file
BIN
user-service/bin/main/de/oaa/xxx/user/User.class
Normal file
Binary file not shown.
BIN
user-service/bin/main/de/oaa/xxx/user/UserApplication.class
Normal file
BIN
user-service/bin/main/de/oaa/xxx/user/UserApplication.class
Normal file
Binary file not shown.
BIN
user-service/bin/main/de/oaa/xxx/user/UserDAO.class
Normal file
BIN
user-service/bin/main/de/oaa/xxx/user/UserDAO.class
Normal file
Binary file not shown.
BIN
user-service/bin/main/de/oaa/xxx/user/UserEntity.class
Normal file
BIN
user-service/bin/main/de/oaa/xxx/user/UserEntity.class
Normal file
Binary file not shown.
BIN
user-service/bin/main/de/oaa/xxx/user/UserResource.class
Normal file
BIN
user-service/bin/main/de/oaa/xxx/user/UserResource.class
Normal file
Binary file not shown.
1
user-service/bin/main/index.html
Normal file
1
user-service/bin/main/index.html
Normal file
@@ -0,0 +1 @@
|
||||
<h1>Was machst du hier?</h1>
|
||||
17
user-service/bin/main/log4j2.xml
Normal file
17
user-service/bin/main/log4j2.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="INFO">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
|
||||
</Console>
|
||||
<File name="MyFile" fileName="all.log" immediateFlush="false" append="false">
|
||||
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
|
||||
</File>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="debug">
|
||||
<AppenderRef ref="Console" />
|
||||
<AppenderRef ref="MyFile"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
BIN
user-service/bin/main/xxx.jks
Normal file
BIN
user-service/bin/main/xxx.jks
Normal file
Binary file not shown.
40
user-service/build.gradle
Normal file
40
user-service/build.gradle
Normal file
@@ -0,0 +1,40 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'war'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
java {
|
||||
srcDir 'src/main/java'
|
||||
}
|
||||
resources {
|
||||
srcDir 'src/main/webapp'
|
||||
// srcDir 'src/main/resources'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'jakarta.platform:jakarta.jakartaee-web-api:9.0.0'
|
||||
compileOnly 'jakarta.persistence:jakarta.persistence-api:3.1.0'
|
||||
compileOnly 'jakarta.resource:jakarta.resource-api:2.1.0'
|
||||
|
||||
compileOnly 'org.jboss.ejb3:jboss-ejb3-ext-api:2.3.0.Final'
|
||||
|
||||
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
|
||||
implementation 'io.jsonwebtoken:jjwt-impl:0.11.5'
|
||||
implementation 'io.jsonwebtoken:jjwt-gson:0.11.5'
|
||||
|
||||
compileOnly 'org.apache.logging.log4j:log4j-slf4j-impl:2.20.0'
|
||||
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
BIN
user-service/build/classes/java/main/de/oaa/xxx/user/User.class
Normal file
BIN
user-service/build/classes/java/main/de/oaa/xxx/user/User.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
user-service/build/libs/user-service.war
Normal file
BIN
user-service/build/libs/user-service.war
Normal file
Binary file not shown.
13
user-service/build/resources/main/META-INF/hibernate.cfg.xml
Normal file
13
user-service/build/resources/main/META-INF/hibernate.cfg.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE hibernate-configuration PUBLIC
|
||||
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
||||
|
||||
<hibernate-configuration>
|
||||
<session-factory>
|
||||
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
|
||||
|
||||
<!-- Validate the database schema on startup -->
|
||||
<property name="hbm2ddl.auto">validate</property>
|
||||
</session-factory>
|
||||
</hibernate-configuration>
|
||||
20
user-service/build/resources/main/META-INF/persistence.xml
Normal file
20
user-service/build/resources/main/META-INF/persistence.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
|
||||
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
|
||||
version="1.0" >
|
||||
|
||||
<persistence-unit name="registration"
|
||||
transaction-type="JTA">
|
||||
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
||||
<jta-data-source>java:/User</jta-data-source>
|
||||
<properties>
|
||||
<property name="hibernate.dialect"
|
||||
value="org.hibernate.dialect.MySQLDialect" />
|
||||
<!--property
|
||||
name="javax.persistence.schema-generation.database.action"
|
||||
value="drop-and-create" /-->
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
||||
6
user-service/build/resources/main/WEB-INF/web.xml
Normal file
6
user-service/build/resources/main/WEB-INF/web.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><web-app version="5.0"
|
||||
xmlns="https://jakarta.ee/xml/ns/jakartaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd">
|
||||
|
||||
</web-app>
|
||||
1
user-service/build/resources/main/index.html
Normal file
1
user-service/build/resources/main/index.html
Normal file
@@ -0,0 +1 @@
|
||||
<h1>Was machst du hier?</h1>
|
||||
17
user-service/build/resources/main/log4j2.xml
Normal file
17
user-service/build/resources/main/log4j2.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="INFO">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
|
||||
</Console>
|
||||
<File name="MyFile" fileName="all.log" immediateFlush="false" append="false">
|
||||
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
|
||||
</File>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="debug">
|
||||
<AppenderRef ref="Console" />
|
||||
<AppenderRef ref="MyFile"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
BIN
user-service/build/resources/main/xxx.jks
Normal file
BIN
user-service/build/resources/main/xxx.jks
Normal file
Binary file not shown.
BIN
user-service/build/tmp/compileJava/previous-compilation-data.bin
Normal file
BIN
user-service/build/tmp/compileJava/previous-compilation-data.bin
Normal file
Binary file not shown.
2
user-service/build/tmp/war/MANIFEST.MF
Normal file
2
user-service/build/tmp/war/MANIFEST.MF
Normal file
@@ -0,0 +1,2 @@
|
||||
Manifest-Version: 1.0
|
||||
|
||||
113
user-service/src/main/java/de/oaa/xxx/user/LoginService.java
Normal file
113
user-service/src/main/java/de/oaa/xxx/user/LoginService.java
Normal file
@@ -0,0 +1,113 @@
|
||||
package de.oaa.xxx.user;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.Key;
|
||||
import java.security.KeyStore;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.UnrecoverableKeyException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jws;
|
||||
import io.jsonwebtoken.JwtBuilder;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.ws.rs.PathParam;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.POST;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.QueryParam;
|
||||
import jakarta.ws.rs.core.Context;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.core.Response.Status;
|
||||
import jakarta.ws.rs.core.UriInfo;
|
||||
|
||||
@ApplicationScoped
|
||||
@Path("login")
|
||||
public class LoginService {
|
||||
|
||||
private String keyPass = "XUR!Rv&f$j3UsqD&";
|
||||
private String alias = "xxx";
|
||||
private Logger LOGGER = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Inject private UserDAO dao;
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public Response login(@QueryParam("email") String email, @QueryParam("hash") String hash, @Context HttpServletRequest req) throws NoSuchAlgorithmException, CertificateException, IOException, KeyStoreException, UnrecoverableKeyException {
|
||||
UserEntity user = dao.login(email, hash);
|
||||
if (user != null) {
|
||||
LOGGER.info("User erolgreich angemeldet: " + email);
|
||||
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
keystore.load(getClass().getClassLoader().getResourceAsStream("/xxx.jks"), keyPass.toCharArray());
|
||||
Key key = keystore.getKey(alias, keyPass.toCharArray());
|
||||
JwtBuilder builder = Jwts.builder()
|
||||
.setIssuer("OAA Games")
|
||||
.setIssuedAt(new Date())
|
||||
.claim("email", email)
|
||||
.claim("client", req.getRemoteAddr())
|
||||
.claim("userId", user.getUserId())
|
||||
.signWith(key, SignatureAlgorithm.RS256);
|
||||
String token = builder.compact();
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Erstellter token: {}", token);
|
||||
}
|
||||
return Response.ok(token).build();
|
||||
} else {
|
||||
return Response.noContent().build();
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Response checkToken(@QueryParam("token") String token, @Context HttpServletRequest req, @Context UriInfo urlInfo) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, UnrecoverableKeyException {
|
||||
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
keystore.load(getClass().getClassLoader().getResourceAsStream("/xxx.jks"), keyPass.toCharArray());
|
||||
Key key = keystore.getKey(alias, keyPass.toCharArray());
|
||||
|
||||
Jws<Claims> claimsJws = Jwts.parserBuilder().setSigningKey(key).build().parseClaimsJws(token);
|
||||
String client = claimsJws.getBody().get("client").toString();
|
||||
UUID fromString = UUID.fromString(claimsJws.getBody().get("userId").toString());
|
||||
UserEntity user = dao.findById(fromString);
|
||||
if (user != null && user.getEmail().equals(claimsJws.getBody().get("email").toString()) && req.getRemoteAddr().equals(client)) {
|
||||
return Response.created(urlInfo.getAbsolutePathBuilder().path(user.getUserId().toString()).build()).build();
|
||||
} else {
|
||||
return Response.status(Status.BAD_REQUEST).build();
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{userId}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Response get(@PathParam("userId") String userId) {
|
||||
UserEntity entity = dao.findById(UUID.fromString(userId));
|
||||
if (entity != null) {
|
||||
return Response.ok(entity.toUser()).build();
|
||||
} else {
|
||||
return Response.noContent().build();
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("publickey")
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public Response getPK() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
|
||||
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
keystore.load(getClass().getClassLoader().getResourceAsStream("/xxx.jks"), keyPass.toCharArray());
|
||||
String string = Base64.getEncoder().encodeToString(keystore.getCertificate(alias).getPublicKey().getEncoded());
|
||||
return Response.ok(string).build();
|
||||
}
|
||||
}
|
||||
50
user-service/src/main/java/de/oaa/xxx/user/Registration.java
Normal file
50
user-service/src/main/java/de/oaa/xxx/user/Registration.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package de.oaa.xxx.user;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Registration {
|
||||
|
||||
private UUID id;
|
||||
private String name;
|
||||
private String email;
|
||||
private String passwordHash;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getPasswordHash() {
|
||||
return passwordHash;
|
||||
}
|
||||
|
||||
public void setPasswordHash(String passwordHash) {
|
||||
this.passwordHash = passwordHash;
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Registration [id=" + id + ", name=" + name + ", email=" + email + ", passwordHash=" + passwordHash
|
||||
+ "]";
|
||||
}
|
||||
|
||||
}
|
||||
43
user-service/src/main/java/de/oaa/xxx/user/User.java
Normal file
43
user-service/src/main/java/de/oaa/xxx/user/User.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package de.oaa.xxx.user;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class User {
|
||||
|
||||
private UUID userId;
|
||||
private String name;
|
||||
private String email;
|
||||
private String password;
|
||||
|
||||
public UUID getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(UUID userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package de.oaa.xxx.user;
|
||||
|
||||
import jakarta.ws.rs.ApplicationPath;
|
||||
import jakarta.ws.rs.core.Application;
|
||||
|
||||
@ApplicationPath("/")
|
||||
public class UserApplication extends Application {
|
||||
|
||||
}
|
||||
74
user-service/src/main/java/de/oaa/xxx/user/UserDAO.java
Normal file
74
user-service/src/main/java/de/oaa/xxx/user/UserDAO.java
Normal file
@@ -0,0 +1,74 @@
|
||||
package de.oaa.xxx.user;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import jakarta.persistence.TypedQuery;
|
||||
import jakarta.transaction.UserTransaction;
|
||||
|
||||
@ApplicationScoped
|
||||
public class UserDAO {
|
||||
|
||||
private Logger LOGGER = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@PersistenceContext(name = "user")
|
||||
private EntityManager entityManager;
|
||||
@Resource
|
||||
private UserTransaction transaction;
|
||||
|
||||
public void update(UserEntity toUpdate) {
|
||||
try {
|
||||
transaction.begin();
|
||||
entityManager.merge(toUpdate);
|
||||
transaction.commit();
|
||||
} catch (Exception exception) {
|
||||
LOGGER.error(exception.getMessage(), exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void persist(UserEntity toPersist) {
|
||||
try {
|
||||
transaction.begin();
|
||||
LOGGER.info("Persisting Entity " + toPersist);
|
||||
entityManager.persist(toPersist);
|
||||
transaction.commit();
|
||||
} catch (Exception exception) {
|
||||
LOGGER.error(exception.getMessage(), exception);
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(UserEntity toRemove) {
|
||||
try {
|
||||
transaction.begin();
|
||||
entityManager.remove(toRemove);
|
||||
transaction.commit();
|
||||
} catch (Exception exception) {
|
||||
LOGGER.error(exception.getMessage(), exception);
|
||||
}
|
||||
}
|
||||
|
||||
public UserEntity findById(UUID id) {
|
||||
return entityManager.find(UserEntity.class, id);
|
||||
}
|
||||
|
||||
public UserEntity login(String email, String password) {
|
||||
try {
|
||||
transaction.begin();
|
||||
TypedQuery<UserEntity> query = entityManager.createQuery("select u from UserEntity u where u.email = :email and u.password = :password", UserEntity.class);
|
||||
query.setParameter("email", email);
|
||||
query.setParameter("password", password);
|
||||
UserEntity result = query.getSingleResult();
|
||||
transaction.commit();
|
||||
return result;
|
||||
} catch (Exception exception) {
|
||||
LOGGER.error(exception.getMessage(), exception);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
62
user-service/src/main/java/de/oaa/xxx/user/UserEntity.java
Normal file
62
user-service/src/main/java/de/oaa/xxx/user/UserEntity.java
Normal file
@@ -0,0 +1,62 @@
|
||||
package de.oaa.xxx.user;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "user")
|
||||
public class UserEntity {
|
||||
@Id
|
||||
@Column
|
||||
private UUID userId;
|
||||
@Column
|
||||
private String name;
|
||||
@Column
|
||||
private String email;
|
||||
@Column
|
||||
private String password;
|
||||
|
||||
public UUID getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(UUID userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public User toUser() {
|
||||
User user = new User();
|
||||
user.setEmail(email);
|
||||
user.setName(name);
|
||||
user.setUserId(userId);
|
||||
return user;
|
||||
}
|
||||
}
|
||||
38
user-service/src/main/java/de/oaa/xxx/user/UserResource.java
Normal file
38
user-service/src/main/java/de/oaa/xxx/user/UserResource.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package de.oaa.xxx.user;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.POST;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
@ApplicationScoped
|
||||
@Path("user")
|
||||
public class UserResource {
|
||||
|
||||
@Inject private UserDAO dao;
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(UserResource.class);
|
||||
|
||||
@POST
|
||||
public Response userAnlegen(Registration registration) {
|
||||
try {
|
||||
UserEntity entity = new UserEntity();
|
||||
entity.setUserId(UUID.randomUUID());
|
||||
entity.setEmail(registration.getEmail());
|
||||
entity.setName(registration.getName());
|
||||
entity.setPassword(registration.getPasswordHash());
|
||||
dao.persist(entity);
|
||||
return Response.ok().build();
|
||||
} catch (Exception exception) {
|
||||
LOGGER.error(exception.getMessage(), exception);
|
||||
return Response.serverError().build();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
17
user-service/src/main/resources/log4j2.xml
Normal file
17
user-service/src/main/resources/log4j2.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="INFO">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
|
||||
</Console>
|
||||
<File name="MyFile" fileName="all.log" immediateFlush="false" append="false">
|
||||
<PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
|
||||
</File>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="debug">
|
||||
<AppenderRef ref="Console" />
|
||||
<AppenderRef ref="MyFile"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
13
user-service/src/main/webapp/META-INF/hibernate.cfg.xml
Normal file
13
user-service/src/main/webapp/META-INF/hibernate.cfg.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE hibernate-configuration PUBLIC
|
||||
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
||||
|
||||
<hibernate-configuration>
|
||||
<session-factory>
|
||||
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
|
||||
|
||||
<!-- Validate the database schema on startup -->
|
||||
<property name="hbm2ddl.auto">validate</property>
|
||||
</session-factory>
|
||||
</hibernate-configuration>
|
||||
20
user-service/src/main/webapp/META-INF/persistence.xml
Normal file
20
user-service/src/main/webapp/META-INF/persistence.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
|
||||
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
|
||||
version="1.0" >
|
||||
|
||||
<persistence-unit name="registration"
|
||||
transaction-type="JTA">
|
||||
<provider>org.hibernate.ejb.HibernatePersistence</provider>
|
||||
<jta-data-source>java:/User</jta-data-source>
|
||||
<properties>
|
||||
<property name="hibernate.dialect"
|
||||
value="org.hibernate.dialect.MySQLDialect" />
|
||||
<!--property
|
||||
name="javax.persistence.schema-generation.database.action"
|
||||
value="drop-and-create" /-->
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
||||
6
user-service/src/main/webapp/WEB-INF/web.xml
Normal file
6
user-service/src/main/webapp/WEB-INF/web.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><web-app version="5.0"
|
||||
xmlns="https://jakarta.ee/xml/ns/jakartaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd">
|
||||
|
||||
</web-app>
|
||||
1
user-service/src/main/webapp/index.html
Normal file
1
user-service/src/main/webapp/index.html
Normal file
@@ -0,0 +1 @@
|
||||
<h1>Was machst du hier?</h1>
|
||||
BIN
user-service/src/main/webapp/xxx.jks
Normal file
BIN
user-service/src/main/webapp/xxx.jks
Normal file
Binary file not shown.
Reference in New Issue
Block a user