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

io.smallrye.jwt.build.impl.JwtProviderImpl Maven / Gradle / Ivy

The newest version!
package io.smallrye.jwt.build.impl;

import java.util.LinkedHashMap;
import java.util.Map;

import jakarta.json.JsonObject;
import jakarta.json.JsonValue;

import org.eclipse.microprofile.jwt.Claims;
import org.eclipse.microprofile.jwt.JsonWebToken;

import io.smallrye.jwt.build.JwtClaimsBuilder;
import io.smallrye.jwt.build.spi.JwtProvider;

/**
 * Default service provider for JWT Claims Builder objects.
 *
 */
public class JwtProviderImpl extends JwtProvider {

    /**
     * {@inheritDoc}
     */
    @Override
    public JwtClaimsBuilder claims() {
        return new JwtClaimsBuilderImpl();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public JwtClaimsBuilder claims(Map claims) {
        return new JwtClaimsBuilderImpl(claims);
    }

    /**
     * {@inheritDoc}
     */
    public JwtClaimsBuilder claims(JsonObject jsonObject) {
        Map claims = new LinkedHashMap<>();
        for (Map.Entry entry : jsonObject.entrySet()) {
            claims.put(entry.getKey(), entry.getValue());
        }
        return claims(claims);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public JwtClaimsBuilder claims(String jsonLocation) {
        return new JwtClaimsBuilderImpl(jsonLocation);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public JwtClaimsBuilder claimsJson(String json) {
        return new JwtClaimsBuilderImpl(JwtBuildUtils.parseJwtContent(json));
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public JwtClaimsBuilder claims(JsonWebToken jwt) {
        Map claims = new LinkedHashMap<>();
        for (String name : jwt.getClaimNames()) {
            if (Claims.raw_token.name().equals(name)) {
                continue;
            }
            claims.put(name, jwt.getClaim(name));
        }
        return claims(claims);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy