Ignore:
Timestamp:
07/24/19 11:23:45 (5 years ago)
Author:
bln4
Message:

Renamed Frame.getItems() to Frame.getSortedItems() to better represent its functionality.

-> org.apollo.ApolloGestureActions
-> org.apollo.ApolloSystem
-> org.expeditee.actions.Actions
-> org.expeditee.actions.Debug
-> org.expeditee.actions.ExploratorySearchActions
-> org.expeditee.actions.JfxBrowserActions
-> org.expeditee.actions.Misc
-> org.expeditee.actions.Navigation
-> org.expeditee.actions.ScriptBase
-> org.expeditee.actions.Simple
-> org.expeditee.agents.ComputeTree
-> org.expeditee.agents.CopyTree
-> org.expeditee.agents.DisplayComet
-> org.expeditee.agents.DisplayTree
-> org.expeditee.agents.DisplayTreeLeaves
-> org.expeditee.agents.GraphFramesetLinks
-> org.expeditee.agents.TreeProcessor
-> org.expeditee.gio.gesture.StandardGestureActions
-> org.expeditee.gui.DisplayController
-> org.expeditee.gui.FrameCreator
-> org.expeditee.gui.FrameIO
-> org.expeditee.io.DefaultTreeWriter
-> org.expeditee.io.JavaWriter
-> org.expeditee.io.PDF2Writer
-> org.expeditee.io.TXTWriter
-> org.expeditee.io.WebParser
-> org.expeditee.io.flowlayout.XGroupItem
-> org.expeditee.items.Dot
-> org.expeditee.items.Item
-> org.expeditee.items.ItemUtils
-> org.expeditee.network.FrameShare
-> org.expeditee.stats.TreeStats


Created ItemsList class to wrap ArrayList<Item>. Frames now use this new class to store its body list (used for display) as well as its primaryBody and surrogateBody.

-> org.expeditee.agents.Format
-> org.expeditee.agents.HFormat
-> org.expeditee.gio.gesture.StandardGestureActions
-> org.expeditee.gui.Frame
-> org.expeditee.gui.FrameUtils


Refactorted Frame.setResort(bool) to Frame.invalidateSorted() to better function how it is intended to with a more accurate name.

-> org.expeditee.agents.Sort


When writing out .exp files and getting attributes to respond to LEFT + RIGHT click, boolean items are by default true. This has always been the case. An ammendment to this is that defaults can now be established.
Also added 'EnterClick' functionality. If cursored over a item with this property and you press enter, it acts as if you have clicked on it instead.

-> org.expeditee.assets.resources-public.framesets.authentication.1.exp to 6.exp
-> org.expeditee.gio.gesture.StandardGestureActions
-> org.expeditee.gio.input.KBMInputEvent
-> org.expeditee.gio.javafx.JavaFXConversions
-> org.expeditee.gio.swing.SwingConversions
-> org.expeditee.gui.AttributeUtils
-> org.expeditee.io.Conversion
-> org.expeditee.io.DefaultFrameWriter
-> org.expeditee.items.Item


Fixed a bug caused by calling Math.abs on Integer.MIN_VALUE returning unexpected result. Due to zero being a thing, you cannot represent Math.abs(Integer.MIN_VALUE) in a Integer object. The solution is to use Integer.MIN_VALUE + 1 instead of Integer.MIN_VALUE.

-> org.expeditee.core.bounds.CombinationBounds
-> org.expeditee.io.flowlayout.DimensionExtent


Recoded the contains function in EllipticalBounds so that intersection tests containing circles work correctly.

-> org.expeditee.core.bounds.EllipticalBounds


Added toString() to PolygonBounds to allow for useful printing during debugging.

-> org.expeditee.core.bounds.PolygonBounds

Implemented Surrogate Mode!

-> org.expeditee.encryption.io.EncryptedExpReader
-> org.expeditee.encryption.io.EncryptedExpWriter
-> org.expeditee.encryption.items.surrogates.EncryptionDetail
-> org.expeditee.encryption.items.surrogates.Label
-> org.expeditee.gui.FrameUtils
-> org.expeditee.gui.ItemsList
-> org.expeditee.items.Item
-> org.expeditee.items.Text


???? Use Integer.MAX_VALUE cast to a float instead of Float.MAX_VALUE. This fixed some bug which I cannot remember.

-> org.expeditee.gio.TextLayoutManager
-> org.expeditee.gio.swing.SwingTextLayoutManager


Improved solution for dealing with the F10 key taking focus away from Expeditee due to it being a assessibility key.

-> org.expeditee.gio.swing.SwingInputManager


Renamed variable visibleItems in FrameGraphics.paintFrame to itemsToPaintCanditates to better represent functional intent.

-> org.expeditee.gui.FrameGraphics


Improved checking for if personal resources exist before recreating them

-> org.expeditee.gui.FrameIO


Repeated messages to message bay now have a visual feedback instead of just a beep. This visual feedback is in the form of a count of the amount of times it has repeated.

-> org.expeditee.gui.MessageBay


Updated comment on the Vector class to explain what vectors are.

-> org.expeditee.gui.Vector


Added constants to represent all of the property keys in DefaultFrameReader and DefaultFrameWriter.

-> org.expeditee.io.DefaultFrameReader
-> org.expeditee.io.DefaultFrameWriter


Updated the KeyList setting to be more heirarcial with how users will store their Secrets.

-> org.expeditee.settings.identity.secrets.KeyList

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/encryption/items/surrogates/Label.java

    r1413 r1415  
    22
    33import java.util.ArrayList;
     4import java.util.Arrays;
    45import java.util.Base64;
    5 import java.util.Collection;
    66import java.util.List;
    7 import java.util.Set;
     7import java.util.function.Predicate;
    88import java.util.stream.Collectors;
    9 
    10 import org.expeditee.auth.AuthenticatorBrowser;
    11 import org.expeditee.gui.DisplayController;
    12 import org.expeditee.gui.Frame;
    13 import org.expeditee.gui.FrameIO;
    14 import org.expeditee.gui.MessageBay;
     9import java.util.stream.Stream;
     10
     11import org.expeditee.gui.ItemsList;
    1512import org.expeditee.items.Item;
    1613import org.expeditee.items.Text;
    17 import org.expeditee.settings.UserSettings;
     14import org.expeditee.settings.identity.secrets.KeyList;
    1815
    1916public class Label {
    2017       
    21         private static List<LabelResult> labelCache = new ArrayList<LabelResult>();
    22         private static List<String> forbiddenLabels = new ArrayList<String>();
    23        
    24         public static LabelResult resolveKey(String label) {
    25                
    26                 if (forbiddenLabels.contains(label)) {
     18        private static int surrogateStep = -1;
     19
     20        public static LabelResult getLabel(String label) {
     21                Text[] userLabels = KeyList.UserLabels.get();
     22                Text labelText = null;
     23                for (Text userLabel : userLabels) {
     24                        if (userLabel.getText().equals(label)) {
     25                                labelText = userLabel;
     26                                break;
     27                        }
     28                }
     29
     30                if (labelText == null) {
     31                        return unableToFindLabelResult(label);
     32                } else {
     33                        List<String> data = labelText.getData();
     34                        if (data == null || data.isEmpty()) {
     35                                return unableToFindLabelResult(label);
     36                        }
     37                        String dataEntry = data.get(0);
     38                       
     39                        if (dataEntry.contains("{")) {
     40                                return partialKeyResult(label, dataEntry);
     41                        } else {
     42                                return fullKeyResult(label, dataEntry);
     43                        }
     44                }
     45        }
     46       
     47        public static void progressSurrogateMode() {
     48                surrogateStep += 1;
     49        }
     50
     51        public static void resetSurrogateMode() {
     52                surrogateStep = -1;
     53        }
     54
     55        public static List<String> getAccessibleLabelsNames(ItemsList itemsList) {
     56                Text[] userLabels = KeyList.UserLabels.get();
     57                Stream<String> accessibleUserWideLabels = Arrays.asList(userLabels).stream().map(label -> label.getText());
     58               
     59                Predicate<Item> isLabelWithoutEncryptionLabel = item -> item.getEncryptionLabel() == null || item.getEncryptionLabel().isEmpty();
     60                itemsList.removeIf(isLabelWithoutEncryptionLabel);
     61                Stream<String> accessibleFrameLocalLabels = itemsList.underlying().stream().map(item -> item.getEncryptionLabel()).distinct();
     62               
     63                List<String> accessibleLabelsUnion = accessibleUserWideLabels.collect(Collectors.toList());
     64                accessibleLabelsUnion.retainAll(accessibleFrameLocalLabels.collect(Collectors.toList()));
     65               
     66                if (surrogateStep > -1 && surrogateStep < accessibleLabelsUnion.size()) {
     67                        String surrogateModeFilter = accessibleLabelsUnion.get(surrogateStep);
     68                        List<String> single = new ArrayList<String>();
     69                        single.add(surrogateModeFilter);
     70                        return single;
     71                } else {
     72                        resetSurrogateMode();
     73                }
     74               
     75                return accessibleLabelsUnion;
     76        }
     77
     78        private static LabelResult partialKeyResult(String label, String dataEntry) {
     79                dataEntry = dataEntry.substring(dataEntry.indexOf('}') + 1).trim();
     80                LabelResult res = LabelResult.SuccessResolveLabelToPartialKey;
     81                res.name = label;
     82                return res;
     83        }
     84
     85        private static LabelResult unableToFindLabelResult(String label) {
     86                LabelResult res = LabelResult.ErrorUnableToFindLabel;
     87                res.name = label;
     88                return res;
     89        }
     90       
     91        private static LabelResult fullKeyResult(String label, String dataEntry) {
     92                try {
     93                        LabelResult res = LabelResult.SuccessResolveLabelToKey;
     94                        res.key = Base64.getDecoder().decode(dataEntry);
     95                        res.name = label;
     96                        return res;
     97                } catch (IllegalArgumentException e) {
    2798                        return LabelResult.ErrorUnableToFindLabel;
    2899                }
    29                
    30                 LabelResult fromCache = getFromCache(label);
    31                 if (fromCache != null) {
    32                         return fromCache;
    33                 }
    34 
    35                
    36                 String credentialsFrameName = UserSettings.ProfileName.get() +
    37                                 AuthenticatorBrowser.CREDENTIALS_FRAME;
    38                 Frame credentialsFrame = FrameIO.LoadFrame(credentialsFrameName);
    39                 Collection<Text> textItems = credentialsFrame.getTextItems();
    40                 textItems.removeIf(t -> !t.getText().equals("Secrets"));
    41                 textItems.removeIf(t -> !t.hasLink());
    42                 if (textItems.isEmpty()) {
    43                         return LabelResult.ErrorUnableToFindSecretsFrame;
    44                 }
    45                 Text linkToSecretsFrame = textItems.iterator().next();
    46                 if (!linkToSecretsFrame.hasLink()) {
    47                         return LabelResult.ErrorUnableToFindSecretsFrame;
    48                 }
    49                 Frame secretsFrame = FrameIO.LoadFrame(linkToSecretsFrame.getParent().getFramesetName() + linkToSecretsFrame.getLink());
    50                 Collection<Text> labels = secretsFrame.getTextItems();
    51                 labels.removeIf(lbl -> !lbl.getText().equals(label));
    52                 labels.removeIf(lbl -> lbl.getData() == null || lbl.getData().size() == 0);
    53                 if (labels.isEmpty()) {
    54                         return LabelResult.ErrorUnableToFindLabel;
    55                 }
    56                 Text labelItem = labels.iterator().next();
    57                 String data = labelItem.getData().get(0);
    58                 if (data.contains("{")) {
    59                         data = data.substring(data.indexOf('}') + 1).trim();
    60                         LabelResult res = LabelResult.SuccessResolveLabelToPartialKey;
    61                         res.key = Base64.getDecoder().decode(data);
    62                         return res;
    63                 } else {
    64                         try {
    65                                 LabelResult res = LabelResult.SuccessResolveLabelToKey;
    66                                 res.key = Base64.getDecoder().decode(data);
    67                                 res.name = label;
    68                                 labelCache.add(res);
    69                                 return res;
    70                         } catch (IllegalArgumentException e) {
    71                                 return LabelResult.ErrorUnableToFindLabel;
    72                         }
    73                 }
    74         }
    75        
    76         public static void progressSurrogateMode() {
    77                 Collection<Item> allItems = DisplayController.getCurrentFrame().getAllItems();
    78                 allItems.removeIf(item -> item.getEncryptionLabel() == null);
    79                 MessageBay.displayMessage("Encryption labels found on items on current frame: ");
    80                 Set<String> allLabels = allItems.stream().map(i -> i.getEncryptionLabel()).collect(Collectors.toSet());
    81                 StringBuilder sb = new StringBuilder();
    82                 for (String label: allLabels) {
    83                         sb.append(label + ",");
    84                 }
    85                 MessageBay.displayMessage(sb.deleteCharAt(sb.length() - 1).toString());
    86         }
    87        
    88         public static void resetSurrogateMode() {
    89                 // TODO Auto-generated method stub
    90                
    91         }
    92        
    93         private static LabelResult getFromCache(String label) {
    94                 List<LabelResult> cacheCanditates = labelCache.stream().filter(labelResult -> labelResult.name.equals(label)).collect(Collectors.toList());
    95                 if (!cacheCanditates.isEmpty()) {
    96                         return cacheCanditates.get(0);
    97                 } else {
    98                         return null;
    99                 }
    100         }
    101        
    102 //      private static List<List<String>> permutation(List<String> strings, List<List<String>> acc) {
    103 //              for (int i = 0; i < strings.size(); i++) {
    104 //                     
     100        }
     101
     102        //private static Map<LabelResult, LabelAccess> labelCache = new LinkedHashMap<LabelResult, LabelAccess>();
     103        //private static int surrogateStep = -1;
     104        //private static final Predicate<? super LabelResult> isAccessible = a -> labelCache.get(a).allowed;
     105       
     106//      public static LabelResult resolveKey(String label) {
     107//              Stream<LabelResult> stream = labelCache.keySet().stream();
     108//              stream = stream.filter(res -> res.name.equals(label));
     109//              if (stream.count() == 0) {
     110//                      return resolveKeyWorker(label);
     111//              } else {
     112//                      LabelResult labelResult = stream.collect(Collectors.toList()).get(0);
     113//                      LabelAccess accessible = labelCache.get(labelResult);
     114//                      if (accessible.allowed) { return labelResult; }
     115//                      else { return LabelResult.ErrorForbiddenLabel; }
     116//              }
     117//      }       
     118//      private static LabelResult resolveKeyWorker(String label) {
     119//              Frame secretsFrame = getSecretsFrame();
     120//              if (secretsFrame == null) {
     121//                      return LabelResult.ErrorUnableToFindSecretsFrame;
     122//              }
     123//             
     124//              String data = getDataFromLabel(secretsFrame, label);
     125//              if (data == null) {
     126//                      return LabelResult.ErrorUnableToFindLabel;
     127//              }
     128//             
     129//              if (data.contains("{")) {
     130//                      data = data.substring(data.indexOf('}') + 1).trim();
     131//                      LabelResult res = LabelResult.SuccessResolveLabelToPartialKey;
     132//                      res.key = Base64.getDecoder().decode(data);
     133//                      return res;
     134//              } else {
     135//                      try {
     136//                              LabelResult res = LabelResult.SuccessResolveLabelToKey;
     137//                              res.key = Base64.getDecoder().decode(data);
     138//                              res.name = label;
     139//                              labelCache.put(res, new LabelAccess(true));
     140//                              return res;
     141//                      } catch (IllegalArgumentException e) {
     142//                              return LabelResult.ErrorUnableToFindLabel;
     143//                      }
    105144//              }
    106145//      }
     146//     
     147//      private static String getDataFromLabel(Frame frame, String label) {
     148//              Collection<Text> labels = frame.getTextItems();
     149//              labels.removeIf(lbl -> !lbl.getText().equals(label));
     150//              labels.removeIf(lbl -> lbl.getData() == null || lbl.getData().size() == 0);
     151//              if (labels.isEmpty()) { return null; }
     152//              Text labelItem = labels.iterator().next();
     153//              List<String> data = labelItem.getData();
     154//              if (data.isEmpty()) { return null; }
     155//              return data.get(0);
     156//      }
     157//     
     158//      private static Frame getSecretsFrame() {
     159//              String credentialsFrameName = UserSettings.ProfileName.get() +
     160//                              AuthenticatorBrowser.CREDENTIALS_FRAME;
     161//              Frame credentialsFrame = FrameIO.LoadFrame(credentialsFrameName);
     162//              Collection<Text> textItems = credentialsFrame.getTextItems();
     163//              textItems.removeIf(t -> !t.getText().equals("Secrets"));
     164//              textItems.removeIf(t -> !t.hasLink());
     165//              if (textItems.isEmpty()) {
     166//                      return null;
     167//              }
     168//              Text linkToSecretsFrame = textItems.iterator().next();
     169//              if (!linkToSecretsFrame.hasLink()) {
     170//                      return null;
     171//              }
     172//              Frame secretsFrame = FrameIO.LoadFrame(linkToSecretsFrame.getParent().getFramesetName() + linkToSecretsFrame.getLink());
     173//              return secretsFrame;
     174//      }
     175//     
     176//      private static class LabelAccess {
     177//              public final boolean allowedDefault;
     178//              public boolean allowed;
     179//             
     180//              public LabelAccess(boolean value) {
     181//                      allowedDefault = value;
     182//                      allowed = allowedDefault;
     183//              }
     184//      }
    107185       
    108186        public enum LabelResult {
     
    110188                SuccessResolveLabelToPartialKey,
    111189                ErrorUnableToFindSecretsFrame,
    112                 ErrorUnableToFindLabel;
     190                ErrorUnableToFindLabel,
     191                ErrorForbiddenLabel;
    113192               
    114193                public byte[] key;
     
    125204                                return "Unable to find your Secrets Frame.";
    126205                        case ErrorUnableToFindLabel:
    127                                 return "Unable to resolve label to encrypt/decrypt frame.  Label: ";
     206                                return "Unable to resolve label to encrypt/decrypt frame.  Label: " + name;
     207                        case ErrorForbiddenLabel:
     208                                return "Whilst you have the key for label " + name + " ; you are not allowed to use it.";
    128209                        }
    129210                       
Note: See TracChangeset for help on using the changeset viewer.