Commit de5c9528 authored by ls1947's avatar ls1947
Browse files

add UserLoginInfo

parent da61e4c5
......@@ -24,7 +24,7 @@ public class UserLoginInfoEntity extends AbstractBaseEntity {
@Column(name = "login_date")
private Date loginDate;
@Column(name = "from", length = 256)
@Column(name = "login_from", length = 256)
private String from;
@Enumerated(EnumType.STRING)
......
......@@ -19,6 +19,9 @@ import edu.kit.scc.webreg.entity.GroupEntity;
import edu.kit.scc.webreg.entity.SamlUserEntity;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.UserLoginInfoEntity;
import edu.kit.scc.webreg.entity.UserLoginInfoStatus;
import edu.kit.scc.webreg.entity.UserLoginMethod;
import edu.kit.scc.webreg.entity.UserStatus;
import edu.kit.scc.webreg.exc.UserUpdateException;
......@@ -55,4 +58,6 @@ public interface UserService extends BaseService<UserEntity, Long> {
UserEntity findByUidNumber(Long uidNumber);
UserLoginInfoEntity addLoginInfo(Long userId, UserLoginMethod method, UserLoginInfoStatus status, String from);
}
......@@ -24,12 +24,16 @@ import edu.kit.scc.webreg.dao.BaseDao;
import edu.kit.scc.webreg.dao.RegistryDao;
import edu.kit.scc.webreg.dao.SamlUserDao;
import edu.kit.scc.webreg.dao.UserDao;
import edu.kit.scc.webreg.dao.UserLoginInfoDao;
import edu.kit.scc.webreg.entity.GroupEntity;
import edu.kit.scc.webreg.entity.RegistryEntity;
import edu.kit.scc.webreg.entity.RegistryStatus;
import edu.kit.scc.webreg.entity.SamlUserEntity;
import edu.kit.scc.webreg.entity.ServiceEntity;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.UserLoginInfoEntity;
import edu.kit.scc.webreg.entity.UserLoginInfoStatus;
import edu.kit.scc.webreg.entity.UserLoginMethod;
import edu.kit.scc.webreg.entity.UserStatus;
import edu.kit.scc.webreg.exc.UserUpdateException;
import edu.kit.scc.webreg.service.UserService;
......@@ -54,6 +58,21 @@ public class UserServiceImpl extends BaseServiceImpl<UserEntity, Long> implement
@Inject
private RegistryDao registryDao;
@Inject
private UserLoginInfoDao userLoginInfoDao;
@Override
public UserLoginInfoEntity addLoginInfo(Long userId, UserLoginMethod method, UserLoginInfoStatus status, String from) {
UserLoginInfoEntity loginInfo = userLoginInfoDao.createNew();
loginInfo.setUser(dao.findById(userId));
loginInfo.setLoginDate(new Date());
loginInfo.setLoginMethod(method);
loginInfo.setLoginStatus(status);
loginInfo.setFrom(from);
loginInfo = userLoginInfoDao.persist(loginInfo);
return loginInfo;
}
@Override
public List<UserEntity> findOrderByUpdatedWithLimit(Date date, Integer limit) {
return dao.findOrderByUpdatedWithLimit(date, limit);
......@@ -126,7 +145,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserEntity, Long> implement
protected BaseDao<UserEntity, Long> getDao() {
return dao;
}
@Override
public void checkOnHoldRegistries(UserEntity user) {
if (user.getUserStatus().equals(UserStatus.ON_HOLD)) {
......
......@@ -20,10 +20,13 @@ import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import edu.kit.scc.webreg.entity.UserEntity;
import edu.kit.scc.webreg.entity.UserLoginInfoStatus;
import edu.kit.scc.webreg.entity.UserLoginMethod;
import edu.kit.scc.webreg.service.UserService;
import edu.kit.scc.webreg.service.twofa.TwoFaException;
import edu.kit.scc.webreg.service.twofa.TwoFaService;
......@@ -72,16 +75,22 @@ public class TwoFaLoginBean implements Serializable {
public void check() {
try {
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
LinotpSimpleResponse response = twoFaService.checkToken(sessionManager.getUserId(), tokenInput);
if (response.getResult() != null && response.getResult().isStatus() && response.getResult().isValue()) {
// Succesfull check
sessionManager.setTwoFaElevation(new Date());
userService.addLoginInfo(user.getId(), UserLoginMethod.TWOFA, UserLoginInfoStatus.SUCCESS,
request.getRemoteAddr());
ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
context.redirect(sessionManager.getOriginalRequestPath());
sessionManager.setOriginalRequestPath(null);
}
else {
userService.addLoginInfo(user.getId(), UserLoginMethod.TWOFA, UserLoginInfoStatus.FAILED,
request.getRemoteAddr());
messageGenerator.addResolvedWarningMessage("twofa_login_failed", "twofa_login_failed_detail", true);
tokenInput = "";
}
......
Supports Markdown
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