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