identity

The jersey identity module

Лицензия

Лицензия

Категории

Категории

IDE Инструменты разработки
Группа

Группа

me.tzion
Идентификатор

Идентификатор

identity
Последняя версия

Последняя версия

0.0.1
Дата

Дата

Тип

Тип

jar
Описание

Описание

identity
The jersey identity module
Ссылка на сайт

Ссылка на сайт

https://github.com/tsiyyon/identity
Система контроля версий

Система контроля версий

https://github.com/tsiyyon/identity

Скачать identity

Как подключить последнюю версию

<!-- 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"]

Зависимости

compile (3)

Идентификатор библиотеки Тип Версия
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)

Идентификатор библиотеки Тип Версия
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

Модули Проекта

Данный проект не имеет модулей.

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

Версии библиотеки

Версия
0.0.1