Пример #1
0
        /// <inheritdoc />
        public override void InjectReferenceValue(X509Certificate2 value)
        {
            Certificate = value;

            Asn1Object exValue = GetExtensionValue(value);

            if (exValue == null)
            {
                if (IsRequired())
                {
                    throw new PolicyRequiredException("Extention " + ExtentionIdentifier.Display + " is marked as required by is not present.");
                }
                PolicyValue = new PolicyValue <string>(String.Empty);
                return;
            }
            var aki = AuthorityKeyIdentifier.GetInstance(exValue);

            byte[] keyId = aki.GetKeyIdentifier();
            if (keyId == null)
            {
                if (IsRequired())
                {
                    throw new PolicyRequiredException("Extention " + ExtentionIdentifier.Display +
                                                      " is marked as required by is not present.");
                }
                PolicyValue = new PolicyValue <string>(String.Empty);
            }
            PolicyValue = new PolicyValue <string>(PolicyUtils.CreateByteStringRep(keyId));
        }
Пример #2
0
 /**
  * Tries to resolve this permission into the specified class.
  * <p/>
  * It is assumed that the class has a proper name (as returned by {@code
  * getName()} of this unresolved permission), so no check is performed to
  * verify this. However, the class must have all required certificates (as
  * per {@code getUnresolvedCerts()}) among the passed collection of signers.
  * If it does, a zero, one, and/or two-argument constructor is tried to
  * instantiate a new permission, which is then returned.
  * <p/>
  * If an appropriate constructor is not available or the class is improperly
  * signed, {@code null} is returned.
  *
  * @param targetType
  *            - a target class instance, must not be {@code null}
  * @return resolved permission or null
  */
 internal Permission resolve(java.lang.Class targetType)
 {
     // check signers at first
     if (PolicyUtils.matchSubset(targetCerts, targetType.getSigners()))
     {
         try {
             return(PolicyUtils.instantiatePermission(targetType,
                                                      name,
                                                      actions));
         } catch (Exception) {
             //TODO log warning?
         }
     }
     return(null);
 }
Пример #3
0
        internal static bool Internal(Pawn getter, Pawn eater, bool desperate, out Thing foodSource, out ThingDef foodDef, bool canRefillDispenser = true, bool canUseInventory = true, bool allowForbidden = false, bool allowCorpse = true, Policy forcedPolicy = null)
        {
            List <FoodSourceRating> FoodListForPawn;

            FoodSearchCache.PawnEntry pawnEntry;

            if (!FoodSearchCache.TryGetEntryForPawn(getter, eater, out pawnEntry, allowForbidden))
            {
                Policy policy;

                if (forcedPolicy != null)
                {
                    policy = forcedPolicy;
                }
                else
                {
                    policy = PolicyUtils.GetPolicyAssignedTo(eater, getter);
                }

                bool foundFood = FoodUtils.MakeRatedFoodListForPawn(getter.Map, eater, getter, policy, out FoodListForPawn, canUseInventory, allowForbidden);

                pawnEntry = FoodSearchCache.AddPawnEntry(getter, eater, FoodListForPawn);
            }

            bool flagAllowHunt  = (getter == eater && eater.RaceProps.predator && !eater.health.hediffSet.HasTendableInjury());
            bool flagAllowPlant = (getter == eater);

            // C# 5 :'(
            var foodSourceRating = pawnEntry.GetBestFoodEntry(flagAllowPlant, allowCorpse, flagAllowHunt);

            if (foodSourceRating != null)
            {
                foodSource = foodSourceRating.FoodSource;
            }
            else
            {
                foodSource = null;
            }

            if (foodSource == null)              // ** If no food source is found set food Definition to null and return
            {
                foodDef = null;
                return(false);
            }

            foodDef = RimWorld.FoodUtility.GetFinalIngestibleDef(foodSource);             // ** Set food definition of food source and return
            return(true);

            //bool flag = getter.RaceProps.ToolUser && getter.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation);
            //Thing thing = null;
            //if (canUseInventory)
            //{
            //	if (flag)
            //	{
            //		thing = RimWorld.FoodUtility.BestFoodInInventory(getter, null, FoodPreferability.MealAwful, FoodPreferability.MealLavish, 0f, false);
            //	}
            //	if (thing != null)
            //	{
            //		if (getter.Faction != Faction.OfPlayer)
            //		{
            //			foodSource = thing;
            //			foodDef = RimWorld.FoodUtility.GetFinalIngestibleDef(foodSource);
            //			return true;
            //		}
            //		CompRottable compRottable = thing.TryGetComp<CompRottable>();
            //		if (compRottable != null && compRottable.Stage == RotStage.Fresh && compRottable.TicksUntilRotAtCurrentTemp < 30000)
            //		{
            //			foodSource = thing;
            //			foodDef = RimWorld.FoodUtility.GetFinalIngestibleDef(foodSource);
            //			return true;
            //		}
            //	}
            //}
            //bool allowPlant = getter == eater;
        }
Пример #4
0
        // static initialization
        // - load security properties files
        // - load statically registered providers
        // - if no provider description file found then load default providers
        static Security()
        {
            bool loaded = false;

            java.io.File f = new java.io.File(java.lang.SystemJ.getProperty("java.home")                //$NON-NLS-1$
                                              + java.io.File.separator + "lib" + java.io.File.separator //$NON-NLS-1$
                                              + "security" + java.io.File.separator + "java.security"); //$NON-NLS-1$ //$NON-NLS-2$
            if (f.exists())
            {
                try
                {
                    java.io.FileInputStream   fis = new java.io.FileInputStream(f);
                    java.io.InputStreamReader isJ = new java.io.InputStreamReader(fis);
                    secprops.load(isJ);
                    loaded = true;
                    isJ.close();
                }
                catch (java.io.IOException)
                {
                    //                        System.err.println("Could not load Security properties file: "
                    //                                        + e);
                }
            }

            if (Util.equalsIgnoreCase("true", secprops.getProperty("security.allowCustomPropertiesFile", "true")))
            {                                                                                    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                String securityFile = java.lang.SystemJ.getProperty("java.security.properties"); //$NON-NLS-1$
                if (securityFile != null)
                {
                    if (securityFile.startsWith("="))
                    { // overwrite //$NON-NLS-1$
                        secprops     = new java.util.Properties();
                        loaded       = false;
                        securityFile = securityFile.substring(1);
                    }
                    try
                    {
                        securityFile = PolicyUtils.expand(securityFile, java.lang.SystemJ.getProperties());
                    }
                    catch (PolicyUtils.ExpansionFailedException)
                    {
                        //                            System.err.println("Could not load custom Security properties file "
                        //                                    + securityFile +": " + e);
                    }
                    f = new java.io.File(securityFile);
                    java.io.InputStreamReader isj;
                    try
                    {
                        if (f.exists())
                        {
                            java.io.FileInputStream fis = new java.io.FileInputStream(f);
                            isj = new java.io.InputStreamReader(fis);
                        }
                        else
                        {
                            java.net.URL url = new java.net.URL(securityFile);
                            isj = new java.io.InputStreamReader(url.openStream());
                        }
                        secprops.load(isj);
                        loaded = true;
                        isj.close();
                    }
                    catch (java.io.IOException)
                    {
                        //                           System.err.println("Could not load custom Security properties file "
                        //                                   + securityFile +": " + e);
                    }
                }
            }
            if (!loaded)
            {
                registerDefaultProviders();
            }
            Engine.door = new SecurityDoor();
        }