PModeFinder { public static Collection<IPMode> findForPulling(final Collection<ISecurityProcessingResult> authInfo, final String mpc) throws SecurityProcessingException { final ArrayList<IPMode> pmodesForPulling = new ArrayList<>(); for(final IPMode p : HolodeckB2BCoreInterface.getPModeSet().getAll()) { final ILeg leg = PModeUtils.getInPullRequestLeg(p); if (leg != null) { boolean authorized = false; ISecurityConfiguration tpSecCfg = null; if (PModeUtils.isHolodeckB2BInitiator(p) && p.getResponder() != null) tpSecCfg = p.getResponder().getSecurityConfiguration(); else if (!PModeUtils.isHolodeckB2BInitiator(p) && p.getInitiator() != null) tpSecCfg = p.getInitiator().getSecurityConfiguration(); final Collection<IPullRequestFlow> flows = leg.getPullRequestFlows(); if (Utils.isNullOrEmpty(flows)) { authorized = checkMainMPC(leg, mpc) && verifyPullRequestAuthorization(null, tpSecCfg, authInfo); } else { for (final Iterator<IPullRequestFlow> it = flows.iterator(); it.hasNext() && !authorized;) { final IPullRequestFlow flow = it.next(); authorized = checkSubMPC(flow, mpc) && verifyPullRequestAuthorization(flow.getSecurityConfiguration(), tpSecCfg, authInfo); } } if (authorized) pmodesForPulling.add(p); } } return pmodesForPulling; }  static IPMode forReceivedUserMessage(final IUserMessage mu); static Collection<IPMode> findForPulling(final Collection<ISecurityProcessingResult> authInfo,
                                                    final String mpc); static Collection<IPMode> getPModesWithErrorsTo(final String url); static Collection<IPMode> getPModesWithReceiptsTo(final String url);  }
@Test public void testPartnerDefinedEbmsUTOnly() throws Exception { final Collection<ISecurityProcessingResult> authInfo = new ArrayList<>(); IUsernameTokenProcessingResult utResultMock = mock(IUsernameTokenProcessingResult.class); when(utResultMock.getUsername()).thenReturn("johndoe"); when(utResultMock.getPassword()).thenReturn("secret"); when(utResultMock.getPasswordType()).thenReturn(UTPasswordType.TEXT); when(utResultMock.getTargetedRole()).thenReturn(SecurityHeaderTarget.EBMS); authInfo.add(utResultMock); Collection<IPMode> pmodes = PModeFinder.findForPulling(authInfo, null); assertFalse(Utils.isNullOrEmpty(pmodes)); assertEquals("tp_ebms_ut_only", pmodes.iterator().next().getId()); }
@Test public void testFlowDefinedEbmsUTOnly() throws Exception { final Collection<ISecurityProcessingResult> authInfo = new ArrayList<>(); IUsernameTokenProcessingResult utResultMock = mock(IUsernameTokenProcessingResult.class); when(utResultMock.getUsername()).thenReturn("johndoe"); when(utResultMock.getPassword()).thenReturn("secret"); when(utResultMock.getPasswordType()).thenReturn(UTPasswordType.TEXT); when(utResultMock.getTargetedRole()).thenReturn(SecurityHeaderTarget.EBMS); authInfo.add(utResultMock); Collection<IPMode> pmodes = PModeFinder.findForPulling(authInfo, "http: assertFalse(Utils.isNullOrEmpty(pmodes)); assertEquals("flow_ebms_ut_only", pmodes.iterator().next().getId()); }
@Test public void testFlowOverrideEbmsUTOnly() throws Exception { final Collection<ISecurityProcessingResult> authInfo = new ArrayList<>(); IUsernameTokenProcessingResult utResultMock = mock(IUsernameTokenProcessingResult.class); when(utResultMock.getUsername()).thenReturn("janedoe"); when(utResultMock.getPassword()).thenReturn("secret"); when(utResultMock.getPasswordType()).thenReturn(UTPasswordType.TEXT); when(utResultMock.getTargetedRole()).thenReturn(SecurityHeaderTarget.EBMS); authInfo.add(utResultMock); Collection<IPMode> pmodes = PModeFinder.findForPulling(authInfo, null); assertFalse(Utils.isNullOrEmpty(pmodes)); assertEquals("flow_override_ebms_ut_only", pmodes.iterator().next().getId()); }
@Test public void testNoneFound() throws Exception { final Collection<ISecurityProcessingResult> authInfo = new ArrayList<>(); IUsernameTokenProcessingResult utResultMock = mock(IUsernameTokenProcessingResult.class); when(utResultMock.getUsername()).thenReturn("nothere"); when(utResultMock.getPassword()).thenReturn("notsosecret"); when(utResultMock.getPasswordType()).thenReturn(UTPasswordType.TEXT); when(utResultMock.getTargetedRole()).thenReturn(SecurityHeaderTarget.EBMS); authInfo.add(utResultMock); Collection<IPMode> pmodes = PModeFinder.findForPulling(authInfo, null); assertTrue(Utils.isNullOrEmpty(pmodes)); }