* Copyright (c) OSGi Alliance (2004, 2013). All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
DmtPrincipalPermission has a target string which controls the name of
the principal on whose behalf the protocol adapter can act. A wildcard is
allowed at the end of the target string, to allow using any principal name
with the given prefix. The "*" target means the adapter can create
a session in the name of any principal.
// specifies whether the target string had a wildcard at the end
// the target string without the wildcard (if there was one)
DmtPrincipalPermissionobject with its name set to the target string. Name must be non-null and non-empty.
if (target == null)
DmtPrincipalPermissionobject using the 'canonical' two argument constructor. In this version this class does not define any actions, the second argument of this constructor must be "*" so that this class can later be extended in a backward compatible way.
targetthe name of the principal, can end with
*to match any principal with the given prefix
actionsno actions defined, must be "*" for forward compatibility
nameis empty or
actionsis not "*"
if (actions == null)
objthe object to compare to this DmtPrincipalPermission instance
trueif the parameter represents the same permissions as this instance
if (obj == this)
method, then calling this method on each of the two DmtPrincipalPermission objects must produce the same integer result.
pthe permission to check for implication
* Returns true if the principal parameter of the given
* DmtPrincipalPermission is implied by the principal of this permission,
* i.e. this principal is a prefix of the other principal but ends with a *,
* or the two principal strings are equal.
return isPrefix ? p.principal.startsWith(principal) : !p.isPrefix && p.principal.equals(principal);
throw new IllegalArgumentException("Cannot add permission, invalid permission type: " + permission);
// only add new permission if it is not already implied by the
// permissions in the collection
// remove all permissions that are implied by the new one
// no need to synchronize because all adds are done sequentially
// before any implies() calls
// Convert Iterator into Enumeration