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

com.vmware.connectors.common.config.JwtConverter Maven / Gradle / Ivy

There is a newer version: 2.9.8
Show newest version
/*
 * Copyright © 2018 VMware, Inc. All Rights Reserved.
 * SPDX-License-Identifier: BSD-2-Clause
 */

package com.vmware.connectors.common.config;

import org.springframework.boot.autoconfigure.security.oauth2.resource.JwtAccessTokenConverterConfigurer;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.UserAuthenticationConverter;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;

import java.util.HashMap;
import java.util.Map;

public class JwtConverter extends DefaultAccessTokenConverter implements
        JwtAccessTokenConverterConfigurer {

    @Override
    public void configure(JwtAccessTokenConverter converter) {
        converter.setAccessTokenConverter(this);
    }

    @Override
    public OAuth2Authentication extractAuthentication(Map map) {
        Map claims = new HashMap<>();
        claims.putAll(map);
        claims.put(UserAuthenticationConverter.USERNAME, map.get("prn"));
        return super.extractAuthentication(claims);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy