Commit 790766fc authored by michael.simon's avatar michael.simon
Browse files

Larger user to identity change

parent aff06fd6
......@@ -18,6 +18,7 @@ import edu.kit.scc.webreg.entity.RegistryEntity;
import edu.kit.scc.webreg.entity.RegistryStatus;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.identity.IdentityEntity;
public interface RegistryDao extends BaseDao<RegistryEntity, Long> {
......@@ -28,8 +29,7 @@ public interface RegistryDao extends BaseDao<RegistryEntity, Long> {
List<RegistryEntity> findByServiceAndStatus(ServiceEntity service,
RegistryStatus status);
List<RegistryEntity> findByUserAndStatus(UserEntity user,
RegistryStatus... status);
List<RegistryEntity> findByIdentityAndStatus(IdentityEntity identity, RegistryStatus... status);
List<RegistryEntity> findByServiceAndUser(ServiceEntity service, UserEntity user);
......@@ -53,12 +53,9 @@ public interface RegistryDao extends BaseDao<RegistryEntity, Long> {
List<RegistryEntity> findByServiceAndStatus(String serviceShortName,
RegistryStatus status, Date date, int limit);
List<RegistryEntity> findByServiceAndUserAndNotStatus(ServiceEntity service,
UserEntity user, RegistryStatus... status);
List<RegistryEntity> findRegistriesForDepro(String serviceShortName);
List<RegistryEntity> findByUserAndNotStatusAndNotHidden(UserEntity user,
List<RegistryEntity> findByIdentityAndNotStatusAndNotHidden(IdentityEntity identity,
RegistryStatus... status);
List<RegistryEntity> findByServiceAndNotStatus(ServiceEntity service,
......@@ -75,4 +72,14 @@ public interface RegistryDao extends BaseDao<RegistryEntity, Long> {
RegistryStatus status);
List<RegistryEntity> findMissingIdentity();
List<RegistryEntity> findByServiceAndIdentityAndNotStatus(ServiceEntity service, IdentityEntity identity,
RegistryStatus... status);
List<RegistryEntity> findByIdentity(IdentityEntity identity);
List<RegistryEntity> findByUserAndStatus(UserEntity user, RegistryStatus... status);
RegistryEntity findByServiceAndIdentityAndStatus(ServiceEntity service, IdentityEntity identity,
RegistryStatus status);
}
......@@ -54,5 +54,9 @@ public interface RoleDao extends BaseDao<RoleEntity, Long> {
List<UserEntity> findUsersForRole(RoleEntity role);
List<GroupEntity> findGroupsForRole(RoleEntity role);
List<RoleEntity> findByUserIdList(List<Long> userIdList);
List<RoleEntity> findByIdentityId(Long identityId);
}
......@@ -17,14 +17,16 @@ import edu.kit.scc.webreg.entity.SshPubKeyStatus;
public interface SshPubKeyDao extends BaseDao<SshPubKeyEntity, Long> {
List<SshPubKeyEntity> findByUser(Long userId);
List<SshPubKeyEntity> findByKey(String encodedKey);
List<SshPubKeyEntity> findByUserAndStatus(Long userId, SshPubKeyStatus keyStatus);
List<SshPubKeyEntity> findMissingIdentity();
List<SshPubKeyEntity> findByUserAndKey(Long userId, String encodedKey);
List<SshPubKeyEntity> findByIdentityAndKey(Long identityId, String encodedKey);
List<SshPubKeyEntity> findByUserAndStatusWithRegs(Long userId, SshPubKeyStatus keyStatus);
List<SshPubKeyEntity> findByIdentityAndStatusWithRegs(Long identityId, SshPubKeyStatus keyStatus);
List<SshPubKeyEntity> findByKey(String encodedKey);
List<SshPubKeyEntity> findByIdentityAndStatus(Long identityId, SshPubKeyStatus keyStatus);
List<SshPubKeyEntity> findByIdentity(Long identityId);
}
......@@ -16,6 +16,7 @@ import java.util.List;
import edu.kit.scc.webreg.entity.GroupEntity;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.UserStatus;
import edu.kit.scc.webreg.entity.identity.IdentityEntity;
public interface UserDao extends BaseDao<UserEntity, Long> {
......@@ -31,4 +32,5 @@ public interface UserDao extends BaseDao<UserEntity, Long> {
List<UserEntity> findByStatus(UserStatus status);
UserEntity findByUidNumber(Long uidNumber);
List<UserEntity> findMissingIdentity();
List<UserEntity> findByIdentity(IdentityEntity identity);
}
......@@ -10,6 +10,8 @@
******************************************************************************/
package edu.kit.scc.webreg.dao.identity;
import java.util.List;
import edu.kit.scc.webreg.dao.BaseDao;
import edu.kit.scc.webreg.entity.identity.IdentityEntity;
......@@ -17,4 +19,6 @@ public interface IdentityDao extends BaseDao<IdentityEntity, Long> {
IdentityEntity findByUserId(Long userId);
List<IdentityEntity> findMissingTwoFaUserId();
}
......@@ -10,6 +10,8 @@
******************************************************************************/
package edu.kit.scc.webreg.dao.identity;
import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;
......@@ -34,6 +36,12 @@ public class JpaIdentityDao extends JpaBaseDao<IdentityEntity, Long> implements
else
return user.getIdentity();
}
@Override
@SuppressWarnings({"unchecked"})
public List<IdentityEntity> findMissingTwoFaUserId() {
return em.createQuery("select e from IdentityEntity e where e.twoFaUserId is null").getResultList();
}
@Override
public Class<IdentityEntity> getEntityClass() {
......
......@@ -35,6 +35,7 @@ import edu.kit.scc.webreg.entity.SamlIdpMetadataEntityStatus;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.ServiceEntity_;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.identity.IdentityEntity;
@Named
@ApplicationScoped
......@@ -268,16 +269,34 @@ public class JpaRegistryDao extends JpaBaseDao<RegistryEntity, Long> implements
return null;
}
}
@Override
public RegistryEntity findByServiceAndIdentityAndStatus(ServiceEntity service, IdentityEntity identity, RegistryStatus status) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<RegistryEntity> criteria = builder.createQuery(RegistryEntity.class);
Root<RegistryEntity> root = criteria.from(RegistryEntity.class);
criteria.where(builder.and(
builder.equal(root.get("service"), service),
builder.equal(root.get("identity"), identity),
builder.equal(root.get("registryStatus"), status)));
criteria.select(root);
try {
return em.createQuery(criteria).getSingleResult();
} catch (NoResultException e) {
return null;
}
}
@Override
public List<RegistryEntity> findByServiceAndUserAndNotStatus(ServiceEntity service, UserEntity user, RegistryStatus... status) {
public List<RegistryEntity> findByServiceAndIdentityAndNotStatus(ServiceEntity service, IdentityEntity identity, RegistryStatus... status) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<RegistryEntity> criteria = builder.createQuery(RegistryEntity.class);
Root<RegistryEntity> root = criteria.from(RegistryEntity.class);
List<Predicate> predList = new ArrayList<Predicate>();
predList.add(builder.equal(root.get("service"), service));
predList.add(builder.equal(root.get("user"), user));
predList.add(builder.equal(root.get("identity"), identity));
for (RegistryStatus s : status)
predList.add(builder.notEqual(root.get("registryStatus"), s));
......@@ -287,6 +306,27 @@ public class JpaRegistryDao extends JpaBaseDao<RegistryEntity, Long> implements
return em.createQuery(criteria).getResultList();
}
@Override
public List<RegistryEntity> findByIdentityAndStatus(IdentityEntity identity, RegistryStatus... status) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<RegistryEntity> criteria = builder.createQuery(RegistryEntity.class);
Root<RegistryEntity> root = criteria.from(RegistryEntity.class);
List<Predicate> predList = new ArrayList<Predicate>();
for (RegistryStatus s : status)
predList.add(builder.equal(root.get("registryStatus"), s));
criteria.where(builder.and(
builder.equal(root.get(RegistryEntity_.identity), identity),
builder.or(predList.toArray(new Predicate[]{}))));
criteria.select(root);
criteria.distinct(true);
criteria.orderBy(builder.asc(root.get("id")));
return em.createQuery(criteria).getResultList();
}
@Override
public List<RegistryEntity> findByUserAndStatus(UserEntity user, RegistryStatus... status) {
CriteriaBuilder builder = em.getCriteriaBuilder();
......@@ -307,9 +347,9 @@ public class JpaRegistryDao extends JpaBaseDao<RegistryEntity, Long> implements
return em.createQuery(criteria).getResultList();
}
@Override
public List<RegistryEntity> findByUserAndNotStatusAndNotHidden(UserEntity user, RegistryStatus... status) {
public List<RegistryEntity> findByIdentityAndNotStatusAndNotHidden(IdentityEntity identity, RegistryStatus... status) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<RegistryEntity> criteria = builder.createQuery(RegistryEntity.class);
Root<RegistryEntity> root = criteria.from(RegistryEntity.class);
......@@ -321,7 +361,7 @@ public class JpaRegistryDao extends JpaBaseDao<RegistryEntity, Long> implements
builder.isNull(serviceJoin.get(ServiceEntity_.hidden)),
builder.equal(serviceJoin.get(ServiceEntity_.hidden), false)));
predList.add(builder.equal(root.get(RegistryEntity_.user), user));
predList.add(builder.equal(root.get(RegistryEntity_.identity), identity));
for (RegistryStatus s : status)
predList.add(builder.notEqual(root.get("registryStatus"), s));
......@@ -346,6 +386,20 @@ public class JpaRegistryDao extends JpaBaseDao<RegistryEntity, Long> implements
return em.createQuery(criteria).getResultList();
}
@Override
public List<RegistryEntity> findByIdentity(IdentityEntity identity) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<RegistryEntity> criteria = builder.createQuery(RegistryEntity.class);
Root<RegistryEntity> root = criteria.from(RegistryEntity.class);
criteria.where(
builder.equal(root.get("identity"), identity));
criteria.select(root);
criteria.distinct(true);
criteria.orderBy(builder.asc(root.get("id")));
return em.createQuery(criteria).getResultList();
}
@SuppressWarnings("unchecked")
@Override
public List<RegistryEntity> findMissingIdentity() {
......
......@@ -15,6 +15,7 @@ import java.util.List;
import java.util.Set;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.NoResultException;
import javax.persistence.criteria.CriteriaBuilder;
......@@ -23,16 +24,21 @@ import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.Root;
import edu.kit.scc.webreg.dao.RoleDao;
import edu.kit.scc.webreg.dao.identity.IdentityDao;
import edu.kit.scc.webreg.entity.GroupEntity;
import edu.kit.scc.webreg.entity.RoleEntity;
import edu.kit.scc.webreg.entity.RoleGroupEntity;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.UserRoleEntity;
import edu.kit.scc.webreg.entity.identity.IdentityEntity;
@Named
@ApplicationScoped
public class JpaRoleDao extends JpaBaseDao<RoleEntity, Long> implements RoleDao {
@Inject
private IdentityDao identityDao;
@Override
public UserRoleEntity createNewUserRole() {
return new UserRoleEntity();
......@@ -116,6 +122,26 @@ public class JpaRoleDao extends JpaBaseDao<RoleEntity, Long> implements RoleDao
.setParameter("userId", userId).getResultList();
}
@SuppressWarnings("unchecked")
@Override
public List<RoleEntity> findByIdentityId(Long identityId) {
List<RoleEntity> roleList = em.createQuery("select r.role from IdentityRoleEntity r where r.identity.id = :identityId")
.setParameter("identityId", identityId).getResultList();
IdentityEntity identity = identityDao.findById(identityId);
roleList.addAll(em.createQuery("select r.role from UserRoleEntity r where r.user.id in :userIdList")
.setParameter("userIdList", identity.getUsers()).getResultList());
return roleList;
}
@SuppressWarnings("unchecked")
@Override
public List<RoleEntity> findByUserIdList(List<Long> userIdList) {
return em.createQuery("select r.role from UserRoleEntity r where r.user.id in :userIdList")
.setParameter("userIdList", userIdList).getResultList();
}
@SuppressWarnings("unchecked")
@Override
public List<UserEntity> findUsersForRole(RoleEntity role) {
......
......@@ -25,36 +25,43 @@ public class JpaSshPubKeyDao extends JpaBaseDao<SshPubKeyEntity, Long> implement
@Override
@SuppressWarnings("unchecked")
public List<SshPubKeyEntity> findByUser(Long userId) {
return em.createQuery("select e from SshPubKeyEntity e where e.user.id = :userId")
.setParameter("userId", userId).getResultList();
public List<SshPubKeyEntity> findByIdentity(Long identityId) {
return em.createQuery("select e from SshPubKeyEntity e where e.identity.id = :identityId")
.setParameter("identityId", identityId).getResultList();
}
@SuppressWarnings("unchecked")
@Override
public List<SshPubKeyEntity> findMissingIdentity() {
return em.createQuery("select r from SshPubKeyEntity r where r.identity is null")
.getResultList();
}
@Override
@SuppressWarnings("unchecked")
public List<SshPubKeyEntity> findByUserAndStatus(Long userId, SshPubKeyStatus keyStatus) {
return em.createQuery("select e from SshPubKeyEntity e where e.user.id = :userId and e.keyStatus = :keyStatus")
.setParameter("userId", userId)
public List<SshPubKeyEntity> findByIdentityAndStatus(Long identityId, SshPubKeyStatus keyStatus) {
return em.createQuery("select e from SshPubKeyEntity e where e.identity.id = :userId and e.keyStatus = :keyStatus")
.setParameter("identityId", identityId)
.setParameter("keyStatus", keyStatus)
.getResultList();
}
@Override
@SuppressWarnings("unchecked")
public List<SshPubKeyEntity> findByUserAndStatusWithRegs(Long userId, SshPubKeyStatus keyStatus) {
public List<SshPubKeyEntity> findByIdentityAndStatusWithRegs(Long identityId, SshPubKeyStatus keyStatus) {
return em.createQuery("select distinct e from SshPubKeyEntity e "
+ "left join fetch e.sshPubKeyRegistries "
+ "where e.user.id = :userId and e.keyStatus = :keyStatus")
.setParameter("userId", userId)
+ "where e.identity.id = :identityId and e.keyStatus = :keyStatus")
.setParameter("identityId", identityId)
.setParameter("keyStatus", keyStatus)
.getResultList();
}
@Override
@SuppressWarnings("unchecked")
public List<SshPubKeyEntity> findByUserAndKey(Long userId, String encodedKey) {
return em.createQuery("select e from SshPubKeyEntity e where e.user.id = :userId and e.encodedKey = :encodedKey")
.setParameter("userId", userId)
public List<SshPubKeyEntity> findByIdentityAndKey(Long identityId, String encodedKey) {
return em.createQuery("select e from SshPubKeyEntity e where e.identity.id = :userId and e.encodedKey = :encodedKey")
.setParameter("identityId", identityId)
.setParameter("encodedKey", encodedKey)
.getResultList();
}
......
......@@ -27,6 +27,7 @@ import edu.kit.scc.webreg.entity.GroupEntity;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.UserEntity_;
import edu.kit.scc.webreg.entity.UserStatus;
import edu.kit.scc.webreg.entity.identity.IdentityEntity;
@Named
@ApplicationScoped
......@@ -41,6 +42,13 @@ public class JpaUserDao extends JpaBaseDao<UserEntity, Long> implements UserDao,
.setParameter("primaryGroup", group).getResultList();
}
@Override
@SuppressWarnings({"unchecked"})
public List<UserEntity> findByIdentity(IdentityEntity identity) {
return em.createQuery("select e from UserEntity e where e.identity = :identity")
.setParameter("identity", identity).getResultList();
}
@Override
@SuppressWarnings({"unchecked"})
public List<UserEntity> findOrderByUpdatedWithLimit(Date date, Integer limit) {
......
......@@ -7,6 +7,8 @@ import javax.persistence.metamodel.SetAttribute;
import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.StaticMetamodel;
import edu.kit.scc.webreg.entity.identity.IdentityEntity;
@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
@StaticMetamodel(RegistryEntity.class)
public abstract class RegistryEntity_ extends edu.kit.scc.webreg.entity.AbstractBaseEntity_ {
......@@ -21,6 +23,7 @@ public abstract class RegistryEntity_ extends edu.kit.scc.webreg.entity.Abstract
public static volatile SingularAttribute<RegistryEntity, RegistryStatus> registryStatus;
public static volatile SingularAttribute<RegistryEntity, Date> lastAccessCheck;
public static volatile SingularAttribute<RegistryEntity, UserEntity> user;
public static volatile SingularAttribute<RegistryEntity, IdentityEntity> identity;
public static volatile SingularAttribute<RegistryEntity, String> registerBean;
public static volatile SingularAttribute<RegistryEntity, Date> agreedTime;
......
......@@ -14,6 +14,8 @@ import javax.persistence.Table;
import org.hibernate.annotations.Type;
import edu.kit.scc.webreg.entity.identity.IdentityEntity;
@Entity(name = "SshPubKeyEntity")
@Table(name = "ssh_pub_key")
public class SshPubKeyEntity extends AbstractBaseEntity {
......@@ -23,6 +25,9 @@ public class SshPubKeyEntity extends AbstractBaseEntity {
@ManyToOne(targetEntity = UserEntity.class)
private UserEntity user;
@ManyToOne(targetEntity = IdentityEntity.class)
private IdentityEntity identity;
@OneToMany(targetEntity = SshPubKeyRegistryEntity.class, mappedBy = "sshPubKey")
private Set<SshPubKeyRegistryEntity> sshPubKeyRegistries;
......@@ -109,4 +114,12 @@ public class SshPubKeyEntity extends AbstractBaseEntity {
public void setSshPubKeyRegistries(Set<SshPubKeyRegistryEntity> sshPubKeyRegistries) {
this.sshPubKeyRegistries = sshPubKeyRegistries;
}
public IdentityEntity getIdentity() {
return identity;
}
public void setIdentity(IdentityEntity identity) {
this.identity = identity;
}
}
......@@ -9,6 +9,8 @@ import javax.persistence.Enumerated;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import edu.kit.scc.webreg.entity.identity.IdentityEntity;
@Entity(name = "SshPubKeyRegistryEntity")
@Table(name = "ssh_pub_key_registry")
public class SshPubKeyRegistryEntity extends AbstractBaseEntity {
......@@ -42,8 +44,8 @@ public class SshPubKeyRegistryEntity extends AbstractBaseEntity {
@Column(name = "approved_at")
private Date approvedAt;
@ManyToOne(targetEntity = UserEntity.class)
private UserEntity approvedBy;
@ManyToOne(targetEntity = IdentityEntity.class)
private IdentityEntity approver;
@Column(name = "expires_at")
private Date expiresAt;
......@@ -128,12 +130,11 @@ public class SshPubKeyRegistryEntity extends AbstractBaseEntity {
this.approvedAt = approvedAt;
}
public UserEntity getApprovedBy() {
return approvedBy;
public IdentityEntity getApprover() {
return approver;
}
public void setApprovedBy(UserEntity approvedBy) {
this.approvedBy = approvedBy;
public void setApprover(IdentityEntity approver) {
this.approver = approver;
}
}
......@@ -9,6 +9,8 @@ import javax.persistence.Enumerated;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import edu.kit.scc.webreg.entity.identity.IdentityEntity;
@Entity(name = "UserLoginInfoEntity")
@Table(name = "user_login_info")
public class UserLoginInfoEntity extends AbstractBaseEntity {
......@@ -18,6 +20,9 @@ public class UserLoginInfoEntity extends AbstractBaseEntity {
@ManyToOne(targetEntity = UserEntity.class)
private UserEntity user;
@ManyToOne(targetEntity = IdentityEntity.class)
private IdentityEntity identity;
@ManyToOne(targetEntity = RegistryEntity.class)
private RegistryEntity registry;
......@@ -80,4 +85,12 @@ public class UserLoginInfoEntity extends AbstractBaseEntity {
public void setRegistry(RegistryEntity registry) {
this.registry = registry;
}
public IdentityEntity getIdentity() {
return identity;
}
public void setIdentity(IdentityEntity identity) {
this.identity = identity;
}
}
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.entity.audit;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import edu.kit.scc.webreg.entity.identity.IdentityEntity;
@Entity(name = "AuditIdentityEntity")
public class AuditIdentityEntity extends AuditEntryEntity {
private static final long serialVersionUID = 1L;
@ManyToOne(targetEntity = IdentityEntity.class)
private IdentityEntity identity;
public IdentityEntity getIdentity() {
return identity;
}
public void setIdentity(IdentityEntity identity) {
this.identity = identity;
}
}
......@@ -29,6 +29,9 @@ public class IdentityEntity extends AbstractBaseEntity {
@Column(name="user_pref_name", length=128, unique = true)
private String userPreferredName;
@Column(name="twofa_user_id", length=512, unique = true)
private String twoFaUserId;
@OneToMany(targetEntity=UserEntity.class, mappedBy = "identity")
private Set<UserEntity> users;
......@@ -47,4 +50,12 @@ public class IdentityEntity extends AbstractBaseEntity {
public void setUsers(Set<UserEntity> users) {
this.users = users;
}
public String getTwoFaUserId() {
return twoFaUserId;
}
public void setTwoFaUserId(String twoFaUserId) {
this.twoFaUserId = twoFaUserId;
}
}
/*******************************************************************************
* Copyright (c) 2014 Michael Simon.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Michael Simon - initial
******************************************************************************/
package edu.kit.scc.webreg.entity.identity;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;