source: trunk/src/org/expeditee/items/PermissionPair.java@ 1200

Last change on this file since 1200 was 1200, checked in by bln4, 6 years ago

org.expeditee.auth.gio.EncryptedExpReader ->
org.expeditee.auth.gio.EncryptedExpWriter ->
org.expeditee.io.DefaultFrameReader ->
org.expeditee.io.DefaultFrameWriter ->
org.expeditee.io.ExpReader ->
org.expeditee.io.ExpWriter ->

The beginnings of a authentication system for Expeditee. Frame files (.exp) can now be encrypted with a password. A login system is being developed to accompany this.


org.expeditee.gui.AttributeUtils ->
org.expeditee.gui.Frame ->
org.expeditee.gui.FrameUtils ->
org.expeditee.items.Item ->
org.expeditee.items.PermissionPair ->
org.expeditee.items.Text ->

As part of the development the login screen. Modifications to Text Items have been made. New properties are 'Mask' and 'MinWidth'. Mask allows you to set a character to use as...a mask...for example, a password field using '*'. MinWidth allows you to specify a minimum width for text boxes. A text box with a minimum width never shrinks below this width; even when it has no content.

  • Property svn:executable set to *
File size: 3.8 KB
Line 
1/**
2 * PermissionPair.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.items;
20
21import org.expeditee.settings.UserSettings;
22
23public class PermissionPair {
24
25 private UserAppliedPermission ownerPermission;
26 private UserAppliedPermission notOwnerPermission;
27
28 public PermissionPair(String permissionCode, UserAppliedPermission defaultPermission) {
29 ownerPermission = defaultPermission;
30 notOwnerPermission = defaultPermission;
31
32 if (permissionCode != null) {
33
34 permissionCode = permissionCode.trim().toLowerCase();
35 if (permissionCode.length() != 0) {
36
37 if (permissionCode.length() == 1 || (permissionCode.length() == 2 && permissionCode.startsWith("-"))) {
38 // replicate it to cover ifOwner/ifNotOwner
39 permissionCode += permissionCode;
40 }
41
42 final int ownerPermissionIndexStart = 0;
43 final int ownerPermissionIndexEnd = permissionCode.charAt(ownerPermissionIndexStart) == '-' ?
44 ownerPermissionIndexStart + 2 : ownerPermissionIndexStart + 1;
45 final int notOwnerPermissionIndexStart = ownerPermissionIndexEnd;
46 final int notOwnerPermissionIndexEnd = permissionCode.charAt(notOwnerPermissionIndexStart) == '-' ?
47 notOwnerPermissionIndexStart + 2 : notOwnerPermissionIndexStart + 1;
48 final String ownerPermissionCode = permissionCode.substring(ownerPermissionIndexStart, ownerPermissionIndexEnd);
49 final String notOwnerPermissionCode = permissionCode.substring(notOwnerPermissionIndexStart, notOwnerPermissionIndexEnd);
50 ownerPermission = UserAppliedPermission.getPermission(ownerPermissionCode, defaultPermission);
51 notOwnerPermission = UserAppliedPermission.getPermission(notOwnerPermissionCode, defaultPermission);
52 }
53 }
54 }
55
56 public PermissionPair(UserAppliedPermission ownerPermission, UserAppliedPermission notOwnerPermission) {
57 this.ownerPermission = ownerPermission;
58 this.notOwnerPermission = notOwnerPermission;
59 }
60
61 public PermissionPair(UserAppliedPermission ownerPermissionForBoth) {
62 this(ownerPermissionForBoth, ownerPermissionForBoth);
63 }
64
65 public PermissionPair(PermissionPair pp) {
66 ownerPermission = pp.ownerPermission;
67 notOwnerPermission = pp.notOwnerPermission;
68 }
69
70 public UserAppliedPermission getPermission(String ownerOfItem) {
71
72 if (UserSettings.UserName.get().equals(ownerOfItem)) {
73 return ownerPermission;
74 } else {
75 return notOwnerPermission;
76 }
77 }
78
79 /**
80 * Converts the given Expeditee permission code into a PermissionPair
81 * corresponding to the constants defined in Item.
82 *
83 * @param permissionCode
84 * The Expeditee permission code to convert
85 * @return The resulting PermissionPair corresponding to a pair of constants as
86 * defined in Item
87 */
88 public static PermissionPair convertString(String permissionCode) {
89 PermissionPair pp = new PermissionPair(permissionCode, UserAppliedPermission.full);
90
91 return pp;
92 }
93
94 public String getCode() {
95 return Integer.toString(ownerPermission.getCode()) + Integer.toString(notOwnerPermission.getCode());
96 }
97
98 @Override
99 public String toString() {
100 return ownerPermission.toString() + ":" + notOwnerPermission.toString();
101 }
102}
Note: See TracBrowser for help on using the repository browser.