1 16 package org.apache.pluto.portalImpl.portlet.test; 17 18 import java.util.Map ; 19 import java.util.Properties ; 20 21 import javax.portlet.ActionRequest; 22 import javax.portlet.ActionResponse; 23 import javax.portlet.PortletContext; 24 import javax.portlet.PortletRequest; 25 26 import org.apache.pluto.testsuite.ExpectedResults; 27 28 31 public class SecurityMappingTest extends AbstractReflectivePortletTest { 32 33 public String getTestSuiteName() { 34 return "Security Mapping Tests"; 35 } 36 37 public Map doPrerequisiteAction(PortletContext context, ActionRequest req, 38 ActionResponse res) { 39 return new java.util.HashMap (); 40 } 41 42 protected TestResult checkIsUserInMappedRole(PortletRequest req) { 43 TestResult res = isUserLoggedIn(req); 44 res.setName("User In Mapped Role Test"); 45 res.setDesc("Test if user is in mapped role"); 46 if(TestResult.WARNING.equals(res.getReturnCode())) { 47 return res; 48 } 49 50 Properties props = ExpectedResults.getExpectedProperties(); 51 String role = props.getProperty("expected.security.role.mapped"); 52 53 if(req.isUserInRole(role)) { 54 res.setReturnCode(TestResult.PASSED); 55 } 56 else { 57 res.setReturnCode(TestResult.WARNING); 58 res.setReturnCode("User is not in the expected '"+role+"' role. This may be due to misconfiuration."); 59 } 60 61 return res; 62 } 63 64 protected TestResult checkIsUserInUnmappedRole(PortletRequest req) { 65 TestResult res = isUserLoggedIn(req); 66 res.setName("User In Unmapped Role Test"); 67 res.setDesc("Test if user is in unmapped role"); 68 if(TestResult.WARNING.equals(res.getReturnCode())) { 69 return res; 70 } 71 72 Properties props = ExpectedResults.getExpectedProperties(); 73 String role = props.getProperty("expected.security.role"); 74 75 if(req.isUserInRole(role)) { 76 res.setReturnCode(TestResult.PASSED); 77 } 78 else { 79 res.setReturnCode(TestResult.WARNING); 80 res.setReturnCode("User is not in the expected '"+role+"' role. This may be due to misconfiuration."); 81 } 82 83 return res; 84 } 85 86 protected TestResult checkIsUserIndUndeclaredRole(PortletRequest req) { 87 TestResult res = isUserLoggedIn(req); 88 res.setName("User In Undeclared Role Test"); 89 res.setDesc("Test if user is in undeclared role"); 90 if(TestResult.WARNING.equals(res.getReturnCode())) { 91 return res; 92 } 93 94 if(!req.isUserInRole("fakeTestRoleFooBar")) { 95 res.setReturnCode(TestResult.PASSED); 96 } 97 else { 98 res.setReturnCode(TestResult.FAILED); 99 res.setReturnCode("User is in the fake role named 'fakeTestRoleFooBar'"); 100 } 101 102 return res; 103 } 104 105 106 private TestResult isUserLoggedIn(PortletRequest req) { 107 if (req.getRemoteUser()==null) { 108 TestResult res = new TestResult(); 109 res.setReturnCode(TestResult.WARNING); 110 res.setResults("User is not logged in."); 111 return res; 112 } 113 return new TestResult(); 114 } 115 } 116 | Popular Tags |