001: /*
002: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003: *
004: * http://izpack.org/
005: * http://izpack.codehaus.org/
006: *
007: * Copyright 2006 Klaus Bartz
008: *
009: * Licensed under the Apache License, Version 2.0 (the "License");
010: * you may not use this file except in compliance with the License.
011: * You may obtain a copy of the License at
012: *
013: * http://www.apache.org/licenses/LICENSE-2.0
014: *
015: * Unless required by applicable law or agreed to in writing, software
016: * distributed under the License is distributed on an "AS IS" BASIS,
017: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: * See the License for the specific language governing permissions and
019: * limitations under the License.
020: */
021:
022: package com.coi.tools.os.win;
023:
024: import java.util.ArrayList;
025:
026: /**
027: * Data container for access control lists used by the registry stuff in the java and in the native
028: * part. DO NOT CHANGE METHODE SIGNATURES etc. without addapt the native methods
029: * RegistryImpl.modifyKeyACL and RegistryImpl.getKeyACL.
030: *
031: * @author Klaus Bartz
032: *
033: */
034: public class AccessControlList extends java.util.ArrayList {
035:
036: /**
037: * Required (serializable)
038: */
039: private static final long serialVersionUID = -5350586385078554562L;
040: private ArrayList<AccessControlEntry> permissions = new ArrayList<AccessControlEntry>();
041:
042: /**
043: * Default constructor.
044: */
045: public AccessControlList() {
046: super ();
047: }
048:
049: /**
050: * Creates an ACE entry in the permission array with the given values.
051: *
052: * @param owner owner of the ACE
053: * @param allowed access allowed mask
054: * @param denied access denied mask
055: */
056: public void setACE(String owner, int allowed, int denied) {
057: AccessControlEntry ace = new AccessControlEntry(owner, allowed,
058: denied);
059: permissions.add(ace);
060: }
061:
062: /**
063: * Returns the access control entry related to the given id.
064: *
065: * @param num id in the internal permisson array.
066: * @return the access control entry for the given id
067: */
068: public AccessControlEntry getACE(int num) {
069: return ((AccessControlEntry) ((permissions.get(num)).clone()));
070: }
071:
072: /**
073: * Returns number of access control entries.
074: *
075: * @return number of access control entries
076: */
077: public int getACECount() {
078: return (permissions.size());
079: }
080:
081: /**
082: * This class holds a representation of MS Windows ACEs.
083: *
084: * @author Klaus Bartz
085: *
086: */
087: public static class AccessControlEntry implements Cloneable {
088:
089: private String owner;
090:
091: private int accessAllowdMask;
092:
093: private int accessDeniedMask;
094:
095: /**
096: * Default constructor.
097: */
098: public AccessControlEntry() {
099: super ();
100: }
101:
102: /**
103: * Creates an ACE with the given parameter.
104: *
105: * @param owner2 owner of the ACE
106: * @param allowed access allowed mask
107: * @param denied access denied mask
108: */
109: public AccessControlEntry(String owner2, int allowed, int denied) {
110: owner = owner2;
111: accessAllowdMask = allowed;
112: accessDeniedMask = denied;
113: }
114:
115: /**
116: * Returns the owner.
117: *
118: * @return the owner
119: */
120: public String getOwner() {
121: return owner;
122: }
123:
124: /**
125: * Sets owner to the given value.
126: *
127: * @param owner The owner to set.
128: */
129: public void setOwner(String owner) {
130: this .owner = owner;
131: }
132:
133: /**
134: * Returns the accessAllowdMask.
135: *
136: * @return the accessAllowdMask
137: */
138: public int getAccessAllowdMask() {
139: return accessAllowdMask;
140: }
141:
142: /**
143: * Sets accessAllowdMask to the given value.
144: *
145: * @param accessAllowdMask The accessAllowdMask to set.
146: */
147: public void setAccessAllowdMask(int accessAllowdMask) {
148: this .accessAllowdMask = accessAllowdMask;
149: }
150:
151: /**
152: * Returns the accessDeniedMask.
153: *
154: * @return the accessDeniedMask
155: */
156: public int getAccessDeniedMask() {
157: return accessDeniedMask;
158: }
159:
160: /**
161: * Sets accessDeniedMask to the given value.
162: *
163: * @param accessDeniedMask The accessDeniedMask to set.
164: */
165: public void setAccessDeniedMask(int accessDeniedMask) {
166: this .accessDeniedMask = accessDeniedMask;
167: }
168:
169: /*
170: * (non-Javadoc)
171: *
172: * @see java.lang.Object#clone()
173: */
174: public Object clone() {
175: try {
176: return (super .clone());
177: } catch (CloneNotSupportedException e) {
178: e.printStackTrace();
179: }
180: return (null);
181: }
182: }
183:
184: }
|