Commit 4ae46689 authored by michael.simon's avatar michael.simon
Browse files

Merge remote-tracking branch 'origin/branch-2.7' into 68-add-projects

Conflicts:
	bwreg-jpa/src/main/java/edu/kit/scc/webreg/dao/ServiceDao.java
	bwreg-jpa/src/main/java/edu/kit/scc/webreg/entity/ServiceEntity.java
	bwreg-service/src/main/java/edu/kit/scc/webreg/service/ServiceService.java
	bwreg-service/src/main/java/edu/kit/scc/webreg/session/SessionManager.java
	bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/admin/service/EditServiceBean.java
	bwreg-webapp/src/main/java/edu/kit/scc/webreg/bean/admin/service/ServiceAdminUserDetailBean.java
parents d80d7321 b4816448
......@@ -21,5 +21,6 @@ public interface ExternalUserDao extends BaseDao<ExternalUserEntity, Long> {
List<ExternalUserEntity> findByAdmin(ExternalUserAdminRoleEntity adminRole);
List<ExternalUserEntity> findByAttribute(String key, String value, ExternalUserAdminRoleEntity adminRole);
List<ExternalUserEntity> findByGeneric(String key, String value, ExternalUserAdminRoleEntity adminRole);
List<ExternalUserEntity> findAll(ExternalUserAdminRoleEntity adminRole);
}
......@@ -71,4 +71,7 @@ public interface RegistryDao extends BaseDao<RegistryEntity, Long> {
List<RegistryEntity> findByServiceAndStatusOrderByRecon(ServiceEntity service, RegistryStatus status, int limit);
List<RegistryEntity> findAllByRegValueAndStatus(ServiceEntity service, String key, String value,
RegistryStatus status);
}
......@@ -17,4 +17,6 @@ public interface SamlAssertionDao extends BaseDao<SamlAssertionEntity, Long> {
void deleteAssertionForUser(UserEntity user);
SamlAssertionEntity findByUserId(Long userId);
}
......@@ -44,4 +44,6 @@ public interface ServiceDao extends BaseDao<ServiceEntity, Long> {
List<ServiceEntity> findByProjectAdminRole(RoleEntity role);
List<ServiceEntity> findBySshPubKeyApproverRole(RoleEntity role);
}
/*******************************************************************************
* 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.dao;
import edu.kit.scc.webreg.entity.SshPubKeyApproverRoleEntity;
public interface SshPubKeyApproverRoleDao extends BaseDao<SshPubKeyApproverRoleEntity, Long> {
}
/*******************************************************************************
* 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.dao;
import java.util.List;
import edu.kit.scc.webreg.entity.SshPubKeyEntity;
import edu.kit.scc.webreg.entity.SshPubKeyStatus;
public interface SshPubKeyDao extends BaseDao<SshPubKeyEntity, Long> {
List<SshPubKeyEntity> findByUser(Long userId);
List<SshPubKeyEntity> findByUserAndStatus(Long userId, SshPubKeyStatus keyStatus);
List<SshPubKeyEntity> findByUserAndKey(Long userId, String encodedKey);
List<SshPubKeyEntity> findByUserAndStatusWithRegs(Long userId, SshPubKeyStatus keyStatus);
List<SshPubKeyEntity> findByKey(String encodedKey);
}
/*******************************************************************************
* 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.dao;
import java.util.List;
import edu.kit.scc.webreg.entity.SshPubKeyRegistryEntity;
public interface SshPubKeyRegistryDao extends BaseDao<SshPubKeyRegistryEntity, Long> {
List<SshPubKeyRegistryEntity> findByUserAndService(Long userId, Long serviceId);
List<SshPubKeyRegistryEntity> findByRegistry(Long registryId);
List<SshPubKeyRegistryEntity> findForApproval(Long serviceId);
List<SshPubKeyRegistryEntity> findByRegistryForInteractiveLogin(Long registryId);
List<SshPubKeyRegistryEntity> findByRegistryForCommandLogin(Long registryId);
List<SshPubKeyRegistryEntity> findByRegistryForLogin(Long registryId);
}
......@@ -29,4 +29,5 @@ public interface UserDao extends BaseDao<UserEntity, Long> {
List<UserEntity> findGenericStoreKeyWithLimit(String key, Integer limit);
List<UserEntity> findOrderByFailedUpdateWithLimit(Date date, Integer limit);
List<UserEntity> findByStatus(UserStatus status);
UserEntity findByUidNumber(Long uidNumber);
}
/*******************************************************************************
* 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.dao;
import java.util.List;
import edu.kit.scc.webreg.entity.UserLoginInfoEntity;
import edu.kit.scc.webreg.entity.UserLoginMethod;
public interface UserLoginInfoDao extends BaseDao<UserLoginInfoEntity, Long> {
List<UserLoginInfoEntity> findByUser(Long userId);
List<UserLoginInfoEntity> findByRegistry(Long registryId);
UserLoginInfoEntity findLastByRegistryAndMethod(Long registryId, UserLoginMethod method);
}
......@@ -23,5 +23,7 @@ public interface ASUserAttrDao extends BaseDao<ASUserAttrEntity, Long> {
AttributeSourceEntity attributeSource);
List<ASUserAttrEntity> findForUser(UserEntity user);
List<ASUserAttrEntity> findForUserWithValues(UserEntity user);
}
......@@ -80,6 +80,20 @@ public class JpaExternalUserDao extends JpaBaseDao<ExternalUserEntity, Long> imp
return em.createQuery(criteria).getResultList();
}
@Override
public List<ExternalUserEntity> findAll(ExternalUserAdminRoleEntity adminRole) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<ExternalUserEntity> criteria = builder.createQuery(ExternalUserEntity.class);
Root<ExternalUserEntity> root = criteria.from(ExternalUserEntity.class);
criteria.select(root);
criteria.where(builder.and(
builder.equal(root.get(ExternalUserEntity_.admin), adminRole)
));
return em.createQuery(criteria).getResultList();
}
@SuppressWarnings("unchecked")
@Override
public List<ExternalUserEntity> findByAdmin(ExternalUserAdminRoleEntity adminRole) {
......
......@@ -40,6 +40,19 @@ import edu.kit.scc.webreg.entity.UserEntity;
@ApplicationScoped
public class JpaRegistryDao extends JpaBaseDao<RegistryEntity, Long> implements RegistryDao {
@SuppressWarnings("unchecked")
@Override
public List<RegistryEntity> findAllByRegValueAndStatus(ServiceEntity service, String key, String value, RegistryStatus status) {
return em.createQuery("select r from RegistryEntity r join r.registryValues rv "
+ "where (key(rv) = :key and rv = :val) "
+ "and r.service = :service and r.registryStatus = :status")
.setParameter("key", key)
.setParameter("val", value)
.setParameter("service", service)
.setParameter("status", status)
.getResultList();
}
@Override
public RegistryEntity findByIdWithAgreements(Long id) {
CriteriaBuilder builder = em.getCriteriaBuilder();
......
......@@ -14,6 +14,7 @@ import java.io.Serializable;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
import javax.persistence.NoResultException;
import javax.persistence.Query;
import edu.kit.scc.webreg.dao.SamlAssertionDao;
......@@ -26,15 +27,28 @@ public class JpaSamlAssertionDao extends JpaBaseDao<SamlAssertionEntity, Long> i
private static final long serialVersionUID = 1L;
@Override
public Class<SamlAssertionEntity> getEntityClass() {
return SamlAssertionEntity.class;
}
@Override
public void deleteAssertionForUser(UserEntity user) {
Query query = em.createQuery("delete from SamlAssertionEntity where user=:user");
query.setParameter("user", user);
query.executeUpdate();
}
@Override
public SamlAssertionEntity findByUserId(Long userId) {
try {
return (SamlAssertionEntity) em.createQuery("select e from SamlAssertionEntity e " +
"where e.user.id = :userId")
.setParameter("userId", userId)
.getSingleResult();
}
catch (NoResultException e) {
return null;
}
}
@Override
public Class<SamlAssertionEntity> getEntityClass() {
return SamlAssertionEntity.class;
}
}
......@@ -81,6 +81,13 @@ public class JpaServiceDao extends JpaBaseDao<ServiceEntity, Long> implements Se
.setParameter("role", role).getResultList();
}
@Override
@SuppressWarnings({"unchecked"})
public List<ServiceEntity> findBySshPubKeyApproverRole(RoleEntity role) {
return em.createQuery("select e from ServiceEntity e where e.sshPubKeyApproverRole = :role")
.setParameter("role", role).getResultList();
}
@Override
@SuppressWarnings({"unchecked"})
public List<ServiceEntity> findByGroupAdminRole(RoleEntity role) {
......
/*******************************************************************************
* 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.dao.jpa;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
import edu.kit.scc.webreg.dao.SshPubKeyApproverRoleDao;
import edu.kit.scc.webreg.entity.SshPubKeyApproverRoleEntity;
@Named
@ApplicationScoped
public class JpaSshPubKeyApproverRoleDao extends JpaBaseDao<SshPubKeyApproverRoleEntity, Long> implements SshPubKeyApproverRoleDao {
@Override
public Class<SshPubKeyApproverRoleEntity> getEntityClass() {
return SshPubKeyApproverRoleEntity.class;
}
}
/*******************************************************************************
* 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.dao.jpa;
import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
import edu.kit.scc.webreg.dao.SshPubKeyDao;
import edu.kit.scc.webreg.entity.SshPubKeyEntity;
import edu.kit.scc.webreg.entity.SshPubKeyStatus;
@Named
@ApplicationScoped
public class JpaSshPubKeyDao extends JpaBaseDao<SshPubKeyEntity, Long> implements SshPubKeyDao {
@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();
}
@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)
.setParameter("keyStatus", keyStatus)
.getResultList();
}
@Override
@SuppressWarnings("unchecked")
public List<SshPubKeyEntity> findByUserAndStatusWithRegs(Long userId, 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)
.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)
.setParameter("encodedKey", encodedKey)
.getResultList();
}
@Override
@SuppressWarnings("unchecked")
public List<SshPubKeyEntity> findByKey(String encodedKey) {
return em.createQuery("select e from SshPubKeyEntity e where e.encodedKey = :encodedKey")
.setParameter("encodedKey", encodedKey)
.getResultList();
}
@Override
public Class<SshPubKeyEntity> getEntityClass() {
return SshPubKeyEntity.class;
}
}
/*******************************************************************************
* 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.dao.jpa;
import java.util.Date;
import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
import edu.kit.scc.webreg.dao.SshPubKeyRegistryDao;
import edu.kit.scc.webreg.entity.SshPubKeyRegistryEntity;
import edu.kit.scc.webreg.entity.SshPubKeyRegistryStatus;
import edu.kit.scc.webreg.entity.SshPubKeyStatus;
import edu.kit.scc.webreg.entity.SshPubKeyUsageType;
@Named
@ApplicationScoped
public class JpaSshPubKeyRegistryDao extends JpaBaseDao<SshPubKeyRegistryEntity, Long> implements SshPubKeyRegistryDao {
@Override
@SuppressWarnings("unchecked")
public List<SshPubKeyRegistryEntity> findByUserAndService(Long userId, Long serviceId) {
return em.createQuery("select e from SshPubKeyRegistryEntity e where e.registry.user.id = :userId and e.registry.service.id = :serviceId")
.setParameter("userId", userId)
.setParameter("serviceId", serviceId)
.getResultList();
}
@Override
@SuppressWarnings("unchecked")
public List<SshPubKeyRegistryEntity> findByRegistry(Long registryId) {
return em.createQuery("select e from SshPubKeyRegistryEntity e where e.registry.id = :registryId")
.setParameter("registryId", registryId)
.getResultList();
}
@Override
@SuppressWarnings("unchecked")
public List<SshPubKeyRegistryEntity> findByRegistryForInteractiveLogin(Long registryId) {
return em.createQuery("select e from SshPubKeyRegistryEntity e "
+ "where e.registry.id = :registryId and e.keyStatus =: keyStatus and "
+ "e.usageType = :usageType and e.sshPubKey.keyStatus =: keyStatus2 and "
+ "(e.sshPubKey.expiresAt > :dateNow or e.sshPubKey.expiresAt is null) and "
+ "(e.expiresAt > :dateNow or e.expiresAt is null)")
.setParameter("registryId", registryId)
.setParameter("keyStatus", SshPubKeyRegistryStatus.ACTIVE)
.setParameter("usageType", SshPubKeyUsageType.INTERACTIVE)
.setParameter("keyStatus2", SshPubKeyStatus.ACTIVE)
.setParameter("dateNow", new Date())
.getResultList();
}
@Override
@SuppressWarnings("unchecked")
public List<SshPubKeyRegistryEntity> findByRegistryForCommandLogin(Long registryId) {
return em.createQuery("select e from SshPubKeyRegistryEntity e "
+ "where e.registry.id = :registryId and e.keyStatus =: keyStatus and "
+ "e.usageType = :usageType and e.sshPubKey.keyStatus =: keyStatus2 and "
+ "(e.sshPubKey.expiresAt > :dateNow or e.sshPubKey.expiresAt is null) and "
+ "(e.expiresAt > :dateNow or e.expiresAt is null)")
.setParameter("registryId", registryId)
.setParameter("keyStatus", SshPubKeyRegistryStatus.ACTIVE)
.setParameter("usageType", SshPubKeyUsageType.COMMAND)
.setParameter("keyStatus2", SshPubKeyStatus.ACTIVE)
.setParameter("dateNow", new Date())
.getResultList();
}
@Override
@SuppressWarnings("unchecked")
public List<SshPubKeyRegistryEntity> findByRegistryForLogin(Long registryId) {
return em.createQuery("select e from SshPubKeyRegistryEntity e "
+ "where e.registry.id = :registryId and e.keyStatus =: keyStatus and "
+ "e.sshPubKey.keyStatus =: keyStatus2 and "
+ "(e.sshPubKey.expiresAt > :dateNow or e.sshPubKey.expiresAt is null) and "
+ "(e.expiresAt > :dateNow or e.expiresAt is null)")
.setParameter("registryId", registryId)
.setParameter("keyStatus", SshPubKeyRegistryStatus.ACTIVE)
.setParameter("keyStatus2", SshPubKeyStatus.ACTIVE)
.setParameter("dateNow", new Date())
.getResultList();
}
@Override
@SuppressWarnings("unchecked")
public List<SshPubKeyRegistryEntity> findForApproval(Long serviceId) {
return em.createQuery("select e from SshPubKeyRegistryEntity e where e.registry.service.id = :serviceId "
+ "and e.keyStatus = :keyStatus")
.setParameter("serviceId", serviceId)
.setParameter("keyStatus", SshPubKeyRegistryStatus.PENDING)
.getResultList();
}
@Override
public Class<SshPubKeyRegistryEntity> getEntityClass() {
return SshPubKeyRegistryEntity.class;
}
}
......@@ -25,6 +25,7 @@ import javax.persistence.criteria.Root;
import edu.kit.scc.webreg.dao.UserDao;
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;
@Named
......@@ -43,15 +44,19 @@ public class JpaUserDao extends JpaBaseDao<UserEntity, Long> implements UserDao,
@Override
@SuppressWarnings({"unchecked"})
public List<UserEntity> findOrderByUpdatedWithLimit(Date date, Integer limit) {
return em.createQuery("select e from UserEntity e where lastUpdate < :date and lastFailedUpdate is null order by lastUpdate asc")
.setParameter("date", date).setMaxResults(limit).getResultList();
return em.createQuery("select e from UserEntity e where e.userStatus != :status and e.lastUpdate < :date and e.lastFailedUpdate is null order by e.lastUpdate asc")
.setParameter("date", date)
.setParameter("status", UserStatus.DEREGISTERED)
.setMaxResults(limit).getResultList();
}
@Override
@SuppressWarnings({"unchecked"})
public List<UserEntity> findOrderByFailedUpdateWithLimit(Date date, Integer limit) {
return em.createQuery("select e from UserEntity e where lastFailedUpdate < :date order by lastFailedUpdate asc")
.setParameter("date", date).setMaxResults(limit).getResultList();
return em.createQuery("select e from UserEntity e where e.userStatus != :status and e.lastFailedUpdate < :date order by e.lastFailedUpdate asc")
.setParameter("date", date)
.setParameter("status", UserStatus.DEREGISTERED)
.setMaxResults(limit).getResultList();
}
@Override
......@@ -79,7 +84,23 @@ public class JpaUserDao extends JpaBaseDao<UserEntity, Long> implements UserDao,
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<UserEntity> criteria = builder.createQuery(UserEntity.class);
Root<UserEntity> user = criteria.from(UserEntity.class);
criteria.where(builder.equal(user.get("eppn"), eppn));
criteria.where(builder.equal(user.get(UserEntity_.eppn), eppn));
criteria.select(user);
try {
return em.createQuery(criteria).getSingleResult();
}
catch (NoResultException e) {
return null;
}
}
@Override
public UserEntity findByUidNumber(Long uidNumber) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<UserEntity> criteria = builder.createQuery(UserEntity.class);
Root<UserEntity> user = criteria.from(UserEntity.class);
criteria.where(builder.equal(user.get(UserEntity_.uidNumber), uidNumber));
criteria.select(user);
try {
......
/*******************************************************************************
* 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.dao.jpa;
import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
import edu.kit.scc.webreg.dao.UserLoginInfoDao;
import edu.kit.scc.webreg.entity.UserLoginInfoEntity;
import edu.kit.scc.webreg.entity.UserLoginMethod;
@Named
@ApplicationScoped
public class JpaUserLoginInfoDao extends JpaBaseDao<UserLoginInfoEntity, Long> implements UserLoginInfoDao {
@Override
@SuppressWarnings("unchecked")
public List<UserLoginInfoEntity> findByUser(Long userId) {
return em.createQuery("select e from UserLoginInfoEntity e where e.user.id = :userId")
.setParameter("userId", userId).getResultList();
}
@Override
@SuppressWarnings("unchecked")
public List<UserLoginInfoEntity> findByRegistry(Long registryId) {
return em.createQuery("select e from UserLoginInfoEntity e where e.registry.id = :registryId")
.setParameter("registryId", registryId).getResultList();
}
@Override
@SuppressWarnings("unchecked")
public UserLoginInfoEntity findLastByRegistryAndMethod(Long registryId, UserLoginMethod method) {
List<UserLoginInfoEntity> list = em.createQuery(
"select e from UserLoginInfoEntity e where e.registry.id = :registryId "
+ "and e.loginMethod = :loginMethod order by e.loginDate desc")
.setParameter("registryId", registryId)
.setParameter("loginMethod", method)