51 lines
1.4 KiB
Java
51 lines
1.4 KiB
Java
package de.tavolio.realm.client;
|
|
|
|
import de.tavolio.bootstrap.Credentials;
|
|
import de.tavolio.bootstrap.model.Client;
|
|
import de.tavolio.realm.RealmEntity;
|
|
import de.tavolio.realm.RealmRepo;
|
|
import io.quarkus.elytron.security.common.BcryptUtil;
|
|
import jakarta.enterprise.context.ApplicationScoped;
|
|
import jakarta.inject.Inject;
|
|
import jakarta.transaction.Transactional;
|
|
import jakarta.ws.rs.NotFoundException;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import java.util.Map;
|
|
|
|
@ApplicationScoped
|
|
public class ClientService
|
|
{
|
|
@Inject
|
|
ClientRepo clientRepo;
|
|
|
|
@Inject
|
|
RealmRepo realmRepo;
|
|
|
|
public ClientEntity findByIdAndRealm(String clientId, RealmEntity realm)
|
|
{
|
|
ClientEntity client = clientRepo.findByRealmAndId(realm, clientId);
|
|
if (client != null)
|
|
{
|
|
return client;
|
|
}
|
|
throw new NotFoundException();
|
|
}
|
|
|
|
@Transactional
|
|
public ClientEntity create(String realmKey, ClientCreation client)
|
|
{
|
|
RealmEntity realm = realmRepo.findByKey(realmKey);
|
|
if (realm != null)
|
|
{
|
|
ClientEntity entity = new ClientEntity();
|
|
entity.setId(client.id());
|
|
entity.setSecret(BcryptUtil.bcryptHash(client.secret()));
|
|
entity.setRealm(realm);
|
|
clientRepo.persist(entity);
|
|
return entity;
|
|
}
|
|
throw new NotFoundException();
|
|
}
|
|
}
|