/** * Test if two factor is enabled in the system and by the user * * @param user * @return */ public boolean isTwoFactorEnabled(Users user) { String twoFactorAuth = settings.getTwoFactorAuth(); String twoFactorExclude = settings.getTwoFactorExclude(); String twoFactorMode = (twoFactorAuth != null ? twoFactorAuth : ""); String excludes = (twoFactorExclude != null ? twoFactorExclude : null); String[] groups = (excludes != null && !excludes.isEmpty() ? excludes.split(";") : new String[]{}); for (String group : groups) { if (isUserInRole(user, group)) { return false; //will allow anyone if one of the users groups are in the exclude list } } if (twoFactorMode.equals(Settings.TwoFactorMode.MANDATORY.getName())) { return true; } else if (twoFactorMode.equals(Settings.TwoFactorMode.OPTIONAL.getName()) && user.getTwoFactor()) { return true; } return false; }
/** * Returns the QR code for the user if two factor is enabled. * * @param user * @param password * @param req * @return null if two factor is disabled. * @throws AppException */ public byte[] getQRCode(Users user, String password, HttpServletRequest req) throws AppException { byte[] qr_code = null; if (user == null) { throw new AppException(Response.Status.NOT_FOUND.getStatusCode(), ResponseMessages.USER_WAS_NOT_FOUND); } if (!authController.validatePassword(user, password, req)) { throw new AppException(Response.Status.BAD_REQUEST.getStatusCode(), ResponseMessages.PASSWORD_INCORRECT); } if (user.getTwoFactor()) { try { qr_code = QRCodeGenerator.getQRCodeBytes(user.getEmail(), Settings.ISSUER, user.getSecret()); } catch (IOException | WriterException ex) { LOGGER.log(Level.SEVERE, null, ex); } } return qr_code; }
if (user.getTwoFactor()) { user.setTwoFactor(false); userFacade.update(user);
public UserDTO(Users user) { this.username = user.getUsername(); this.email = user.getEmail(); this.firstName = user.getFname(); this.lastName = user.getLname(); this.telephoneNum = user.getMobile(); if (user.getOrganization() != null) { this.orgName = user.getOrganization().getOrgName(); this.dep = user.getOrganization().getDepartment(); } if (user.getAddress() != null) { this.street = user.getAddress().getAddress2(); this.city = user.getAddress().getCity(); this.postCode = user.getAddress().getPostalcode(); this.country = user.getAddress().getCountry(); } this.maxNumProjects = user.getMaxNumProjects(); this.numCreatedProjects = user.getNumCreatedProjects(); this.twoFactor = user.getTwoFactor(); this.toursState = user.getToursState(); this.userAccountType = user.getMode().toString(); this.numActiveProjects = user.getNumActiveProjects(); numRemainingProjects = maxNumProjects-numCreatedProjects; }