Skip to content

Commit

Permalink
enhancement(auth-service): initial version of auth service
Browse files Browse the repository at this point in the history
  • Loading branch information
zZHorizonZz committed Jul 21, 2023
1 parent b25dc96 commit 9e610ce
Show file tree
Hide file tree
Showing 25 changed files with 439 additions and 101 deletions.
61 changes: 47 additions & 14 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
<version>1.0-SNAPSHOT</version>
<properties>
<compiler-plugin.version>3.11.0</compiler-plugin.version>
<lombok.version>1.18.28</lombok.version>
<mapstruct.version>1.5.5.Final</mapstruct.version>
<maven.compiler.release>17</maven.compiler.release>
<microprofile-jwt-auth-api.version>2.1</microprofile-jwt-auth-api.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>3.2.0.Final</quarkus.platform.version>
<mapstruct.version>1.4.2.Final</mapstruct.version>
<skipITs>true</skipITs>
<surefire-plugin.version>3.0.0</surefire-plugin.version>
</properties>
Expand Down Expand Up @@ -53,10 +55,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-reactive-panache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-reactive</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-reactive-pg-client</artifactId>
Expand All @@ -70,10 +68,41 @@
<artifactId>quarkus-minio</artifactId>
<version>3.1.0.Final</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-security</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile.jwt</groupId>
<artifactId>microprofile-jwt-auth-api</artifactId>
<version>${microprofile-jwt-auth-api.version}</version>
</dependency>
<dependency>
<groupId>at.favre.lib</groupId>
<artifactId>bcrypt</artifactId>
<version>0.10.2</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-api</artifactId>
<version>0.11.2</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-impl</artifactId>
<version>0.11.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt-jackson</artifactId>
<version>0.11.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.28</version>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -117,21 +146,25 @@
<arg>-parameters</arg>
</compilerArgs>
<annotationProcessorPaths>
<!-- Your existing annotation processor(s)... -->
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-panache-common</artifactId>
<version>${quarkus.platform.version}</version>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.28</version>
<version>${lombok.version}</version>
</path>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct.version}</version>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
</path>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-panache-common</artifactId>
<version>${quarkus.platform.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
Expand Down
14 changes: 9 additions & 5 deletions server/src/main/java/dev/shiperist/entity/AccountEntity.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package dev.shiperist.entity;

import io.quarkus.hibernate.reactive.panache.PanacheEntity;
import io.quarkus.hibernate.reactive.panache.PanacheEntityBase;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@Entity
@Table(name = "account")
@Entity(name = "Account")
@Table(name = "account", schema = "public")
@EqualsAndHashCode(callSuper = true)
public class AccountEntity extends PanacheEntity {
public class AccountEntity extends PanacheEntityBase {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;

@Column(name = "user_id")
private String userId;
private Long userId;

@Column(name = "type")
private String type;
Expand Down
14 changes: 9 additions & 5 deletions server/src/main/java/dev/shiperist/entity/SessionEntity.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
package dev.shiperist.entity;

import io.quarkus.hibernate.reactive.panache.PanacheEntity;
import io.quarkus.hibernate.reactive.panache.PanacheEntityBase;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;

@Data
@Entity
@Table(name = "session")
@Entity(name = "Session")
@Table(name = "session", schema = "public")
@EqualsAndHashCode(callSuper = true)
public class SessionEntity extends PanacheEntity {
public class SessionEntity extends PanacheEntityBase {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;

@Column(name = "session_token", unique = true)
private String sessionToken;

@Column(name = "user_id")
private String userId;
private Long userId;

@Column(name = "expires")
private LocalDateTime expires;
Expand Down
20 changes: 12 additions & 8 deletions server/src/main/java/dev/shiperist/entity/UserEntity.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package dev.shiperist.entity;

import io.quarkus.hibernate.reactive.panache.PanacheEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import io.quarkus.hibernate.reactive.panache.PanacheEntityBase;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;
import java.util.Set;

@Data
@Entity
@Table(name = "user")
@Entity(name = "User")
@Table(name = "user", schema = "public")
@EqualsAndHashCode(callSuper = true)
public class UserEntity extends PanacheEntity {
public class UserEntity extends PanacheEntityBase {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;

@Column(name = "name")
private String name;
Expand All @@ -29,6 +30,9 @@ public class UserEntity extends PanacheEntity {
@Column(name = "image")
private String image;

@Column(name = "password")
private String password;

@OneToMany(mappedBy = "user")
private Set<AccountEntity> accounts;

Expand Down
15 changes: 13 additions & 2 deletions server/src/main/java/dev/shiperist/mapper/AccountMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@

import dev.shiperist.entity.AccountEntity;
import dev.shiperist.model.Account;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;

@Mapper(componentModel = "jakarta")
import java.util.List;

@Mapper(config = QuarkusMappingConfig.class)
public interface AccountMapper {

AccountEntity toEntity(Account domain);
List<Account> toDomainList(List<AccountEntity> entities);

Account toDomain(AccountEntity entity);

@InheritInverseConfiguration(name = "toDomain")
AccountEntity toEntity(Account domain);

void updateEntityFromDomain(Account domain, @MappingTarget AccountEntity entity);

void updateDomainFromEntity(AccountEntity entity, @MappingTarget Account domain);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dev.shiperist.mapper;

import org.mapstruct.MapperConfig;

@MapperConfig(componentModel = "jakarta-cdi")
interface QuarkusMappingConfig {
}
15 changes: 13 additions & 2 deletions server/src/main/java/dev/shiperist/mapper/SessionMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@

import dev.shiperist.entity.SessionEntity;
import dev.shiperist.model.Session;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;

@Mapper(componentModel = "jakarta")
import java.util.List;

@Mapper(config = QuarkusMappingConfig.class)
public interface SessionMapper {

SessionEntity toEntity(Session domain);
List<Session> toDomainList(List<SessionEntity> entities);

Session toDomain(SessionEntity entity);

@InheritInverseConfiguration(name = "toDomain")
SessionEntity toEntity(Session domain);

void updateEntityFromDomain(Session domain, @MappingTarget SessionEntity entity);

void updateDomainFromEntity(SessionEntity entity, @MappingTarget Session domain);
}
15 changes: 13 additions & 2 deletions server/src/main/java/dev/shiperist/mapper/UserMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@

import dev.shiperist.entity.UserEntity;
import dev.shiperist.model.User;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;

@Mapper(componentModel = "jakarta")
import java.util.List;

@Mapper(config = QuarkusMappingConfig.class)
public interface UserMapper {

UserEntity toEntity(User domain);
List<User> toDomainList(List<UserEntity> entities);

User toDomain(UserEntity entity);

@InheritInverseConfiguration(name = "toDomain")
UserEntity toEntity(User domain);

void updateEntityFromDomain(User domain, @MappingTarget UserEntity entity);

void updateDomainFromEntity(UserEntity entity, @MappingTarget User domain);
}
3 changes: 2 additions & 1 deletion server/src/main/java/dev/shiperist/model/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

@Data
public class Account {
private String userId;
private Long id;
private Long userId;
private String type;
private String provider;
private String providerAccountId;
Expand Down
3 changes: 2 additions & 1 deletion server/src/main/java/dev/shiperist/model/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

@Data
public class Session {
private Long id;
private Long userId;
private String sessionToken;
private String userId;
private LocalDateTime expires;
private UserEntity user;
}
2 changes: 2 additions & 0 deletions server/src/main/java/dev/shiperist/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

@Data
public class User {
private Long id;
private String name;
private String email;
private LocalDateTime emailVerified;
private String image;
public String password;
private Set<AccountEntity> accounts;
private Set<SessionEntity> sessions;
}
9 changes: 9 additions & 0 deletions server/src/main/java/dev/shiperist/model/UserCredentials.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.shiperist.model;

import lombok.Data;

@Data
public class UserCredentials {
private String email;
private String password;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import dev.shiperist.entity.AccountEntity;
import io.quarkus.hibernate.reactive.panache.PanacheRepository;
import io.quarkus.hibernate.reactive.panache.PanacheRepositoryBase;
import jakarta.enterprise.context.ApplicationScoped;

public class AccountRepository implements PanacheRepository<AccountEntity> {
@ApplicationScoped
public class AccountRepository implements PanacheRepositoryBase<AccountEntity, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

import dev.shiperist.entity.SessionEntity;
import io.quarkus.hibernate.reactive.panache.PanacheRepository;
import io.quarkus.hibernate.reactive.panache.PanacheRepositoryBase;
import io.smallrye.mutiny.Uni;
import jakarta.enterprise.context.ApplicationScoped;

public class SessionRepository implements PanacheRepository<SessionEntity> {
@ApplicationScoped
public class SessionRepository implements PanacheRepositoryBase<SessionEntity, Long> {

public Uni<SessionEntity> findByToken(String token) {
return find("sessionToken", token).firstResult();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import dev.shiperist.entity.UserEntity;
import io.quarkus.hibernate.reactive.panache.PanacheRepository;
import io.quarkus.hibernate.reactive.panache.PanacheRepositoryBase;
import io.smallrye.mutiny.Uni;
import jakarta.enterprise.context.ApplicationScoped;

public class UserRepository implements PanacheRepository<UserEntity> {
@ApplicationScoped
public class UserRepository implements PanacheRepositoryBase<UserEntity, Long> {

public Uni<UserEntity> findByEmail(String email) {
return find("email", email).firstResult();
Expand Down
Loading

0 comments on commit 9e610ce

Please sign in to comment.