Skip to content

Commit

Permalink
created new enum class PasswordType that represents the type of passw…
Browse files Browse the repository at this point in the history
…ord the user will use
  • Loading branch information
astrapi69 committed Nov 18, 2023
1 parent 0c88c06 commit 7128b41
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import javax.crypto.Cipher;

import io.github.astrapi69.mystic.crypt.panel.signin.PasswordType;
import lombok.NonNull;
import lombok.extern.java.Log;

Expand Down Expand Up @@ -61,19 +62,17 @@ public class ApplicationXmlFileReader

public static ApplicationModelBean read(@NonNull MasterPwFileModelBean modelObject)
{
if (modelObject.isWithMasterPw() && modelObject.isWithKeyFile())
PasswordType passwordType = PasswordType.resolve(modelObject.isWithMasterPw(),
modelObject.isWithKeyFile());
if (passwordType.equals(PasswordType.PASSWORD_WITH_PRIVATE_KEY))
{
return readApplicationFileWithPasswordAndPrivateKey(modelObject);
}
else if (modelObject.isWithMasterPw())
else if (passwordType.equals(PasswordType.PASSWORD))
{
return readApplicationFileWithPassword(modelObject);
}
else if (modelObject.isWithKeyFile())
{
return readApplicationFileWithPrivateKey(modelObject);
}
return null;
return readApplicationFileWithPrivateKey(modelObject);
}

public static ApplicationModelBean readApplicationFileWithPasswordAndPrivateKey(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,23 +133,24 @@ public void onSingleClick(MouseEvent mouseEvent)
List<MysticCryptEntryModelBean> data = getTblTreeEntryTable().getGenericTableModel()
.getData();
List<MysticCryptEntryModelBean> allSelectedRowData = getTblTreeEntryTable()
.getAllSelectedRowData();
.getAllSelectedRowData();

boolean noRowSelected = allSelectedRowData.isEmpty();
boolean emptyTable = data.isEmpty();
if(emptyTable || noRowSelected) {
if (emptyTable || noRowSelected)
{
if (mouseEvent.getButton() == MouseEvent.BUTTON1)
{
SecretKeyTreeWithContentPanel.this.onTableSingleLeftClick(mouseEvent);
SecretKeyTreeWithContentPanel.this.onTableSingleLeftClick(mouseEvent);
}
if (mouseEvent.getButton() == MouseEvent.BUTTON2)
{

SecretKeyTreeWithContentPanel.this.onTableSingleMiddleClick(mouseEvent);
SecretKeyTreeWithContentPanel.this.onTableSingleMiddleClick(mouseEvent);
}
if (mouseEvent.getButton() == MouseEvent.BUTTON3)
{
SecretKeyTreeWithContentPanel.this.onTableSingleRightClick(mouseEvent);
SecretKeyTreeWithContentPanel.this.onTableSingleRightClick(mouseEvent);
}
}
}
Expand Down Expand Up @@ -626,13 +627,13 @@ protected void onTableSingleRightClick(MouseEvent mouseEvent)
popup.addSeparator();

JMenuItem selectAll = JMenuItemFactory.newJMenuItem("select all",
actionEvent -> this.onSelectAllTableEntries());
actionEvent -> this.onSelectAllTableEntries());
selectAll.setEnabled(0 < getTblTreeEntryTable().getRowCount());

popup.add(selectAll);

JMenuItem clearSelection = JMenuItemFactory.newJMenuItem("clear selection",
actionEvent -> this.onDeselectAllTableEntries());
actionEvent -> this.onDeselectAllTableEntries());
clearSelection.setEnabled(rowsSelected);

popup.add(clearSelection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package io.github.astrapi69.mystic.crypt.panel.signin;

import java.io.Serial;
import java.io.Serializable;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -54,11 +55,13 @@
public class MasterPwFileModelBean implements Serializable
{
/** The Constant serialVersionUID. */
@Serial
private static final long serialVersionUID = 1L;

/** The encrypted data file for the application. */
/** The application file info for create the application file object */
FileInfo applicationFileInfo;

/** The currently selected key file path */
String selectedApplicationFilePath;

Expand Down Expand Up @@ -116,12 +119,11 @@ public MemoizedSigninModelBean toMemoizedSigninModelBean(MasterPwFileModelBean m
keyFilePathSet.addAll(modelObject.getKeyFilePaths());
Set<String> applicationFilePathSet = SetFactory.newHashSet(this.applicationFilePaths);
applicationFilePathSet.addAll(modelObject.getApplicationFilePaths());
MemoizedSigninModelBean memoizedSignin = MemoizedSigninModelBean.builder()
return MemoizedSigninModelBean.builder()
.keyFilePaths(ListFactory.newArrayList(keyFilePathSet))
.selectedKeyFilePath(this.selectedKeyFilePath)
.applicationFilePaths(ListFactory.newArrayList(applicationFilePathSet))
.selectedApplicationFilePath(this.selectedApplicationFilePath)
.withMasterPw(this.withMasterPw).withKeyFile(this.withKeyFile).build();
return memoizedSignin;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* The MIT License
*
* Copyright (C) 2015 Asterios Raptis
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package io.github.astrapi69.mystic.crypt.panel.signin;

/**
* The enum class {@link PasswordType} provides the password types for signing in an application
*/
public enum PasswordType
{

/**
* The <code>PasswordType#PASSWORD</code> type indicates that only a password is needed
*/
PASSWORD,

/**
* The <code>PasswordType#PRIVATE_KEY</code> type indicates that only a private key is needed
*/
PRIVATE_KEY,

/**
* The <code>PasswordType#PASSWORD_WITH_PRIVATE_KEY</code> type indicates that a password and a
* key is needed
*/
PASSWORD_WITH_PRIVATE_KEY,

/**
* The <code>PasswordType#UNKNOWN</code> type indicates that the password type is unknown
*/
UNKNOWN;

/**
* Resolves the {@link PasswordType} object from the given flags
*
* @param withPassword
* the flag if it is with a password
* @param withPrivateKey
* the flag if it is with a private key file
* @return the resolved {@link PasswordType} object
*/
public static PasswordType resolve(boolean withPassword, boolean withPrivateKey)
{
if (withPassword && withPrivateKey)
{
return PASSWORD_WITH_PRIVATE_KEY;
}
else if (withPassword)
{
return PASSWORD;
}
return PRIVATE_KEY;
}

}

0 comments on commit 7128b41

Please sign in to comment.