Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * 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.
  */
 
 package org.osgi.service.application;
 
This class implements permissions for manipulating applications and their instances.

ApplicationAdminPermission can be targeted to applications that matches the specified filter.

ApplicationAdminPermission may be granted for different actions: lifecycle, schedule and lock. The permission schedule implies the permission lifecycle.

Author(s):
$Id: c8c799ae29ff5bb6095e22d201b47a3445eb42cb $
 
 public class ApplicationAdminPermission extends Permission {
 	private static final long		serialVersionUID	= 1L;

Allows the lifecycle management of the target applications.
 
 	public static final String		LIFECYCLE_ACTION"lifecycle";

Allows scheduling of the target applications. The permission to schedule an application implies that the scheduler can also manage the lifecycle of that application i.e. schedule implies lifecycle
 
 	public static final String		SCHEDULE_ACTION"schedule";

Allows setting/unsetting the locking state of the target applications.
 
 	public static final String		LOCK_ACTION"lock";
 
Constructs an ApplicationAdminPermission. The filter specifies the target application. The filter is an LDAP-style filter, the recognized properties are signer and pid. The pattern specified in the signer is matched with the Distinguished Name chain used to sign the application. Wildcards in a DN are not matched according to the filter string rules, but according to the rules defined for a DN chain. The attribute pid is matched with the PID of the application according to the filter string rules.

If the filter is null then it matches "*". If actions is "*" then it identifies all the possible actions.

Parameters:
filter filter to identify application. The value null is equivalent to "*" and it indicates "all application".
actions comma-separated list of the desired actions granted on the applications or "*" means all the actions. It must not be null. The order of the actions in the list is not significant.
Throws:
org.osgi.framework.InvalidSyntaxException is thrown if the specified filter is not syntactically correct.
java.lang.NullPointerException is thrown if the actions parameter is null
See also:
ApplicationDescriptor
org.osgi.framework.AdminPermission
 
 	public ApplicationAdminPermission(String filterString actionsthrows InvalidSyntaxException {
 		super(filter == null ? "*" : filter);
 
 		if (filter == null)
 			filter = "*";
 
 		if (actions == null)
 			throw new NullPointerException("Action string cannot be null!");
 
		this. = null;
		this. = (filter == null ? "*" : filter);
		this. = actions;
		if (!filter.equals("*") && !filter.equals("<<SELF>>"))
			FrameworkUtil.createFilter(this.); // check if the filter is
														// valid
	}

This contructor should be used when creating ApplicationAdminPermission instance for checkPermission call.

Parameters:
application the tareget of the operation, it must not be null
actions the required operation. it must not be null
Throws:
java.lang.NullPointerException if any of the arguments is null.
	public ApplicationAdminPermission(ApplicationDescriptor applicationString actions) {
		super(application.getApplicationId());
		if (application == null || actions == null)
			throw new NullPointerException("ApplicationDescriptor and action string cannot be null!");
		this. = application.getApplicationId();
		this. = application;
		this. = actions;
	}

This method can be used in the java.security.ProtectionDomain implementation in the implies method to insert the application ID of the current application into the permission being checked. This enables the evaluation of the <<SELF>> pseudo targets.

Parameters:
applicationId the ID of the current application.
Returns:
the permission updated with the ID of the current application
		ApplicationAdminPermission newPerm = null;
		if (this. == null) {
			try {
				newPerm = new ApplicationAdminPermission(this.this.);
catch (InvalidSyntaxException e) {
				throw new RuntimeException(e); /* this can never happen */
			}
else
		newPerm.applicationID = applicationId;
		return newPerm;
	}

Checks if the specified permission is implied by this permission. The method returns true under the following conditions: Otherwise the method returns false.

Parameters:
otherPermission the implied permission
Returns:
true if this permission implies the otherPermission, false otherwise.
	public boolean implies(Permission otherPermission) {
		if (otherPermission == null)
			return false;
		if (!(otherPermission instanceof ApplicationAdminPermission))
			return false;
		if (!.equals("*")) {
			if (other.applicationDescriptor == null)
				return false;
			if (.equals("<<SELF>>")) {
				if (other.applicationID == null)
					return false/* it cannot be, this might be a bug */
				if (!other.applicationID.equals(other.applicationDescriptor.getApplicationId()))
					return false;
else {
				Hashtable props = new Hashtable();
				props.put("pid"other.applicationDescriptor.getApplicationId());
				props.put("signer"new SignerWrapper(other.applicationDescriptor));
				Filter flt = getFilter();
				if (flt == null)
					return false;
				if (!flt.match(props))
					return false;
			}
		}
		if (!.containsAll(other.actionsVector))
			return false;
		return true;
	}
	public boolean equals(Object with) {
		if (with == null || !(with instanceof ApplicationAdminPermission))
			return false;
		// Compare actions:
		if (other.actionsVector.size() != .size())
			return false;
		for (int i = 0; i != .size(); i++)
			if (!other.actionsVector.contains(.get(i)))
				return false;
		return equal(this.other.filter) && equal(this.other.applicationDescriptor) && equal(this.other.applicationID);
	}

Compares parameters for equality. If both object are null, they are considered equal.

Parameters:
a object to compare
b other object to compare
Returns:
true if both objects are equal or both are null
	private static boolean equal(Object aObject b) {
		// This equation is true if both references are null or both point
		// to the same object. In both cases they are considered as equal.
		if (a == b) {
			return true;
		}
		return a.equals(b);
	}
	public int hashCode() {
		int hc = 0;
		for (int i = 0; i != .size(); i++)
			hc ^= ((String.get(i)).hashCode();
		hc ^= (null == this.) ? 0 : this..hashCode();
		hc ^= (null == this.) ? 0 : this..hashCode();
		hc ^= (null == this.) ? 0 : this..hashCode();
		return hc;
	}

Returns the actions of this permission.

Returns:
the actions specified when this permission was created
	public String getActions() {
		return ;
	}
	private static final Vector	ACTIONSnew Vector();
	private final String		filter;
	private final String		actions;
	private Filter				appliedFilternull;
	static {
	}
	private static Vector actionsVector(String actions) {
		Vector v = new Vector();
		StringTokenizer t = new StringTokenizer(actions.toUpperCase(), ",");
		while (t.hasMoreTokens()) {
			String action = t.nextToken().trim();
			v.add(action.toLowerCase());
		}
		return v;
	}
	private static class SignerWrapper extends Object {
		private String					pattern;

Parameters:
pattern
		public SignerWrapper(String pattern) {
			this. = pattern;
		}
			this. = appDesc;
		}
		public boolean equals(Object o) {
			if (!(o instanceof SignerWrapper))
				return false;
			ApplicationDescriptor matchAppDesc =  != null ?  : other.appDesc;
			String matchPattern =  != null ? other.pattern : ;
			return matchAppDesc.matchDNChain(matchPattern);
		}
	}
	private void init() {
		if (.equals("*"))
		else
				throw new IllegalArgumentException("Illegal action!");
		 = null;
	}
	private Filter getFilter() {
		if ( == null) {
			try {
				 = FrameworkUtil.createFilter();
catch (InvalidSyntaxException e) {
				// we will return null
			}
		}
	}
New to GrepCode? Check out our FAQ X