use of ddf.security.service.SecurityManager in project ddf by codice.
the class TestPepInterceptorActions method testMessageWithOperationAction.
@Test
public void testMessageWithOperationAction() throws SecurityServiceException {
PEPAuthorizingInterceptor interceptor = new PEPAuthorizingInterceptor();
SecurityManager mockSecurityManager = mock(SecurityManager.class);
interceptor.setSecurityManager(mockSecurityManager);
Message messageWithAction = mock(Message.class);
SecurityAssertion mockSecurityAssertion = mock(SecurityAssertion.class);
SecurityToken mockSecurityToken = mock(SecurityToken.class);
Subject mockSubject = mock(Subject.class);
assertNotNull(mockSecurityAssertion);
PowerMockito.mockStatic(SecurityAssertionStore.class);
PowerMockito.mockStatic(SecurityLogger.class);
when(SecurityAssertionStore.getSecurityAssertion(messageWithAction)).thenReturn(mockSecurityAssertion);
// SecurityLogger is already stubbed out
when(mockSecurityAssertion.getSecurityToken()).thenReturn(mockSecurityToken);
when(mockSecurityToken.getToken()).thenReturn(null);
when(mockSecurityManager.getSubject(mockSecurityToken)).thenReturn(mockSubject);
Exchange mockExchange = mock(Exchange.class);
BindingOperationInfo mockBOI = mock(BindingOperationInfo.class);
SoapOperationInfo mockSOI = mock(SoapOperationInfo.class);
when(messageWithAction.getExchange()).thenReturn(mockExchange);
when(mockExchange.get(BindingOperationInfo.class)).thenReturn(mockBOI);
when(mockBOI.getExtensor(SoapOperationInfo.class)).thenReturn(mockSOI);
when(mockSOI.getAction()).thenReturn("urn:catalog:query:query-port:search");
doAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
CollectionPermission perm = (CollectionPermission) invocation.getArguments()[0];
assertEquals("urn:catalog:query:query-port:search", perm.getAction());
return true;
}
}).when(mockSubject).isPermitted(isA(CollectionPermission.class));
// This should work.
interceptor.handleMessage(messageWithAction);
PowerMockito.verifyStatic();
}
use of ddf.security.service.SecurityManager in project ddf by codice.
the class IdpEndpointTest method testExpiredLoginCookie.
@Test
public void testExpiredLoginCookie() throws SecurityServiceException, WSSecurityException {
String samlRequest = authNRequestGet;
HttpServletRequest request = mock(HttpServletRequest.class);
Cookie cookie = mock(Cookie.class);
SecurityManager securityManager = mock(SecurityManager.class);
when(securityManager.getSubject(anyObject())).thenThrow(new SecurityServiceException("test"));
idpEndpoint.setSecurityManager(securityManager);
when(request.isSecure()).thenReturn(true);
when(request.getRequestURL()).thenReturn(requestURL);
when(request.getAttribute(ContextPolicy.ACTIVE_REALM)).thenReturn("*");
when(request.getCookies()).thenReturn(new Cookie[] { cookie });
when(cookie.getName()).thenReturn(IdpEndpoint.COOKIE);
when(cookie.getValue()).thenReturn("2");
Response response = idpEndpoint.showGetLogin(samlRequest, relayState, signatureAlgorithm, signature, request);
//the only cookie that should exist is the "1" cookie so "2" should send us to the login webapp
assertThat(response.getEntity().toString(), containsString("<title>Login</title>"));
}
use of ddf.security.service.SecurityManager in project ddf by codice.
the class IdpEndpointTest method testPassiveLoginPkiSignatureErrorPost.
@Test
public void testPassiveLoginPkiSignatureErrorPost() throws SecurityServiceException, WSSecurityException, CertificateEncodingException, IOException {
String samlRequest = authNRequestPassivePkiPost;
HttpServletRequest request = mock(HttpServletRequest.class);
X509Certificate x509Certificate = mock(X509Certificate.class);
SecurityManager securityManager = mock(SecurityManager.class);
when(securityManager.getSubject(anyObject())).thenThrow(new SecurityServiceException("test"));
idpEndpoint.setSecurityManager(securityManager);
when(request.isSecure()).thenReturn(true);
when(request.getRequestURL()).thenReturn(requestURL);
when(request.getAttribute(ContextPolicy.ACTIVE_REALM)).thenReturn("*");
//dummy cert
when((X509Certificate[]) request.getAttribute(requestCertificateAttributeName)).thenReturn(new X509Certificate[] { x509Certificate });
when(x509Certificate.getEncoded()).thenReturn(new byte[48]);
Response response = idpEndpoint.showPostLogin(samlRequest, relayState, request);
assertThat(response.getStatus(), is(500));
}
use of ddf.security.service.SecurityManager in project ddf by codice.
the class IdpEndpointTest method testFailedLogin.
@Test
public void testFailedLogin() throws SecurityServiceException {
String samlRequest = authNRequestGet;
HttpServletRequest request = mock(HttpServletRequest.class);
SecurityManager securityManager = mock(SecurityManager.class);
when(securityManager.getSubject(anyObject())).thenThrow(new SecurityServiceException("test"));
idpEndpoint.setSecurityManager(securityManager);
when(request.isSecure()).thenReturn(true);
when(request.getRequestURL()).thenReturn(requestURL);
when(request.getAttribute(ContextPolicy.ACTIVE_REALM)).thenReturn("*");
Response response = idpEndpoint.processLogin(samlRequest, relayState, Idp.GUEST, signatureAlgorithm, signature, SamlProtocol.REDIRECT_BINDING, request);
assertThat(response.getStatus(), is(401));
}
use of ddf.security.service.SecurityManager in project ddf by codice.
the class IdpEndpointTest method testLoginForceAuthnCookie.
@Test
public void testLoginForceAuthnCookie() throws SecurityServiceException, WSSecurityException, IOException {
String samlRequest = RestSecurity.deflateAndBase64Encode(authNRequestGetForce);
HttpServletRequest request = mock(HttpServletRequest.class);
Cookie cookie = mock(Cookie.class);
SecurityManager securityManager = mock(SecurityManager.class);
when(securityManager.getSubject(anyObject())).thenThrow(new SecurityServiceException("test"));
idpEndpoint.setSecurityManager(securityManager);
idpEndpoint.setStrictSignature(false);
when(request.isSecure()).thenReturn(true);
when(request.getRequestURL()).thenReturn(requestURL);
when(request.getAttribute(ContextPolicy.ACTIVE_REALM)).thenReturn("*");
when(request.getCookies()).thenReturn(new Cookie[] { cookie });
when(cookie.getName()).thenReturn(IdpEndpoint.COOKIE);
when(cookie.getValue()).thenReturn("1");
Response response = idpEndpoint.showGetLogin(samlRequest, relayState, signatureAlgorithm, signature, request);
assertThat(response.getEntity().toString(), containsString("<title>Login</title>"));
}
Aggregations