Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

En esta guía vamos explicar como se desarrollan plugins que pueda utilizar un módulo de plataforma con un ejemplo concreto.

...

In this guide we are going to explain how to develop plugins that a platform module can use, with a concrete example.

Info

This functionality is only available in the Enterprise version of the Platform, starting with version 1.6.2-empire.

...

Development of a token enhancer

...

for Identity Manager

Supongamos que queremos personalizar la forma en la que se construye el token JWT que nos proporciona el Identity Manager de Plataforma Say you want to customize the way in which the JWT token provided by the Platform Identity Manager (oauth-server) is constructed.

Creación de proyecto maven

...

Maven project creation

To do this, create a new Maven project on which you will develop the proposed functionality.

...

Para que el plugin sea 100% compatible con los módulos de plataforma, es necesario usar la For the plugin to be 100% compatible with platform modules, it is necessary to use Spring Boot version 1.5.9.RELEASE de Spring Boot, y la , and Java version 1.8 de java.

...

...

Lo primero desarrollamos nuestro TokenEnhancer, simplemente vamos a añadir una propiedad al token JWT:

...

Para que el servidor de Autorización utilice este enhancer, tenemos que hacer una clase de configuración que extienda de AuthorizationServerConfigurerAdapter. En esta clase, haremos un override del método que configura los endpoints del servidor.

En dicho método, añadiremos nuestro PluginTokenEnhancer a la cadena de enhancing existente:

Image Removed

De esta forma, se aplicará nuestro enhancer al final de la cadena, antes de devolvernos el token JWT.

Generar el JAR

JAR ligero

Siempre que NO utilicemos librerías externas a las que trae spring-boot usaremos este método.

Para poder utilizar el plugin, tendremos que empaquetar el proyecto maven en un JAR, bien con un mvn clean install o con mvn clean package

Una vez generado el JAR, deberemos subirlo a un servidor accesible desde internet, o al menos desde la máquina donde está instalada la plataforma.

...

Developing functionality

First you must develop your TokenEnhancer. You are simply going to add a property to the JWT token:

...

For the Authorization server to use this enhancer, you have to make a configuration class that extends AuthorizationServerConfigurerAdapter. In this class, override the method that configures the server endpoints.

In that method, add your PluginTokenEnhancer to the existing enhancement chain:

Image Added

This way, your enhancer will be applied at the end of the chain, before returning the JWT token.

Generate the JAR

Lightweight JAR

As long as you do NOT use external libraries that spring-boot brings, you must use this method.

In order to use the plugin, you have to package the maven project in a JAR, either with a mvn clean install or with mvn clean package.

Once the JAR is generated, you must upload it to a server accessible from the Internet, or at least from the machine where the platform is installed.

This can be from a nexus, where you will copy the link to the jar:

https://nexus.onesaitplatform.com/nexus/service/local/repositories/releases/content/com/minsait/onesait/platform/onesaitplatform-base-plugin/1.0.0/onesaitplatform-base-plugin-1.0.0.jar

Hasta el propio repositorio de binarios de la plataformaTo the platform's own binary repository:

...

Nótese que el JAR tiene que ser público sea cual sea la fuente, ya que el módulo de plataforma tiene que tener acceso sin ningún tipo de autenticaciónNotice that the JAR must be public regardless of the source, since the platform module has to have access without any type of authentication.

https://development.onesaitplatform.com/controlpanel/files/5e71fb0e7ec58a000bf6f966

FAT JAR

Siempre que SÍ utilicemos librerías externas a las que trae spring-boot usaremos este método.

El proceso será parecido al anterior, pero tendremos que añadir un plugin de maven al Whenever you DO use external libraries that spring-boot brings, you must use this method.

The process will be similar to the previous one, but you will have to add a maven plugin to the pom.xml:

Code Block
<build>
	<plugins>
		<plugin>
			<artifactId>maven-assembly-plugin</artifactId>
			<configuration>
				<descriptorRefs>
					<descriptorRef>jar-with-dependencies</descriptorRef>
				</descriptorRefs>
			</configuration>
			<executions>
				<execution>
					<id>make-assembly</id> 
					<phase>package</phase> 
					<goals>
						<goal>single</goal>
					</goals>
				</execution>
			</executions>
		</plugin>
	</plugins>
</build>

Para generar el plugin, utilizaremos el comando mvn package

Hay que tener en cuenta que esto generará un JAR con todas las dependencias, y por tanto aumentará considerablemente el tamaño del plugin.

Indicar al módulo Oauth Server la URI del plugin(s)

Deberemos indicar la URI del plugin o plugins en la variable de entorno PLUGIN_URI. Si es el último caso, deberemos separar las URIs por To generate the plugin, you will use the mvn package command.

Bear in mind that this will generate a JAR with all the dependencies, and therefore will considerably increase the size of the plugin.

Indicate the URI of the plugin(s) to the OAuth Server module

We must indicate the URI of the plugin or plugins in the PLUGIN_URI environment variable. If it is the latter case, you must separate the URIs by ';'

...

De esta forma, el Oauth Server al iniciarse, buscará los plugins y los cargaráIn this way, the OAuth Server, when started, will search for the plugins and load them:

...

...

JWT token generation test

Now generate the JWT token with the plugin loaded, to verify that the functionality added to the OAuth enhancement chain is being used:

...

Resources

View file
nameplugin-onesait-im.zip

...