Java 11 – ChaCha20-Poly1305 encryption examples

This article shows you how to encrypt and decrypt a message with the ChaCha20-Poly1305 algorithm, defined in RFC 7539. P.S The ChaCha20-Poly1305 encryption algorithm is available at Java 11. 1. FAQs Some commonly asked questions: 1.1 What is ChaCha20-Poly1305? ChaCha20-Poly1305 means the ChaCha20 (encryption and decryption algorithm) running in AEAD mode with the Poly1305 authenticator. …

Read more

OkHttp – How to send HTTP requests

This article shows you how to use the OkHttp library to send an HTTP GET/POST requests and some frequent used examples. P.S Tested with OkHttp 4.2.2 pom.xml <dependency> <groupId>com.squareup.okhttp3</groupId> <artifactId>okhttp</artifactId> <version>4.2.2</version> </dependency> 1. Synchronous Get Request OkHttpExample1.java package com.mkyong.http; import okhttp3.Headers; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; import java.io.IOException; public class OkHttpExample1 { // only …

Read more

Apache HttpClient Basic Authentication Examples

This article shows you how to use Apache HttpClient to perform an HTTP basic authentication. P.S Tested with HttpClient 4.5.10 pom.xml <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.10</version> </dependency> Start a simple Spring Security WebApp providing HTTP basic authentication, and test it with the HttpClient 1. Basic Authentication The key is to configure CredentialsProvider and pass it to …

Read more

MongoDB Authentication example

This guide shows you how to enable authentication in MongoDB. The authentication is disabled by default. To configure it, you must first add a user to the “admin” database. > show dbs admin #add single user to this database testdb Note Users with normal access in “admin” database, HAVE read and write access to all …

Read more

Spring Security HTTP basic authentication example

When HTTP basic authentication is configured, web browser will display a login dialog for user authentication. This tutorial show you how to configure HTTP basic authentication in Spring Security. <http> <intercept-url pattern="/welcome*" access="ROLE_USER" /> <http-basic /> </http> Last Spring Security form-based login example will be reused, but switch authentication to support HTTP basic. 1. Spring …

Read more

Java MongoDB : Authentication example

By default, MongoDB is run in trust environment (authentication with a username and password is NOT required). In this tutorial, we will show you how to start MongoDB in secure mode / enable authentication, and connect with the Java MongoDB driver. 1. Start MongoDB in Secure Mode Start MongoDB with –auth option, now, MongoDB need …

Read more

Container Authentication with JAX-WS – (Tomcat version)

In this article, we show you how to implement container authentication with JAX-WS, under Tomcat 6.0. In this way, the authentication is declarative rather than programmatic like this – application authentication in JAX-WS. And Tomcat implement the container authentication via security realm. At the end of this article, the deployed web service will authenticate user …

Read more

Application Authentication with JAX-WS

One of the common way to handle authentication in JAX-WS is client provides “username” and “password”, attached it in SOAP request header and send to server, server parse the SOAP document and retrieve the provided “username” and “password” from request header and do validation from database, or whatever method prefer. In this article, we show …

Read more