All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.tokensmith.jwt.jws.serialization.SecureJwtSerializer Maven / Gradle / Ivy

There is a newer version: 1.3.4
Show newest version
package net.tokensmith.jwt.jws.serialization;


import net.tokensmith.jwt.entity.jwt.Claims;
import net.tokensmith.jwt.entity.jwt.JsonWebToken;
import net.tokensmith.jwt.factory.SecureJwtFactory;
import net.tokensmith.jwt.serialization.JwtSerde;
import net.tokensmith.jwt.serialization.exception.JwtToJsonException;

import java.io.ByteArrayOutputStream;


public class SecureJwtSerializer {
    private SecureJwtFactory secureJwtFactory;
    private JwtSerde jwtSerde;

    public SecureJwtSerializer(SecureJwtFactory secureJwtFactory, JwtSerde jwtSerde) {
        this.secureJwtFactory = secureJwtFactory;
        this.jwtSerde = jwtSerde;
    }

    public String compactJwtToString(Claims claims) throws JwtToJsonException {
        return compactJwt(claims).toString();
    }

    public  ByteArrayOutputStream compactJwt(T claims) throws JwtToJsonException {
        JsonWebToken jsonWebToken;
        try {
            jsonWebToken = secureJwtFactory.makeJwt(claims);
        } catch (JwtToJsonException e) {
            throw e;
        }

        ByteArrayOutputStream compactJwt;
        try {
            compactJwt = jwtSerde.compactJwt(jsonWebToken);
        } catch (JwtToJsonException e) {
            throw e;
        }

        return compactJwt;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy