JAX-RS Security

Provide an authorization filter that uses Authorization HTTP header to set JAX-RS API security context.

Лицензия

Лицензия

Категории

Категории

Безопасность
Группа

Группа

com.bekioui.jaxrs
Идентификатор

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

jaxrs-security
Последняя версия

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

1.1.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

JAX-RS Security
Provide an authorization filter that uses Authorization HTTP header to set JAX-RS API security context.
Ссылка на сайт

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

https://github.com/MehdiBekioui/jaxrs-security
Система контроля версий

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

https://github.com/MehdiBekioui/jaxrs-security

Скачать jaxrs-security

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

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

Зависимости

compile (6)

Идентификатор библиотеки Тип Версия
org.springframework : spring-context jar 4.2.5.RELEASE
org.jboss.resteasy : resteasy-jaxrs jar 3.0.16.Final
org.jboss.resteasy : resteasy-jackson2-provider jar 3.0.16.Final
com.auth0 : java-jwt jar 2.1.0
com.excilys.ebi.utils : spring-log jar 1.0.4
ch.qos.logback : logback-classic jar 1.1.3

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

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

Jaxrs Security

Jaxrs Security provides an authorization filter that uses Authorization HTTP header to set JAX-RS API security context. It allows you to use Javax security annotations in your resources.

This library use JWT for securely transmitting information between parties encoded as a JSON object.

You can do a single sign-on (SSO) authentication by choosing the multiple application token type.

Get it

Add the following to your Maven configuration:

<dependency>
	<groupId>com.bekioui.jaxrs</groupId>
	<artifactId>jaxrs-security</artifactId>
	<version>1.1.0</version>
</dependency>

Use it

Import the JaxrsSecurityConfig class in your Spring configuration file:

@Configuration
@Import({ JaxrsSecurityConfig.class })
public class SpringConfig {
  
}

Configure it

You need to define a secret to encode and decode tokens on the server. In case you have a multiple application context, you need to define the same secret for all your applications.

Single application context

Token has an identifier that represents the user and a list of roles on the application.

{
  "identifier":"solid",
  "roles":["USER"]
}

Add the following to your Spring configuration file:

@Bean
public ApplicationTokenDescriptor getTokenDescriptor() {
	return ApplicationTokenDescriptor.getSingleApplicationTokenDescriptor(secret);
}

Multiple application context

Token has an identifier that represents the user and a map of roles which contains a list of roles for each application defined by its package name.

{
  "identifier":"solid",
  "roles":{
    "com.bekioui.app1":["USER"],
    "com.bekioui.app2":["ADMIN"],
  }
}

Each application from your microservices architecture has to add the following to its Spring configuration file:

@Bean
public ApplicationTokenDescriptor getTokenDescriptor() {
	return ApplicationTokenDescriptor.getMultipleApplicationTokenDescriptor("com.bekioui.app", secret);
}

Don't forget to use the same secret for all your applications.

Resources

Now you can add, for example, RolesAllowed annotation to specify which roles are allowed to access to your resource.

@Path("/users")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public interface UserResource {

    @GET
    @RolesAllowed("USER")
    List<String> findAllLogins();
    
}

License

Copyright (C) 2016 Mehdi Bekioui (consulting@bekioui.com)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.		

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

Версия
1.1.0
1.0.0