public boolean logout() { PieUser user = userService.getUser(); user.setPassword(null); user.setIsLoggedIn(false); try { File unencryptedFile = new File( String.format( unsafeFile, user.getPieShareConfiguration().getPwdFile().getCanonicalPath())); unencryptedFile.delete(); File ivF = new File(user.getPieShareConfiguration().getPwdFile().getParent(), ivFile); if (ivF.exists()) { ivF.delete(); } this.clusterManagementService.disconnect(user.getCloudName()); } catch (IOException e) { PieLogger.error( this.getClass(), String.format("Error in Logout. Message: %s", e.getMessage())); return false; } catch (ClusterServiceException e) { PieLogger.error( this.getClass(), String.format("Error in Logout. Message: %s", e.getMessage())); return false; } PieLogger.info(this.getClass(), "Logout Successful!"); return true; }
public void resetPassword() { logout(); PieUser user = userService.getUser(); user.getPieShareConfiguration().getPwdFile().delete(); databaseService.removePieUser(user); user.setHasPasswordFile(false); PieLogger.info(this.getClass(), "Reset Password Successful!"); }
public boolean createUser(PlainTextPassword pp) { EncryptedPassword pwd1 = passwordEncryptionService.encryptPassword(pp); pp = null; try { PieLogger.trace(this.getClass(), "Creating user {}!", userService.getUser().getUserName()); createNewPwdFile(pwd1, userService.getUser().getPieShareConfiguration().getPwdFile()); userService.getUser().setHasPasswordFile(true); // This is only for Android if (userService.getUser().getUserName() != null) { databaseService.persistPieUser(userService.getUser()); } } catch (Exception e) { PieLogger.error( this.getClass(), String.format("Error creating password file. Message: %s", e.getMessage())); return false; } return true; }
public boolean Login(PlainTextPassword pp, String userName) { EncryptedPassword pwd1 = null; PieUser user = userService.getUser(); if (user == null || user.getPieShareConfiguration() == null) { return false; } File pwdFile = user.getPieShareConfiguration().getPwdFile(); if (pp != null) { pwd1 = passwordEncryptionService.encryptPassword(pp); pp = null; } else { try { File unencryptedFile = new File( String.format( unsafeFile, user.getPieShareConfiguration().getPwdFile().getCanonicalPath())); if (!unencryptedFile.exists()) { return false; } pwd1 = passwordEncryptionService.getEncryptedPasswordFromExistingSecretKey( FileUtils.readFileToByteArray(unencryptedFile)); File ivF = new File(user.getPieShareConfiguration().getPwdFile().getParent(), ivFile); if (ivF.exists()) { pwd1.setIv(FileUtils.readFileToByteArray(ivF)); } } catch (IOException e) { PieLogger.error( this.getClass(), String.format("error during auto login! Message: %s", e.getMessage())); return false; } } pwd1.setUseIv(useIv); if (pwdFile.exists()) { try { if (!Arrays.equals( encodeService.decrypt(pwd1, FileUtils.readFileToByteArray(pwdFile)), pwd1.getPassword())) { return false; // throw new WrongPasswordException("The given password was wrong."); } File unencryptedFile = new File( String.format( unsafeFile, user.getPieShareConfiguration().getPwdFile().getCanonicalPath())); FileUtils.writeByteArrayToFile(unencryptedFile, pwd1.getPassword()); if (pwd1.getIv() != null) { FileUtils.writeByteArrayToFile( new File( userService.getUser().getPieShareConfiguration().getPwdFile().getParent(), ivFile), pwd1.getIv()); } } catch (Exception ex) { PieLogger.info( this.getClass(), String.format( "Wrong password, not possible to encrypt file! Messgae %s", ex.getMessage())); return false; } } else { PieLogger.info(this.getClass(), "Tried to login but no passwordFile was avaliable!"); return false; } if (userService.getUser().getUserName() == null && userName != null) { userService.getUser().setUserName(userName); } databaseService.mergePieUser(userService.getUser()); user.setPassword(pwd1); user.setHasPasswordFile(true); user.setIsLoggedIn(true); SymmetricEncryptedChannel channel = this.symmetricEncryptedChannelProvider.get(); channel.setChannelId(user.getUserName()); channel.setEncPwd(user.getPassword()); try { this.clusterManagementService.registerChannel(user.getCloudName(), channel); } catch (ClusterManagmentServiceException e) { PieLogger.error( this.getClass(), String.format("Error in Register Channel. Message: %s", e.getMessage())); } PieLogger.info(this.getClass(), "Login Successful"); this.historyService.syncLocalFilders(); // todo-mr3: now we have to send a list with everything // todo-after-ase: ultimatively instead of making an initial sync we have to perform a list // request when ever // the cluster state changes try { // todo: change this maybe in future to different aproach // should probably be coupled with network chang detection! // this is needed to recognize local changes on this node IFileListMessage fileList = this.messageFactoryService.getFileListMessage(); fileList.getAddress().setClusterName(userService.getUser().getCloudName()); fileList.getAddress().setChannelId(userService.getUser().getUserName()); fileList.setFileList(this.historyService.getPieFiles()); fileList.setFolderList(this.historyService.getPieFolders()); this.clusterManagementService.sendMessage(fileList); // send file list request message to cluster FileListRequestMessage msg = this.messageFactoryService.getFileListRequestMessage(); msg.getAddress().setClusterName(userService.getUser().getCloudName()); msg.getAddress().setChannelId(userService.getUser().getUserName()); this.clusterManagementService.sendMessage(msg); } catch (ClusterManagmentServiceException ex) { PieLogger.error(this.getClass(), "Connect failed!", ex); } return true; }