identity

The jersey identity module

License

License

Categories

Categories

IDE Development Tools
GroupId

GroupId

me.tzion
ArtifactId

ArtifactId

identity
Last Version

Last Version

0.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

identity
The jersey identity module
Project URL

Project URL

https://github.com/tsiyyon/identity
Source Code Management

Source Code Management

https://github.com/tsiyyon/identity

Download identity

How to add to project

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

Dependencies

compile (3)

Group / Artifact Type Version
javax.ws.rs : javax.ws.rs-api jar 2.0.1
com.google.inject : guice jar 3.0
org.glassfish.jersey.core : jersey-server jar 2.17

test (5)

Group / Artifact Type Version
junit : junit jar 4.12
org.hamcrest : hamcrest-all jar 1.3
org.mockito : mockito-all jar 1.9.5
org.glassfish.jersey.test-framework : jersey-test-framework-core jar 2.17
org.glassfish.jersey.test-framework.providers : jersey-test-framework-provider-grizzly2 jar 2.17

Project Modules

There are no modules declared in this project.

The jersey identity module

config

    resourceConfig.register(new IdentityFeature(
            new IdentityFilter(
                    context -> Optional.ofNullable(context.getHeaderString(HttpHeaders.AUTHORIZATION)),
                    identifiable -> {
                        if (Objects.equals(identifiable, "token_for_kayla")) {
                            return Optional.of(new User("kayla"));
                        }
                        return Optional.empty();
                    },
                    (context) -> Response.status(401).build()
            )));

    resourceConfig.register(new IdentityValueFactoryProvider.Binder<>(User.class));

usage as following

@Path("/")
public class Resources {
    @GET
    @Path("required")
    public Response required(
            @Current User user) {
        return Response.ok().build();
    }

    @GET
    @Path("optional")
    public Response optional(
            @Current Optional<User> user) {
        return user.map(u -> Response.ok(u.getName()).build())
                .orElse(Response.ok("anonymous").build());
    }

    @GET
    @Path("opened")
    public Response opened() {
        return Response.status(200).build();
    }
  1. First get need the user be authenticated. if not exception will throwed
  2. Second get user can be authenticated or anonymous user.
  3. The second get is opened to all the user

Versions

Version
0.0.1