FileDocCategorySizeDatePackage
JACCPermissions.javaAPI DocHibernate 3.2.53756Fri Nov 25 05:00:22 GMT 2005org.hibernate.secure

JACCPermissions

public class JACCPermissions extends Object
Copied from JBoss org.jboss.ejb3.security.JaccHelper and org.jboss.ejb3.security.SecurityActions
author
Kabir Khan

Fields Summary
Constructors Summary
Methods Summary
public static voidcheckPermission(java.lang.Class clazz, java.lang.String contextID, javax.security.jacc.EJBMethodPermission methodPerm)

		CodeSource ejbCS = clazz.getProtectionDomain().getCodeSource();

		try {
			setContextID( contextID );

			Policy policy = Policy.getPolicy();
			// Get the caller
			Subject caller = getContextSubject();

			Principal[] principals = null;
			if ( caller != null ) {
				// Get the caller principals
				Set principalsSet = caller.getPrincipals();
				principals = new Principal[ principalsSet.size() ];
				principalsSet.toArray( principals );
			}

			ProtectionDomain pd = new ProtectionDomain( ejbCS, null, null, principals );
			if ( policy.implies( pd, methodPerm ) == false ) {
				String msg = "Denied: " + methodPerm + ", caller=" + caller;
				SecurityException e = new SecurityException( msg );
				throw e;
			}
		}
		catch (PolicyContextException e) {
			throw new RuntimeException( e );
		}
	
static javax.security.auth.SubjectgetContextSubject()


		   
	

	     
		if ( System.getSecurityManager() == null ) {
			return PolicyContextActions.NON_PRIVILEGED.getContextSubject();
		}
		else {
			return PolicyContextActions.PRIVILEGED.getContextSubject();
		}
	
static java.lang.StringsetContextID(java.lang.String contextID)

		PrivilegedAction action = new SetContextID( contextID );
		String previousID = (String) AccessController.doPrivileged( action );
		return previousID;