use of ddf.security.audit.SecurityLogger in project ddf by codice.
the class PepInterceptorInvalidSubjectTest method testMessageInvalidSecurityAssertionToken.
// CHECKSTYLE.ON: VisibilityModifier
@Test
public void testMessageInvalidSecurityAssertionToken() throws SecurityServiceException {
SecurityAssertion mockSecurityAssertion = mock(SecurityAssertion.class);
PEPAuthorizingInterceptor interceptor = spy(new PEPAuthorizingInterceptor(m -> mockSecurityAssertion));
interceptor.setSecurityLogger(mock(SecurityLogger.class));
SecurityManager mockSecurityManager = mock(SecurityManager.class);
interceptor.setSecurityManager(mockSecurityManager);
Message messageWithInvalidSecurityAssertion = mock(Message.class);
SecurityToken mockSecurityToken = mock(SecurityToken.class);
Subject mockSubject = mock(Subject.class);
assertNotNull(mockSecurityAssertion);
// SecurityLogger is already stubbed out
when(mockSecurityAssertion.getToken()).thenReturn(mockSecurityToken);
when(mockSecurityToken.getToken()).thenReturn(null);
when(mockSecurityManager.getSubject(mockSecurityToken)).thenReturn(mockSubject);
QName op = new QName("urn:catalog:query", "search", "ns1");
QName port = new QName("urn:catalog:query", "query-port", "ns1");
when(messageWithInvalidSecurityAssertion.get("javax.xml.ws.wsdl.operation")).thenReturn(op);
when(messageWithInvalidSecurityAssertion.get("javax.xml.ws.wsdl.port")).thenReturn(port);
Exchange mockExchange = mock(Exchange.class);
BindingOperationInfo mockBOI = mock(BindingOperationInfo.class);
when(messageWithInvalidSecurityAssertion.getExchange()).thenReturn(mockExchange);
when(mockExchange.get(BindingOperationInfo.class)).thenReturn(mockBOI);
when(mockBOI.getExtensor(SoapOperationInfo.class)).thenReturn(null);
when(mockSubject.isPermitted(isA(CollectionPermission.class))).thenReturn(false);
expectedExForInvalidSubject.expect(AccessDeniedException.class);
expectedExForInvalidSubject.expectMessage("Unauthorized");
// This should throw
interceptor.handleMessage(messageWithInvalidSecurityAssertion);
}
use of ddf.security.audit.SecurityLogger in project ddf by codice.
the class PepInterceptorNullAssertionTokenTest method testMessageNullSecurityAssertionToken.
@Test
public void testMessageNullSecurityAssertionToken() {
Message messageWithNullSecurityAssertion = mock(Message.class);
SecurityAssertion mockSecurityAssertion = mock(SecurityAssertion.class);
assertNotNull(mockSecurityAssertion);
PEPAuthorizingInterceptor interceptor = spy(new PEPAuthorizingInterceptor(m -> mockSecurityAssertion));
interceptor.setSecurityLogger(mock(SecurityLogger.class));
// SecurityLogger is already stubbed out
when(mockSecurityAssertion.getToken()).thenReturn(null);
expectedExForNullMessage.expect(AccessDeniedException.class);
expectedExForNullMessage.expectMessage("Unauthorized");
interceptor.handleMessage(messageWithNullSecurityAssertion);
}
use of ddf.security.audit.SecurityLogger in project ddf by codice.
the class SslLdapLoginModule method installSecurityLogger.
private void installSecurityLogger() {
BundleContext bundleContext = getContext();
if (bundleContext != null) {
ServiceReference serviceReference = bundleContext.getServiceReference(SecurityLogger.class.getName());
securityLogger = (SecurityLogger) bundleContext.getService(serviceReference);
bundleContext.ungetService(serviceReference);
}
}
use of ddf.security.audit.SecurityLogger in project ddf by codice.
the class PepInterceptorNullAssertionTest method testMessageNullSecurityAssertion.
@Test
public void testMessageNullSecurityAssertion() {
PEPAuthorizingInterceptor interceptor = spy(new PEPAuthorizingInterceptor(m -> null));
interceptor.setSecurityLogger(mock(SecurityLogger.class));
Message messageWithNullSecurityAssertion = mock(Message.class);
// SecurityLogger is already stubbed out
expectedExForNullMessage.expect(AccessDeniedException.class);
expectedExForNullMessage.expectMessage("Unauthorized");
interceptor.handleMessage(messageWithNullSecurityAssertion);
}
use of ddf.security.audit.SecurityLogger in project ddf by codice.
the class PepInterceptorValidSubjectTest method testMessageValidSecurityAssertionToken.
@Test
public void testMessageValidSecurityAssertionToken() throws SecurityServiceException {
SecurityAssertion mockSecurityAssertion = mock(SecurityAssertion.class);
PEPAuthorizingInterceptor interceptor = spy(new PEPAuthorizingInterceptor(m -> mockSecurityAssertion));
interceptor.setSecurityLogger(mock(SecurityLogger.class));
SecurityManager mockSecurityManager = mock(SecurityManager.class);
interceptor.setSecurityManager(mockSecurityManager);
Message messageWithValidSecurityAssertion = mock(Message.class);
SecurityToken mockSecurityToken = mock(SecurityToken.class);
Subject mockSubject = mock(Subject.class);
assertNotNull(mockSecurityAssertion);
// SecurityLogger is already stubbed out
when(mockSecurityAssertion.getToken()).thenReturn(mockSecurityToken);
when(mockSecurityToken.getToken()).thenReturn(null);
when(mockSecurityManager.getSubject(mockSecurityToken)).thenReturn(mockSubject);
QName op = new QName("urn:catalog:query", "search", "ns1");
QName port = new QName("urn:catalog:query", "query-port", "ns1");
when(messageWithValidSecurityAssertion.get("javax.xml.ws.wsdl.operation")).thenReturn(op);
when(messageWithValidSecurityAssertion.get("javax.xml.ws.wsdl.port")).thenReturn(port);
Exchange mockExchange = mock(Exchange.class);
BindingOperationInfo mockBOI = mock(BindingOperationInfo.class);
when(messageWithValidSecurityAssertion.getExchange()).thenReturn(mockExchange);
when(mockExchange.get(BindingOperationInfo.class)).thenReturn(mockBOI);
when(mockBOI.getExtensor(SoapOperationInfo.class)).thenReturn(null);
when(mockSubject.isPermitted(isA(CollectionPermission.class))).thenReturn(true);
// This should work.
interceptor.handleMessage(messageWithValidSecurityAssertion);
}
Aggregations