001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package javax.security.auth.kerberos;
019:
020: import java.io.IOException;
021: import java.io.ObjectInputStream;
022: import java.io.ObjectOutputStream;
023: import java.io.Serializable;
024: import java.security.BasicPermission;
025: import java.security.Permission;
026: import java.security.PermissionCollection;
027:
028: import org.apache.harmony.auth.internal.nls.Messages;
029:
030: public final class DelegationPermission extends BasicPermission
031: implements Serializable {
032:
033: private static final long serialVersionUID = 883133252142523922L;
034:
035: // initialization of a target name
036: private static String init(String name) {
037:
038: String trName = name.trim();
039:
040: int length = trName.length();
041: // length MUST be at least 7 characters
042: if (length < 7) {
043: throw new IllegalArgumentException(Messages
044: .getString("auth.20")); //$NON-NLS-1$
045:
046: }
047:
048: int index = name.indexOf('"', 2);
049:
050: if (trName.charAt(0) != '"' || index == -1
051: || (index + 6) > trName.length()
052: || trName.charAt(index + 1) != ' '
053: || trName.charAt(index + 2) != '"'
054: || trName.charAt(trName.length() - 1) != '"') {
055: throw new IllegalArgumentException(Messages
056: .getString("auth.20")); //$NON-NLS-1$
057: }
058: return trName;
059: }
060:
061: public DelegationPermission(String principals) {
062: super (init(principals));
063: }
064:
065: public DelegationPermission(String principals, String action) {
066: super (init(principals), action);
067: }
068:
069: @Override
070: public boolean equals(Object obj) {
071: if (obj == this ) {
072: return true;
073: }
074:
075: if (obj == null || obj.getClass() != this .getClass()) {
076: return false;
077: }
078:
079: return this .getName().equals(
080: ((DelegationPermission) obj).getName());
081: }
082:
083: @Override
084: public boolean implies(Permission permission) {
085: return equals(permission);
086: }
087:
088: @Override
089: public int hashCode() {
090: return getName().hashCode();
091: }
092:
093: @Override
094: public PermissionCollection newPermissionCollection() {
095: return new KrbDelegationPermissionCollection();
096: }
097:
098: private void writeObject(ObjectOutputStream s) throws IOException,
099: ClassNotFoundException {
100: s.defaultWriteObject();
101: }
102:
103: private void readObject(ObjectInputStream s) throws IOException,
104: ClassNotFoundException {
105: s.defaultReadObject();
106: init(getName());
107: }
108: }
|