Когда вы запускаете в браузере localhost: 8080 / users , в базу данных будет добавлен один пользователь. Затем, когда вы пытаетесь запустить localhost: 8080 / users / aqq , вы получаете внутреннюю ошибку сервера: org.wildfly.common.code c .DecodeException: COM00508: недопустимый символ base 64
Подскажите, пожалуйста, почему не работает.
application.properties
quarkus.security.jdbc.enabled=true
quarkus.security.jdbc.principal-query.sql=SELECT u.password, u.salt, u.iteration_count, u.role FROM user u WHERE u.userMail=?
quarkus.security.jdbc.principal-query.bcrypt-password-mapper.enabled=true
quarkus.security.jdbc.principal-query.bcrypt-password-mapper.password-index=1
quarkus.security.jdbc.principal-query.bcrypt-password-mapper.salt-index=2
quarkus.security.jdbc.principal-query.bcrypt-password-mapper.iteration-count-index=3
quarkus.security.jdbc.principal-query.attribute-mappings.0.index=4
quarkus.security.jdbc.principal-query.attribute-mappings.0.to=groups
quarkus.security.jdbc.principal-query.bcrypt-password-mapper.hash-encoding=base64
User.class
package com.murawski.model;
import javax.persistence.*;
import javax.validation.constraints.Email;
@Entity
@Table(uniqueConstraints = @UniqueConstraint(columnNames = {"userMail", "role"}))
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Email
private String userMail;
private String password;
private byte[] salt;
private Integer iterationCount;
@Enumerated(value = EnumType.STRING)
private Role role;
public User(@Email String userMail, String password, byte[] salt, Integer iterationCount, Role
role) {
this.userMail = userMail;
this.password = password;
this.salt = salt;
this.iterationCount = iterationCount;
this.role = role;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUserMail() {
return userMail;
}
public void setUserMail(String userMail) {
this.userMail = userMail;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Role getRole() {
return role;
}
public void setRole(Role role) {
this.role = role;
}
public User() {
}
public Integer getIterationCount() {
return iterationCount;
}
public void setIterationCount(Integer iterationCount) {
this.iterationCount = iterationCount;
}
public byte[] getSalt() {
return salt;
}
public void setSalt(byte[] salt) {
this.salt = salt;
}
}
UserRepository.inteface
package com.murawski.model;
import org.springframework.data.jpa.repository.JpaRepository;
public interface UserRepository extends JpaRepository<User, Long> {
}
UserApi.class
package com.murawski;
import com.murawski.model.BookRepository;
import com.murawski.model.Role;
import com.murawski.model.User;
import com.murawski.model.UserRepository;
import io.quarkus.elytron.security.common.BcryptUtil;
import javax.annotation.security.RolesAllowed;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.SecurityContext;
import java.util.Base64;
import java.util.List;
@Path("/users")
@Produces(MediaType.APPLICATION_JSON)
public class UserApi {
private UserRepository userRepository;
@Inject
public UserApi(UserRepository userRepository) {
this.userRepository = userRepository;
addUser(new User("user@gmail.com", "pass", "passpasspasspass".getBytes(), 4, Role.USER));
}
@GET
public List<User> getUserList() {
return userRepository.findAll();
}
@POST
public void addUser(User user) {
user.setPassword(BcryptUtil.bcryptHash(user.getPassword(), user.getIterationCount(),
user.getSalt()));
String hashSalt = Base64.getEncoder().encodeToString(user.getSalt());
user.setSalt(hashSalt.getBytes());
userRepository.save(user);
}
@GET
@RolesAllowed("USER")
@Path("/aqq")
public String me(@Context SecurityContext securityContext) {
return securityContext.getUserPrincipal().getName();
}
}