Basic Authentication Filter

Servlet filter for basic authentication. Useful for developing REST services without servlet-engine integration like Spring Boot

License

License

GroupId

GroupId

io.github.jdlopez
ArtifactId

ArtifactId

basicauthfilter
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

Basic Authentication Filter
Servlet filter for basic authentication. Useful for developing REST services without servlet-engine integration like Spring Boot
Project URL

Project URL

https://github.com/jdlopez/basicauthfilter
Source Code Management

Source Code Management

https://github.com/jdlopez/basicauthfilter.git

Download basicauthfilter

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.jdlopez/basicauthfilter/ -->
<dependency>
    <groupId>io.github.jdlopez</groupId>
    <artifactId>basicauthfilter</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.jdlopez/basicauthfilter/
implementation 'io.github.jdlopez:basicauthfilter:1.0.0'
// https://jarcasting.com/artifacts/io.github.jdlopez/basicauthfilter/
implementation ("io.github.jdlopez:basicauthfilter:1.0.0")
'io.github.jdlopez:basicauthfilter:jar:1.0.0'
<dependency org="io.github.jdlopez" name="basicauthfilter" rev="1.0.0">
  <artifact name="basicauthfilter" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.jdlopez', module='basicauthfilter', version='1.0.0')
)
libraryDependencies += "io.github.jdlopez" % "basicauthfilter" % "1.0.0"
[io.github.jdlopez/basicauthfilter "1.0.0"]

Dependencies

provided (1)

Group / Artifact Type Version
javax.servlet : javax.servlet-api jar 3.1.0

test (2)

Group / Artifact Type Version
junit : junit jar 4.13
org.mockito : mockito-core jar 3.2.4

Project Modules

There are no modules declared in this project.

Basic Authentication Filter for Java-Servlet

Very basic authentication filter. Suitable for Spring Boot REST services without servlet-engine configuration.

Configuration

Filter parameters could provide credentials repository

  • realm: Realm display name
  • credentialsFile: Credentials file, a properties file with user=pass. Could be external file or resource file. Checked in that order
  • one user-password: Use user and password parameters

No encription at all. Use with caution.

Usage

Add dependency to maven pom.xml:

<dependency>
    <groupId>io.github.jdlopez</groupId>
    <artifactId>basicauthfilter</artifactId>
    <version>1.0.0</version>
</dependency>

Add servlet filter and configure it. This is a spring-boot sample:

@Bean
public FilterRegistrationBean<es.jdl.web.BasicAuthenticationFilter> authFilter() {
    FilterRegistrationBean<es.jdl.web.BasicAuthenticationFilter> registrationBean
            = new FilterRegistrationBean<>();

    registrationBean.setFilter(new es.jdl.web.BasicAuthenticationFilter());
    registrationBean.addInitParameter("realm", "myapp");
    registrationBean.addInitParameter("user", "sampleuser");
    registrationBean.addInitParameter("password", "easypassword");
    registrationBean.addUrlPatterns("/rest/*");

    return registrationBean;
}

Aditional documentation

Basic Authentication specification: https://tools.ietf.org/html/rfc7617

Based in code found at: https://gist.github.com/neolitec/8953607

Tested using mockito:

Deploy to repository

mvn clean deploy -e -P ossrh

Versions

Version
1.0.0