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

org.rootservices.jwt.jws.serialization.SecureJwtSerializer Maven / Gradle / Ivy

There is a newer version: 1.3.1
Show newest version
package org.rootservices.jwt.jws.serialization;


import org.rootservices.jwt.entity.jwt.Claims;
import org.rootservices.jwt.entity.jwt.JsonWebToken;
import org.rootservices.jwt.factory.SecureJwtFactory;
import org.rootservices.jwt.serialization.JwtSerde;
import org.rootservices.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(Claims 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