diff --git a/src/com/sun/ts/tests/jacc/provider/TSPolicy.java b/src/com/sun/ts/tests/jacc/provider/TSPolicy.java index c8d9e2af38..ef72dbfe7e 100644 --- a/src/com/sun/ts/tests/jacc/provider/TSPolicy.java +++ b/src/com/sun/ts/tests/jacc/provider/TSPolicy.java @@ -36,6 +36,8 @@ import jakarta.security.jacc.EJBMethodPermission; import jakarta.security.jacc.EJBRoleRefPermission; +import jakarta.security.jacc.PolicyConfiguration; +import jakarta.security.jacc.PolicyConfigurationFactory; import jakarta.security.jacc.PolicyContext; import jakarta.security.jacc.WebResourcePermission; import jakarta.security.jacc.WebRoleRefPermission; @@ -187,6 +189,31 @@ public boolean implies(ProtectionDomain domain, Permission permission) { } } + // If there is a PolicyContext.getContextID, verify new getPolicyConfiguration() methods work + String contextId = PolicyContext.getContextID(); + if(contextId != null) { + try { + // Should be non-null PolicyConfiguration + PolicyConfigurationFactory pcf = PolicyConfigurationFactory.getPolicyConfigurationFactory(); + PolicyConfiguration pc = pcf.getPolicyConfiguration(); + if(pc != null) { + logger.log(Level.INFO, "PolicyConfigurationFactory.getPolicyConfiguration() : PASSED"); + } else { + logger.log(Level.INFO, "PolicyConfigurationFactory.getPolicyConfiguration() : FAILED"); + } + // Should be non-null PolicyConfiguration and match no-arg getPolicyConfiguration() + PolicyConfiguration pc2 = pcf.getPolicyConfiguration(contextId); + if(pc2 == null || !pc.equals(pc2)) { + logger.log(Level.INFO, "PolicyConfigurationFactory.getPolicyConfiguration(String) : FAILED"); + } else { + logger.log(Level.INFO, "PolicyConfigurationFactory.getPolicyConfiguration(String) : PASSED"); + } + + } catch (Exception e) { + logger.log(Level.INFO, "PolicyConfigurationFactory.getPolicyConfiguration() : FAILED"); + } + } + return policy.implies(domain, permission); } @@ -311,18 +338,16 @@ public static void setTSLogger(TSLogger lgr) { private void policyContextKey1() { try { // Get HttpServletRequest object - Object o = PolicyContext - .getContext("jakarta.servlet.http.HttpServletRequest"); - if (o instanceof jakarta.servlet.http.HttpServletRequest) { - logger.log(Level.INFO, "PolicyContext.getContext() " + "test passed for" - + "jakarta.servlet.http.HttpServletRequest"); - logger.log(Level.INFO, "PolicyContextKey1: PASSED"); - } else { - logger.log(Level.INFO, - "PolicyContext.getContext()" + "returned incorrect value for key " - + "jakarta.servlet.http.HttpServletRequest"); - logger.log(Level.INFO, "PolicyContextKey1: FAILED"); - } + jakarta.servlet.http.HttpServletRequest ctx = PolicyContext + .getContext("jakarta.servlet.http.HttpServletRequest"); + logger.log(Level.INFO, "PolicyContext.getContext() " + "test passed for" + + "jakarta.servlet.http.HttpServletRequest"); + logger.log(Level.INFO, "PolicyContextKey1: PASSED"); + } catch (ClassCastException e) { + logger.log(Level.INFO, + "PolicyContext.getContext()" + "returned incorrect value for key " + + "jakarta.servlet.http.HttpServletRequest"); + logger.log(Level.SEVERE, "PolicyContextKey1: FAILED"); } catch (Exception e) { logger.log(Level.SEVERE, "PolicyContextKey1: FAILED"); } @@ -342,18 +367,16 @@ private void policyContextKey1() { private void policyContextKey3() { try { // Get Subject - Object o = PolicyContext - .getContext("javax.security.auth.Subject.container"); - if (o instanceof javax.security.auth.Subject) { - logger.log(Level.INFO, "PolicyContext.getContext() " + "test passed for" - + "javax.security.auth.Subject.container"); - logger.log(Level.INFO, "PolicyContextKey3: PASSED"); - } else { - logger.log(Level.INFO, - "PolicyContext.getContext()" + "returned incorrect value for key " - + "javax.security.auth.Subject.container"); - logger.log(Level.INFO, "PolicyContextKey3: FAILED"); - } + javax.security.auth.Subject subject = PolicyContext + .getContext("javax.security.auth.Subject.container"); + logger.log(Level.INFO, "PolicyContext.getContext() " + "test passed for" + + "javax.security.auth.Subject.container"); + logger.log(Level.INFO, "PolicyContextKey3: PASSED"); + } catch (ClassCastException e) { + logger.log(Level.INFO, + "PolicyContext.getContext()" + "returned incorrect value for key " + + "javax.security.auth.Subject.container"); + logger.log(Level.INFO, "PolicyContextKey3: FAILED"); } catch (Exception e) { logger.log(Level.SEVERE, "PolicyContextKey3: FAILED"); } diff --git a/src/com/sun/ts/tests/jacc/provider/TSPolicyConfigurationFactoryImpl.java b/src/com/sun/ts/tests/jacc/provider/TSPolicyConfigurationFactoryImpl.java index 67afc3dd8b..796d5da2f0 100644 --- a/src/com/sun/ts/tests/jacc/provider/TSPolicyConfigurationFactoryImpl.java +++ b/src/com/sun/ts/tests/jacc/provider/TSPolicyConfigurationFactoryImpl.java @@ -27,6 +27,7 @@ import jakarta.security.jacc.PolicyConfiguration; import jakarta.security.jacc.PolicyConfigurationFactory; +import jakarta.security.jacc.PolicyContext; import jakarta.security.jacc.PolicyContextException; /** @@ -84,7 +85,7 @@ public TSPolicyConfigurationFactoryImpl() throws PolicyContextException { * be thread safe. *

* - * @param contextID + * @param contextId * A String identifying the policy context whose PolicyConfiguration * interface is to be returned. The value passed to this parameter * must not be null. @@ -187,7 +188,7 @@ public static PolicyConfigurationFactory getPolicyConfigurationFactory() * "inService" in the Policy provider associated with the factory. *

* - * @param contextID + * @param contextId * A string identifying a policy context * * @return true if the identified policy context exists within the provider @@ -222,13 +223,31 @@ public boolean inService(String contextId) throws PolicyContextException { } public PolicyConfiguration getPolicyConfiguration(String contextID){ - return null; + if (lgr.isLoggable(Level.FINER)) { + lgr.entering("PolicyConfigurationFactoryImpl", "getPolicyConfiguration(String)"); + } + PolicyConfiguration polConf = pcFactory.getPolicyConfiguration(contextID); + lgr.log(Level.INFO, + "PolicyConfigurationFactory.getPolicyConfiguration(String) invoked"); + return polConf; } public PolicyConfiguration getPolicyConfiguration(){ - return null; - } + String contextId = PolicyContext.getContextID(); + PolicyConfiguration polConf = null; + // check if we can invoke method + if (lgr.isLoggable(Level.FINER)) { + lgr.entering("PolicyConfigurationFactoryImpl", "getPolicyConfiguration()"); + } + polConf = pcFactory.getPolicyConfiguration(contextId); + lgr.log(Level.INFO, + "PolicyConfigurationFactory.getPolicyConfiguration(String) invoked"); + lgr.log(Level.FINER, + "Getting PolicyConfiguration object with id = " + contextId); + policyConfiguration = (TSPolicyConfigurationImpl) polConf; + return polConf; + } private static void getTSLogger() { if (lgr != null) diff --git a/src/com/sun/ts/tests/jacc/provider/TSPolicyConfigurationImpl.java b/src/com/sun/ts/tests/jacc/provider/TSPolicyConfigurationImpl.java index ae2f9ed46d..7384a76fb5 100644 --- a/src/com/sun/ts/tests/jacc/provider/TSPolicyConfigurationImpl.java +++ b/src/com/sun/ts/tests/jacc/provider/TSPolicyConfigurationImpl.java @@ -940,15 +940,15 @@ public static String stuffData(String inputStr) { } public PermissionCollection getExcludedPermissions(){ - return null; + return policyConfiguration.getExcludedPermissions(); } public PermissionCollection getUncheckedPermissions(){ - return null; + return policyConfiguration.getUncheckedPermissions(); } public Map getPerRolePermissions(){ - return null; + return policyConfiguration.getPerRolePermissions(); } private void assertIsInserviceState(String callingMethod) {