Commit e2f2487c authored by michael.simon's avatar michael.simon
Browse files

change findByEppn to non unique operation

parent 92d951fd
...@@ -20,7 +20,7 @@ import edu.kit.scc.webreg.entity.identity.IdentityEntity; ...@@ -20,7 +20,7 @@ import edu.kit.scc.webreg.entity.identity.IdentityEntity;
public interface UserDao extends BaseDao<UserEntity, Long> { public interface UserDao extends BaseDao<UserEntity, Long> {
UserEntity findByEppn(String eppn); List<UserEntity> findByEppn(String eppn);
UserEntity findByIdWithAll(Long id); UserEntity findByIdWithAll(Long id);
List<UserEntity> findLegacyUsers(); List<UserEntity> findLegacyUsers();
List<UserEntity> findByPrimaryGroup(GroupEntity group); List<UserEntity> findByPrimaryGroup(GroupEntity group);
......
...@@ -127,19 +127,14 @@ public class JpaUserDao extends JpaBaseDao<UserEntity, Long> implements UserDao, ...@@ -127,19 +127,14 @@ public class JpaUserDao extends JpaBaseDao<UserEntity, Long> implements UserDao,
} }
@Override @Override
public UserEntity findByEppn(String eppn) { public List<UserEntity> findByEppn(String eppn) {
CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<UserEntity> criteria = builder.createQuery(UserEntity.class); CriteriaQuery<UserEntity> criteria = builder.createQuery(UserEntity.class);
Root<UserEntity> user = criteria.from(UserEntity.class); Root<UserEntity> user = criteria.from(UserEntity.class);
criteria.where(builder.equal(user.get(UserEntity_.eppn), eppn)); criteria.where(builder.equal(user.get(UserEntity_.eppn), eppn));
criteria.select(user); criteria.select(user);
try { return em.createQuery(criteria).getResultList();
return em.createQuery(criteria).getSingleResult();
}
catch (NoResultException e) {
return null;
}
} }
@Override @Override
......
...@@ -24,8 +24,8 @@ public class UserGroupCallbackImpl implements UserGroupCallback { ...@@ -24,8 +24,8 @@ public class UserGroupCallbackImpl implements UserGroupCallback {
@Override @Override
public boolean existsUser(String userId) { public boolean existsUser(String userId) {
UserEntity user = userService.findByEppn(userId); List<UserEntity> user = userService.findByEppn(userId);
if (user == null) { if (user.size() == 0) {
return false; return false;
} }
else { else {
...@@ -47,15 +47,18 @@ public class UserGroupCallbackImpl implements UserGroupCallback { ...@@ -47,15 +47,18 @@ public class UserGroupCallbackImpl implements UserGroupCallback {
@Override @Override
public List<String> getGroupsForUser(String userId, List<String> groupIds, public List<String> getGroupsForUser(String userId, List<String> groupIds,
List<String> allExistingGroupIds) { List<String> allExistingGroupIds) {
UserEntity user = userService.findByEppn(userId); List<UserEntity> userList = userService.findByEppn(userId);
if (user == null) { if (userList.size() == 0) {
return null; return null;
} }
List<RoleEntity> roleEntityList = roleService.findByUser(user); List<String> returnList = new ArrayList<String>();
List<String> returnList = new ArrayList<String>(roleEntityList.size());
for (UserEntity user : userList) {
for (RoleEntity role : roleEntityList) { List<RoleEntity> roleEntityList = roleService.findByUser(user);
returnList.add(role.getName());
for (RoleEntity role : roleEntityList) {
returnList.add(role.getName());
}
} }
return returnList; return returnList;
......
...@@ -31,7 +31,7 @@ public interface UserService extends BaseService<UserEntity, Long> { ...@@ -31,7 +31,7 @@ public interface UserService extends BaseService<UserEntity, Long> {
SamlUserEntity findByPersistentWithRoles(String spId, String idpId, SamlUserEntity findByPersistentWithRoles(String spId, String idpId,
String persistentId); String persistentId);
UserEntity findByEppn(String eppn); List<UserEntity> findByEppn(String eppn);
UserEntity findByIdWithAll(Long id); UserEntity findByIdWithAll(Long id);
......
...@@ -129,7 +129,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserEntity, Long> implement ...@@ -129,7 +129,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserEntity, Long> implement
} }
@Override @Override
public UserEntity findByEppn(String eppn) { public List<UserEntity> findByEppn(String eppn) {
return dao.findByEppn(eppn); return dao.findByEppn(eppn);
} }
......
...@@ -107,7 +107,7 @@ public class RegisterOidcUserBean implements Serializable { ...@@ -107,7 +107,7 @@ public class RegisterOidcUserBean implements Serializable {
return; return;
} }
if (service.findByEppn(entity.getEppn()) != null) { if (service.findByEppn(entity.getEppn()) != null && service.findByEppn(entity.getEppn()).size() > 0) {
errorState = true; errorState = true;
messageGenerator.addResolvedErrorMessage("eppn-blocked", "eppn-blocked-detail", true); messageGenerator.addResolvedErrorMessage("eppn-blocked", "eppn-blocked-detail", true);
} }
......
...@@ -94,7 +94,7 @@ public class RegisterUserBean implements Serializable { ...@@ -94,7 +94,7 @@ public class RegisterUserBean implements Serializable {
return; return;
} }
if (service.findByEppn(entity.getEppn()) != null) { if (service.findByEppn(entity.getEppn()) != null && service.findByEppn(entity.getEppn()).size() > 0) {
errorState = true; errorState = true;
messageGenerator.addResolvedErrorMessage("eppn-blocked", "eppn-blocked-detail", true); messageGenerator.addResolvedErrorMessage("eppn-blocked", "eppn-blocked-detail", true);
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
package edu.kit.scc.webreg.bean.admin.as; package edu.kit.scc.webreg.bean.admin.as;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
import javax.inject.Named; import javax.inject.Named;
import javax.faces.view.ViewScoped; import javax.faces.view.ViewScoped;
...@@ -57,15 +58,20 @@ public class ShowAttributeSourceBean implements Serializable { ...@@ -57,15 +58,20 @@ public class ShowAttributeSourceBean implements Serializable {
} }
public void testSource() { public void testSource() {
UserEntity user = userService.findByEppn(testUsername); List<UserEntity> user = userService.findByEppn(testUsername);
if (user == null) { if (user.size() == 0) {
logger.info("User {} not found", testUsername); logger.info("User {} not found", testUsername);
return; return;
} }
if (user.size() > 1) {
logger.info("User {} not unique", testUsername);
return;
}
try { try {
asQueryService.updateUserAttributes(user, entity, "test"); asQueryService.updateUserAttributes(user.get(0), entity, "test");
} catch (UserUpdateException e) { } catch (UserUpdateException e) {
logger.info("Exception!", e); logger.info("Exception!", e);
} }
......
...@@ -117,22 +117,27 @@ public class BulkRegisterBean implements Serializable { ...@@ -117,22 +117,27 @@ public class BulkRegisterBean implements Serializable {
for (RegisterUser registerUser : selectedUsers) { for (RegisterUser registerUser : selectedUsers) {
try { try {
logger.debug("Processing user {} for service {}", registerUser.getEppn(), selectedService.getName()); logger.debug("Processing user {} for service {}", registerUser.getEppn(), selectedService.getName());
UserEntity userEntity = userService.findByEppn(registerUser.getEppn()); List<UserEntity> userEntity = userService.findByEppn(registerUser.getEppn());
if (userEntity == null) { if (userEntity.size() == 0) {
registerUser.setStatus("User unkown"); registerUser.setStatus("User unkown");
continue; continue;
} }
if (userEntity.size() > 1) {
registerUser.setStatus("User not unique");
continue;
}
RegistryEntity registry = registryService.findByServiceAndUserAndStatus( RegistryEntity registry = registryService.findByServiceAndUserAndStatus(
selectedService, userEntity, RegistryStatus.ACTIVE); selectedService, userEntity.get(0), RegistryStatus.ACTIVE);
if (registry != null) { if (registry != null) {
registerUser.setStatus("User already registered"); registerUser.setStatus("User already registered");
continue; continue;
} }
registerUserService.registerUser(userEntity, service, "bulk-register"); registerUserService.registerUser(userEntity.get(0), service, "bulk-register");
registerUser.setStatus("Successfully registered"); registerUser.setStatus("Successfully registered");
} catch (Exception e) { } catch (Exception e) {
......
...@@ -148,7 +148,7 @@ public class Saml2AttributeQueryHandler implements Servlet { ...@@ -148,7 +148,7 @@ public class Saml2AttributeQueryHandler implements Servlet {
String nameIdValue = query.getSubject().getNameID().getValue(); String nameIdValue = query.getSubject().getNameID().getValue();
String nameIdFormat = query.getSubject().getNameID().getFormat(); String nameIdFormat = query.getSubject().getNameID().getFormat();
UserEntity user = userService.findByEppn(nameIdValue); UserEntity user = userService.findById(Long.parseLong(nameIdValue));
if (user != null) { if (user != null) {
Assertion assertion = samlHelper.create(Assertion.class, Assertion.DEFAULT_ELEMENT_NAME); Assertion assertion = samlHelper.create(Assertion.class, Assertion.DEFAULT_ELEMENT_NAME);
assertion.setIssueInstant(new DateTime()); assertion.setIssueInstant(new DateTime());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment