User etwas überarbeitet
This commit is contained in:
@@ -3,13 +3,8 @@ package de.mbremer.secutity;
|
|||||||
import de.mbremer.room.Room;
|
import de.mbremer.room.Room;
|
||||||
import io.quarkus.elytron.security.common.BcryptUtil;
|
import io.quarkus.elytron.security.common.BcryptUtil;
|
||||||
import io.quarkus.hibernate.orm.panache.PanacheEntity;
|
import io.quarkus.hibernate.orm.panache.PanacheEntity;
|
||||||
import io.quarkus.security.jpa.Password;
|
import io.quarkus.security.jpa.*;
|
||||||
import io.quarkus.security.jpa.Roles;
|
import lombok.*;
|
||||||
import io.quarkus.security.jpa.UserDefinition;
|
|
||||||
import io.quarkus.security.jpa.Username;
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
@@ -34,6 +29,7 @@ public class User extends PanacheEntity {
|
|||||||
|
|
||||||
@OneToOne
|
@OneToOne
|
||||||
@Getter
|
@Getter
|
||||||
|
@Setter
|
||||||
private Room room;
|
private Room room;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,28 +37,19 @@ public class User extends PanacheEntity {
|
|||||||
*/
|
*/
|
||||||
@Roles
|
@Roles
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
|
||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private String role = "USER";
|
private String role = "USER";
|
||||||
|
|
||||||
public User setPassword(String password) {
|
public void setPassword(String password) {
|
||||||
this.password = BcryptUtil.bcryptHash(password);
|
this.password = BcryptUtil.bcryptHash(password);
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public User setUsername(String username) {
|
public void setUsername(String username) {
|
||||||
this.username = username == null ? null : username.trim();
|
this.username = username == null ? null : username.trim();
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public User setRole(String role) {
|
public void setRole(String role) {
|
||||||
this.role = role == null ? role : role.toUpperCase();
|
this.role = role == null ? role : role.toUpperCase();
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public User setRoom(Room room) {
|
|
||||||
this.room = room;
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasRoleAdmin() {
|
public boolean hasRoleAdmin() {
|
||||||
|
|||||||
@@ -5,15 +5,24 @@ import de.mbremer.room.Room;
|
|||||||
import javax.ws.rs.FormParam;
|
import javax.ws.rs.FormParam;
|
||||||
|
|
||||||
public class UserForm {
|
public class UserForm {
|
||||||
public @FormParam("username") String username;
|
public @FormParam("username")
|
||||||
public @FormParam("password") String password;
|
String username;
|
||||||
public @FormParam("passwordVerify") String passwordVerify;
|
public @FormParam("password")
|
||||||
public @FormParam("room") String room;
|
String password;
|
||||||
public @FormParam("role") String role;
|
public @FormParam("passwordVerify")
|
||||||
|
String passwordVerify;
|
||||||
|
public @FormParam("room")
|
||||||
|
String room;
|
||||||
|
public @FormParam("role")
|
||||||
|
String role;
|
||||||
|
|
||||||
public User getUser() {
|
public User getUser() {
|
||||||
return new User().setUsername(username).setPassword(password).setRole(role)
|
User user = new User();
|
||||||
.setRoom((Room) Room.find("name", room).singleResultOptional().orElse(null));
|
user.setUsername(username);
|
||||||
|
user.setPassword(password);
|
||||||
|
user.setRole(role);
|
||||||
|
user.setRoom((Room) Room.find("name", room).singleResultOptional().orElse(null));
|
||||||
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean verifyPassword() {
|
public boolean verifyPassword() {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
quarkus.datasource.db-kind=postgresql
|
quarkus.datasource.db-kind=postgresql
|
||||||
|
|
||||||
quarkus.hibernate-orm.dialect=org.hibernate.dialect.PostgreSQL95Dialect
|
quarkus.hibernate-orm.dialect=org.hibernate.dialect.PostgreSQL95Dialect
|
||||||
|
%dev.quarkus.hibernate-orm.log.sql=true
|
||||||
|
|
||||||
quarkus.flyway.migrate-at-start=true
|
quarkus.flyway.migrate-at-start=true
|
||||||
# theoretische soll auch 'filesystem:' funktionieren
|
# theoretische soll auch 'filesystem:' funktionieren
|
||||||
|
|||||||
@@ -30,14 +30,17 @@ class UserResourceTest {
|
|||||||
|
|
||||||
PanacheMock.mock(User.class);
|
PanacheMock.mock(User.class);
|
||||||
PanacheQuery panacheQuery = mock(PanacheQuery.class);
|
PanacheQuery panacheQuery = mock(PanacheQuery.class);
|
||||||
when(panacheQuery.singleResult()).thenReturn(new User());
|
User user = new User();
|
||||||
|
user.setUsername("testuser");
|
||||||
|
|
||||||
|
when(panacheQuery.singleResult()).thenReturn(user);
|
||||||
when(User.find("username", "user")).thenReturn(panacheQuery);
|
when(User.find("username", "user")).thenReturn(panacheQuery);
|
||||||
|
|
||||||
given()
|
given()
|
||||||
.when().get("/user")
|
.when().get("/user")
|
||||||
.then()
|
.then()
|
||||||
.statusCode(200)
|
.statusCode(200)
|
||||||
.body(containsString("Hallo"));
|
.body(containsString("Hallo testuser"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user