use of javax.ws.rs.core.HttpHeaders in project keycloak by keycloak.
the class HttpBasicAuthenticator method authenticate.
@Override
public void authenticate(final AuthenticationFlowContext context) {
final HttpRequest httpRequest = context.getHttpRequest();
final HttpHeaders httpHeaders = httpRequest.getHttpHeaders();
final String[] usernameAndPassword = getUsernameAndPassword(httpHeaders);
context.attempted();
if (usernameAndPassword != null) {
final RealmModel realm = context.getRealm();
final String username = usernameAndPassword[0];
final UserModel user = context.getSession().users().getUserByUsername(realm, username);
// to allow success/failure logging for brute force
context.getEvent().detail(Details.USERNAME, username);
context.getAuthenticationSession().setAuthNote(AbstractUsernameFormAuthenticator.ATTEMPTED_USERNAME, username);
if (user != null) {
final String password = usernameAndPassword[1];
final boolean valid = context.getSession().userCredentialManager().isValid(realm, user, UserCredentialModel.password(password));
if (valid) {
if (isTemporarilyDisabledByBruteForce(context, user)) {
userDisabledAction(context, realm, user, Errors.USER_TEMPORARILY_DISABLED);
} else if (user.isEnabled()) {
userSuccessAction(context, user);
} else {
userDisabledAction(context, realm, user, Errors.USER_DISABLED);
}
} else {
notValidCredentialsAction(context, realm, user);
}
} else {
nullUserAction(context, realm, username);
}
}
}
use of javax.ws.rs.core.HttpHeaders in project ddf by codice.
the class CatalogServiceImplTest method testAddDocumentWithAttributeOverrides.
@Test
@SuppressWarnings({ "unchecked" })
public void testAddDocumentWithAttributeOverrides() throws Exception {
CatalogFramework framework = givenCatalogFramework();
AttributeDescriptor descriptor = new AttributeDescriptorImpl("custom.attribute", true, true, false, false, BasicTypes.STRING_TYPE);
HttpHeaders headers = createHeaders(Collections.singletonList(MediaType.APPLICATION_JSON));
BundleContext bundleContext = mock(BundleContext.class);
Collection<ServiceReference<InputTransformer>> serviceReferences = new ArrayList<>();
ServiceReference serviceReference = mock(ServiceReference.class);
InputTransformer inputTransformer = mock(InputTransformer.class);
when(inputTransformer.transform(any())).thenReturn(new MetacardImpl());
when(bundleContext.getService(serviceReference)).thenReturn(inputTransformer);
serviceReferences.add(serviceReference);
when(bundleContext.getServiceReferences(InputTransformer.class, "(id=xml)")).thenReturn(serviceReferences);
when(attributeRegistry.lookup("custom.attribute")).thenReturn(Optional.of(descriptor));
CatalogServiceImpl catalogService = new CatalogServiceImpl(framework, attachmentParser, attributeRegistry) {
@Override
protected BundleContext getBundleContext() {
return bundleContext;
}
};
UuidGenerator uuidGenerator = mock(UuidGenerator.class);
when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString());
catalogService.setUuidGenerator(uuidGenerator);
addMatchingService(catalogService, Collections.singletonList(getSimpleTransformer()));
List<Attachment> attachments = new ArrayList<>();
ContentDisposition contentDisposition = new ContentDisposition("form-data; name=parse.resource; filename=C:\\DDF\\metacard.txt");
Attachment attachment = new Attachment("parse.resource", new ByteArrayInputStream("Some Text".getBytes()), contentDisposition);
attachments.add(attachment);
ContentDisposition contentDisposition2 = new ContentDisposition("form-data; name=custom.attribute; ");
Attachment attachment2 = new Attachment(descriptor.getName(), new ByteArrayInputStream("CustomValue".getBytes()), contentDisposition2);
attachments.add(attachment2);
MultipartBody multipartBody = new MultipartBody(attachments);
String response = catalogService.addDocument(headers.getRequestHeader(HttpHeaders.CONTENT_TYPE), multipartBody, null, new ByteArrayInputStream("".getBytes()));
LOGGER.debug(ToStringBuilder.reflectionToString(response));
ArgumentCaptor<CreateStorageRequest> captor = ArgumentCaptor.forClass(CreateStorageRequest.class);
verify(framework, times(1)).create(captor.capture());
assertThat(captor.getValue().getContentItems().get(0).getMetacard().getMetacardType().getAttributeDescriptor(descriptor.getName()), equalTo(descriptor));
}
use of javax.ws.rs.core.HttpHeaders in project ddf by codice.
the class CatalogServiceImplTest method testAddDocumentNullMessage.
@Test
public void testAddDocumentNullMessage() {
CatalogFramework framework = mock(CatalogFramework.class);
CatalogServiceImpl catalogService = new CatalogServiceImpl(framework, attachmentParser, attributeRegistry);
HttpHeaders headers = mock(HttpHeaders.class);
try {
catalogService.addDocument(headers.getRequestHeader(HttpHeaders.CONTENT_TYPE), mock(MultipartBody.class), null, null);
} catch (CatalogServiceException e) {
assertEquals(e.getMessage(), "No content found, cannot do CREATE.");
}
}
use of javax.ws.rs.core.HttpHeaders in project ddf by codice.
the class CatalogServiceImplTest method mcardIdTest.
private String mcardIdTest(Metacard metacard, UuidGenerator uuidGenerator) throws Exception {
CatalogFramework framework = mock(CatalogFramework.class);
when(framework.create(isA(CreateStorageRequest.class))).thenAnswer(args -> {
ContentItem item = ((CreateStorageRequest) args.getArguments()[0]).getContentItems().get(0);
item.getMetacard().setAttribute(new AttributeImpl(Core.ID, item.getId()));
return new CreateResponseImpl(null, new HashMap<>(), Collections.singletonList(item.getMetacard()));
});
HttpHeaders headers = createHeaders(Collections.singletonList(MediaType.APPLICATION_JSON));
BundleContext bundleContext = mock(BundleContext.class);
Collection<ServiceReference<InputTransformer>> serviceReferences = new ArrayList<>();
ServiceReference serviceReference = mock(ServiceReference.class);
InputTransformer inputTransformer = mock(InputTransformer.class);
when(inputTransformer.transform(any())).thenReturn(metacard);
when(bundleContext.getService(serviceReference)).thenReturn(inputTransformer);
serviceReferences.add(serviceReference);
when(bundleContext.getServiceReferences(InputTransformer.class, "(id=xml)")).thenReturn(serviceReferences);
CatalogServiceImpl catalogService = new CatalogServiceImpl(framework, attachmentParser, attributeRegistry) {
@Override
protected BundleContext getBundleContext() {
return bundleContext;
}
};
String generatedMcardId = UUID.randomUUID().toString();
when(uuidGenerator.generateUuid()).thenReturn(generatedMcardId);
catalogService.setUuidGenerator(uuidGenerator);
when(attributeRegistry.lookup(Core.METADATA)).thenReturn(Optional.of(new CoreAttributes().getAttributeDescriptor(Core.METADATA)));
addMatchingService(catalogService, Collections.singletonList(inputTransformer));
List<Attachment> attachments = new ArrayList<>();
ContentDisposition contentDisposition = new ContentDisposition("form-data; name=parse.resource; filename=C:\\DDF\\metacard.txt");
Attachment attachment = new Attachment("parse.resource", new ByteArrayInputStream("Some Text".getBytes()), contentDisposition);
attachments.add(attachment);
ContentDisposition contentDisposition1 = new ContentDisposition("form-data; name=parse.metadata; filename=C:\\DDF\\metacard.xml");
Attachment attachment1 = new Attachment("parse.metadata", new ByteArrayInputStream("Some Text Again".getBytes()), contentDisposition1);
attachments.add(attachment1);
MultipartBody multipartBody = new MultipartBody(attachments);
return catalogService.addDocument(headers.getRequestHeader(HttpHeaders.CONTENT_TYPE), multipartBody, null, new ByteArrayInputStream("".getBytes()));
}
use of javax.ws.rs.core.HttpHeaders in project ddf by codice.
the class CatalogServiceImplTest method createHeaders.
private HttpHeaders createHeaders(List<String> mimeTypeList) {
HttpHeaders headers = mock(HttpHeaders.class);
when(headers.getRequestHeader(HttpHeaders.CONTENT_TYPE)).thenReturn(mimeTypeList);
return headers;
}
Aggregations