Changeset 1509


Ignore:
Timestamp:
02/05/20 15:20:37 (4 years ago)
Author:
bnemhaus
Message:

ItemEncryptionPermission is now respected.

Location:
trunk/src/org/expeditee
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/gui/AttributeUtils.java

    r1508 r1509  
    210210                        _FrameAttrib.put("HomogeneousEncryptionLabel",          Frame.class.getMethod("getHomogeneousEncryptionLabel"),
    211211                                                                                                                                Frame.class.getMethod("setHomogeneousEncryptionLabel", pString));
    212                         _FrameAttrib.put("EncryptionPermission",                        Frame.class.getMethod("getEncryptionPermission"),
     212                        _FrameAttrib.put("ItemEncryptionPermission",            Frame.class.getMethod("getEncryptionPermission"),
    213213                                                                                                                                Frame.class.getMethod("setEncryptionPermission", pEncPermission));
    214214                        _FrameAttrib.put("HetrogeneousEncryptionLabels",        Frame.class.getMethod("getHetrogeneousFrameOwnerLabels"),
     
    225225                        _FrameAttrib.alias("encframeperm",      "EncryptionFramePermission");
    226226                        _FrameAttrib.alias("homoenclabel",      "HomogeneousEncryptionLabel");
    227                         _FrameAttrib.alias("encperm",           "EncryptionPermission");
     227                        _FrameAttrib.alias("encperm",           "ItemEncryptionPermission");
    228228                       
    229229                        // Generic Items
  • trunk/src/org/expeditee/gui/Frame.java

    r1508 r1509  
    30223022                String homogeneousEncryptionLabel = getHomogeneousEncryptionLabel();
    30233023                if (homogeneousEncryptionLabel == null) { homogeneousEncryptionLabel = getFrameEncryptionLabel(); }
    3024                 if (homogeneousEncryptionLabel == null) { homogeneousEncryptionLabel = EncryptedExpWriter.getLabelNone(); }
    3025                
     3024                if (homogeneousEncryptionLabel == null) { homogeneousEncryptionLabel = EncryptedExpWriter.getLabelNone(); }             
    30263025                List<String> hetrogeneousFrameOwnerLabels = getHetrogeneousFrameOwnerLabels();
    30273026               
     
    31193118       
    31203119        public EncryptionPermissionTriple getEncryptionPermission() {
     3120                if (_itemEncryptionPermission == null) {
     3121                        _itemEncryptionPermission = EncryptionPermissionTriple.convertString("300");
     3122                }
    31213123                return _itemEncryptionPermission;
    31223124        }
  • trunk/src/org/expeditee/io/Conversion.java

    r1506 r1509  
    522522                value = value.trim();
    523523
    524                 if ((method.getParameterTypes()[0].isEnum()) || (name.matches("setPermission")) || (name.matches("setFrameEncryptionPermission"))) {
     524                if ((method.getParameterTypes()[0].isEnum()) || (name.matches("setPermission")) || (name.matches("setFrameEncryptionPermission")) || (name.matches("setEncryptionPermission"))) {
    525525                        Method convertString;
    526526                        Object[] objects = new Object[1];
     
    650650                }
    651651
    652                 if ((method.getReturnType().isEnum()) || (name.equals("getPermission")) || (name.equals("getFrameEncryptionPermission"))) {
     652                if ((method.getReturnType().isEnum()) || (name.equals("getPermission")) || (name.equals("getFrameEncryptionPermission")) || (name.equals("getEncryptionPermission"))) {
    653653                        try {
    654654                                return output.getClass().getMethod("getCode", new Class[] {})
  • trunk/src/org/expeditee/items/Item.java

    r1505 r1509  
    4949import org.expeditee.core.bounds.PolygonBounds;
    5050import org.expeditee.encryption.core.EncryptedImage;
     51import org.expeditee.encryption.io.EncryptedExpWriter;
    5152import org.expeditee.encryption.items.KeyType;
     53import org.expeditee.encryption.items.UserAppliedEncryptionPermission;
    5254import org.expeditee.encryption.items.surrogates.EncryptionDetail;
    5355import org.expeditee.encryption.items.surrogates.EncryptionDetail.Type;
     
    40974099                }
    40984100        }
    4099        
     4101               
    41004102        public void setEncryptionLabel(String label) {
    4101                 this.getSurrogates().clear();
    4102                 this._encryptionLabel = label;
    4103                
     4103                if (label == null) {
     4104                        _encryptionLabel = null;
     4105                        return;
     4106                }
     4107                               
    41044108                if (this.getParent().getFrameEncryptionLabel() == null) {
    41054109                        MessageBay.displayMessage("Items can only be entrypted if the frame they are on is.");
    41064110                        return;
    41074111                }
     4112                               
    41084113                LabelInfo labelResult = Label.getLabel(label);
    41094114                if (!labelResult.is(LabelResult.SuccessResolveLabelToKey)) {
    41104115                        MessageBay.displayMessage(labelResult.toString());
    4111                         this._encryptionLabel = null;
    41124116                        return;
    41134117                }
    41144118               
     4119                String errorMessage = "You do not have sufficient permissions to set the encryption label to " + label;
     4120                UserAppliedEncryptionPermission p = getParent().getEncryptionPermission().getPermission(getParent().getOwner(), getParent().getGroupMembers());
     4121                String homogeneousEncryptionLabel = getParent().getHomogeneousEncryptionLabel();
     4122                if (homogeneousEncryptionLabel == null) { homogeneousEncryptionLabel = getParent().getFrameEncryptionLabel(); }
     4123                if (homogeneousEncryptionLabel == null) { homogeneousEncryptionLabel = EncryptedExpWriter.getLabelNone(); }             
     4124                List<String> hetrogeneousFrameOwnerLabels = getParent().getHetrogeneousFrameOwnerLabels();
     4125               
     4126                switch(p) {
     4127                case none:
     4128                        MessageBay.errorMessage(errorMessage);
     4129                        return;
     4130                case homogeneous:
     4131                        if (!homogeneousEncryptionLabel.equals(label)) {
     4132                                MessageBay.errorMessage(errorMessage);
     4133                                return;
     4134                        }
     4135                        break;
     4136                case hetrogeneous_owner:
     4137                        if (!homogeneousEncryptionLabel.equals(label) && !hetrogeneousFrameOwnerLabels.contains(label)) {
     4138                                MessageBay.errorMessage(errorMessage);
     4139                                return;
     4140                        }
     4141                        break;
     4142                case hetrogeneous: break;
     4143                }
     4144               
     4145                this.getSurrogates().clear();
     4146                this._encryptionLabel = label;
     4147               
    41154148                //Setup surrogate items.
     4149                generateSurrogate(labelResult);
     4150        }
     4151       
     4152        public void setEncryptionLabelOnLoad(String label) {
     4153                this._encryptionLabel = label;
     4154        }
     4155
     4156        /**
     4157         * Replaces the given dot item with a text item displaying the given character.
     4158         *
     4159         * @param dot
     4160         *              The Dot item to replace.
     4161         *
     4162         * @param ch
     4163         *              The character to display as the text for the created Text item.
     4164         *
     4165         * @return
     4166         *              The created Text item.
     4167         */
     4168        public static Text replaceDot(Item dot, char ch) {
     4169                // TODO: Should this make sure 'dot' is actually a Dot and not some other item? cts16
     4170                Text text = Text.createText(ch);
     4171                Item.DuplicateItem(dot, text);
     4172                FrameUtils.setLastEdited(text);
     4173
     4174                // Copy the lines list so it can be modified
     4175                List<Line> lines = new LinkedList<Line>(dot.getLines());
     4176                for (Line line : lines)
     4177                        line.replaceLineEnd(dot, text);
     4178                Frame current = dot.getParentOrCurrentFrame();
     4179                current.removeItem(dot);
     4180                ItemUtils.EnclosedCheck(current.getSortedItems());
     4181                return text;
     4182                // TODO: Should this add the newly-created Text item to the frame? cts16
     4183        }
     4184
     4185        /**
     4186         * Replaces the given text item with a dot
     4187         */
     4188        public static Item replaceText(Item text) {
     4189                Item dot = new Dot(text.getX(), text.getY(), text.getID());
     4190                Item.DuplicateItem(text, dot);
     4191
     4192                List<Line> lines = new LinkedList<Line>();
     4193                lines.addAll(text.getLines());
     4194                if (lines.size() > 0)
     4195                        dot.setColor(lines.get(0).getColor());
     4196                for (Line line : lines) {
     4197                        line.replaceLineEnd(text, dot);
     4198                }
     4199                text.delete();
     4200                Frame current = text.getParentOrCurrentFrame();
     4201                current.addItem(dot);
     4202                DisplayController.setCursor(Item.DEFAULT_CURSOR);
     4203                ItemUtils.EnclosedCheck(current.getSortedItems());
     4204                return dot;
     4205        }
     4206
     4207        public Set<Item> getSurrogates() {
     4208                return surrogateItems;
     4209        }
     4210               
     4211        private void setAsSurrogateFor(Item primary) {
     4212                this.surrogateFor = primary;
     4213        }
     4214
     4215        public void addToSurrogates(Item surrogate) {
     4216                if (this.getEncryptionLabel() == null) {
     4217                        MessageBay.displayMessage("Only Items with encryption labels can have surrogates.");
     4218                        return;
     4219                }
     4220               
     4221                this.getParent().removeItem(surrogate);
     4222                this.surrogateItems.add(surrogate);
     4223                surrogate.setAsSurrogateFor(this);
     4224                this.getParent().addItem(surrogate);
     4225               
     4226                EncryptionDetail reencryptOnSave = new EncryptionDetail(EncryptionDetail.Type.ReencryptOnSave);
     4227                EncryptionDetail unencryptedOnSave = new EncryptionDetail(EncryptionDetail.Type.UnencryptedOnSave);
     4228               
     4229                for (Character tag: DefaultFrameWriter.getItemCharTags().keySet()) {
     4230                        if (tag == 'T') {
     4231                                primaryPropertyEncryption.put(tag + "", reencryptOnSave.clone());
     4232                        } else {
     4233                                primaryPropertyEncryption.put(tag + "", unencryptedOnSave.clone());
     4234                        }
     4235                                       
     4236                        if (tag == 'T' || tag == 'S') {
     4237                                surrogate.surrogatePropertyInheritance.put(tag + "", false);
     4238                        } else {
     4239                                surrogate.surrogatePropertyInheritance.put(tag + "", true);
     4240                        }
     4241                }
     4242               
     4243                for (String tag: DefaultFrameWriter.getItemStrTags().keySet()) {
     4244                        primaryPropertyEncryption.put(tag, unencryptedOnSave.clone());
     4245                        surrogate.surrogatePropertyInheritance.put(tag + "", true);
     4246                }
     4247        }
     4248       
     4249        public boolean isSurrogate() {
     4250                return this.surrogateFor != null;
     4251        }
     4252       
     4253        public Item getPrimary() {
     4254                return this.surrogateFor;
     4255        }
     4256       
     4257        public EncryptionDetail getEncryptionDetailForTag(String tag) {
     4258                EncryptionDetail encryptionDetail = primaryPropertyEncryption.get(tag);
     4259               
     4260                if (encryptionDetail == null) {
     4261                        EncryptionDetail unencryptedOnSave = new EncryptionDetail(EncryptionDetail.Type.UnencryptedOnSave);
     4262                        return unencryptedOnSave;
     4263                } else {
     4264                        return encryptionDetail;
     4265                }
     4266        }
     4267       
     4268        public void setEncryptionDetailForTag(String tag, EncryptionDetail encryptionDetail) {
     4269                primaryPropertyEncryption.put(tag, encryptionDetail);
     4270        }
     4271       
     4272        public boolean isTagInherited(String tag) {
     4273                return surrogatePropertyInheritance.get(tag);
     4274        }
     4275       
     4276        public void setTagNotInherited(String tag) {
     4277                surrogatePropertyInheritance.put(tag, false);
     4278        }
     4279       
     4280        public boolean hasAccessToItemAsPrimary() {
     4281                String label = this.getEncryptionLabel();
     4282                if (this.isSurrogate() || label == null || label.length() == 0) {
     4283                        return true;
     4284                }
     4285               
     4286                return Label.getLabel(label).is(LabelResult.SuccessResolveLabelToKey);
     4287        }
     4288       
     4289
     4290        /**
     4291         * If when setting a property, we find that the primary has a undeciphered value, when we must continue using that undeciphered value
     4292         * when eventually saving.
     4293         * @return
     4294         */
     4295        protected boolean subjectToInheritanceCheckOnSave(String tag) {
     4296                if (tag.equals(DefaultFrameWriter.TYPE_AND_ID_STR)) {
     4297                        return false;
     4298                }
     4299                Item primary = getPrimary();
     4300                if (primary == null) return false;
     4301                EncryptionDetail primaryItemTagEncryptionDetail = primary.primaryPropertyEncryption.get(tag);
     4302                Type primaryItemTagEncryptionDetailType = primaryItemTagEncryptionDetail.getEncryptionDetailType();
     4303                return primaryItemTagEncryptionDetailType != EncryptionDetail.Type.UseUndecipheredValueOnSave;
     4304        }
     4305
     4306        public boolean acceptsKeyboardEnter() {
     4307                return _acceptsKeyboardEnter;
     4308        }
     4309               
     4310        public void setAcceptsEnter(boolean value) {
     4311                if (this.getText() != null && this.getText().equals("Beep")) {
     4312                        System.err.println();
     4313                }
     4314                _acceptsKeyboardEnter = value;
     4315        }
     4316       
     4317        private void generateSurrogate(LabelInfo labelResult) {
    41164318                Item copy = this.copy();
    41174319                if (copy.isAnnotation()) {
     
    41554357                this.addToSurrogates(copy);
    41564358        }
    4157        
    4158         public void setEncryptionLabelOnLoad(String label) {
    4159                 this._encryptionLabel = label;
    4160         }
    4161 
    4162         /**
    4163          * Replaces the given dot item with a text item displaying the given character.
    4164          *
    4165          * @param dot
    4166          *              The Dot item to replace.
    4167          *
    4168          * @param ch
    4169          *              The character to display as the text for the created Text item.
    4170          *
    4171          * @return
    4172          *              The created Text item.
    4173          */
    4174         public static Text replaceDot(Item dot, char ch) {
    4175                 // TODO: Should this make sure 'dot' is actually a Dot and not some other item? cts16
    4176                 Text text = Text.createText(ch);
    4177                 Item.DuplicateItem(dot, text);
    4178                 FrameUtils.setLastEdited(text);
    4179 
    4180                 // Copy the lines list so it can be modified
    4181                 List<Line> lines = new LinkedList<Line>(dot.getLines());
    4182                 for (Line line : lines)
    4183                         line.replaceLineEnd(dot, text);
    4184                 Frame current = dot.getParentOrCurrentFrame();
    4185                 current.removeItem(dot);
    4186                 ItemUtils.EnclosedCheck(current.getSortedItems());
    4187                 return text;
    4188                 // TODO: Should this add the newly-created Text item to the frame? cts16
    4189         }
    4190 
    4191         /**
    4192          * Replaces the given text item with a dot
    4193          */
    4194         public static Item replaceText(Item text) {
    4195                 Item dot = new Dot(text.getX(), text.getY(), text.getID());
    4196                 Item.DuplicateItem(text, dot);
    4197 
    4198                 List<Line> lines = new LinkedList<Line>();
    4199                 lines.addAll(text.getLines());
    4200                 if (lines.size() > 0)
    4201                         dot.setColor(lines.get(0).getColor());
    4202                 for (Line line : lines) {
    4203                         line.replaceLineEnd(text, dot);
    4204                 }
    4205                 text.delete();
    4206                 Frame current = text.getParentOrCurrentFrame();
    4207                 current.addItem(dot);
    4208                 DisplayController.setCursor(Item.DEFAULT_CURSOR);
    4209                 ItemUtils.EnclosedCheck(current.getSortedItems());
    4210                 return dot;
    4211         }
    4212 
    4213         public Set<Item> getSurrogates() {
    4214                 return surrogateItems;
    4215         }
    4216                
    4217         private void setAsSurrogateFor(Item primary) {
    4218                 this.surrogateFor = primary;
    4219         }
    4220 
    4221         public void addToSurrogates(Item surrogate) {
    4222                 if (this.getEncryptionLabel() == null) {
    4223                         MessageBay.displayMessage("Only Items with encryption labels can have surrogates.");
    4224                         return;
    4225                 }
    4226                
    4227                 this.getParent().removeItem(surrogate);
    4228                 this.surrogateItems.add(surrogate);
    4229                 surrogate.setAsSurrogateFor(this);
    4230                 this.getParent().addItem(surrogate);
    4231                
    4232                 EncryptionDetail reencryptOnSave = new EncryptionDetail(EncryptionDetail.Type.ReencryptOnSave);
    4233                 EncryptionDetail unencryptedOnSave = new EncryptionDetail(EncryptionDetail.Type.UnencryptedOnSave);
    4234                
    4235                 for (Character tag: DefaultFrameWriter.getItemCharTags().keySet()) {
    4236                         if (tag == 'T') {
    4237                                 primaryPropertyEncryption.put(tag + "", reencryptOnSave.clone());
    4238                         } else {
    4239                                 primaryPropertyEncryption.put(tag + "", unencryptedOnSave.clone());
    4240                         }
    4241                                        
    4242                         if (tag == 'T' || tag == 'S') {
    4243                                 surrogate.surrogatePropertyInheritance.put(tag + "", false);
    4244                         } else {
    4245                                 surrogate.surrogatePropertyInheritance.put(tag + "", true);
    4246                         }
    4247                 }
    4248                
    4249                 for (String tag: DefaultFrameWriter.getItemStrTags().keySet()) {
    4250                         primaryPropertyEncryption.put(tag, unencryptedOnSave.clone());
    4251                         surrogate.surrogatePropertyInheritance.put(tag + "", true);
    4252                 }
    4253         }
    4254        
    4255         public boolean isSurrogate() {
    4256                 return this.surrogateFor != null;
    4257         }
    4258        
    4259         public Item getPrimary() {
    4260                 return this.surrogateFor;
    4261         }
    4262        
    4263         public EncryptionDetail getEncryptionDetailForTag(String tag) {
    4264                 EncryptionDetail encryptionDetail = primaryPropertyEncryption.get(tag);
    4265                
    4266                 if (encryptionDetail == null) {
    4267                         EncryptionDetail unencryptedOnSave = new EncryptionDetail(EncryptionDetail.Type.UnencryptedOnSave);
    4268                         return unencryptedOnSave;
    4269                 } else {
    4270                         return encryptionDetail;
    4271                 }
    4272         }
    4273        
    4274         public void setEncryptionDetailForTag(String tag, EncryptionDetail encryptionDetail) {
    4275                 primaryPropertyEncryption.put(tag, encryptionDetail);
    4276         }
    4277        
    4278         public boolean isTagInherited(String tag) {
    4279                 return surrogatePropertyInheritance.get(tag);
    4280         }
    4281        
    4282         public void setTagNotInherited(String tag) {
    4283                 surrogatePropertyInheritance.put(tag, false);
    4284         }
    4285        
    4286         public boolean hasAccessToItemAsPrimary() {
    4287                 String label = this.getEncryptionLabel();
    4288                 if (this.isSurrogate() || label == null || label.length() == 0) {
    4289                         return true;
    4290                 }
    4291                
    4292                 return Label.getLabel(label).is(LabelResult.SuccessResolveLabelToKey);
    4293         }
    4294        
    4295 
    4296         /**
    4297          * If when setting a property, we find that the primary has a undeciphered value, when we must continue using that undeciphered value
    4298          * when eventually saving.
    4299          * @return
    4300          */
    4301         protected boolean subjectToInheritanceCheckOnSave(String tag) {
    4302                 if (tag.equals(DefaultFrameWriter.TYPE_AND_ID_STR)) {
    4303                         return false;
    4304                 }
    4305                 Item primary = getPrimary();
    4306                 if (primary == null) return false;
    4307                 EncryptionDetail primaryItemTagEncryptionDetail = primary.primaryPropertyEncryption.get(tag);
    4308                 Type primaryItemTagEncryptionDetailType = primaryItemTagEncryptionDetail.getEncryptionDetailType();
    4309                 return primaryItemTagEncryptionDetailType != EncryptionDetail.Type.UseUndecipheredValueOnSave;
    4310         }
    4311 
    4312         public boolean acceptsKeyboardEnter() {
    4313                 return _acceptsKeyboardEnter;
    4314         }
    4315                
    4316         public void setAcceptsEnter(boolean value) {
    4317                 if (this.getText() != null && this.getText().equals("Beep")) {
    4318                         System.err.println();
    4319                 }
    4320                 _acceptsKeyboardEnter = value;
    4321         }
    43224359}
Note: See TracChangeset for help on using the changeset viewer.