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

pl.edu.icm.unity.oauth.as.token.access.ClientAttributesProvider Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2021 Bixbit - Krzysztof Benedyczak. All rights reserved.
 * See LICENCE.txt file for licensing information.
 */

package pl.edu.icm.unity.oauth.as.token.access;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.nimbusds.oauth2.sdk.OAuth2Error;

import pl.edu.icm.unity.base.attribute.AttributeExt;
import pl.edu.icm.unity.base.entity.EntityParam;
import pl.edu.icm.unity.oauth.as.OAuthASProperties;
import pl.edu.icm.unity.oauth.as.OAuthRequestValidator;
import pl.edu.icm.unity.oauth.as.OAuthRequestValidator.OAuthRequestValidatorFactory;
import pl.edu.icm.unity.oauth.as.OAuthSystemAttributesProvider;
import pl.edu.icm.unity.oauth.as.token.BaseOAuthResource;
import pl.edu.icm.unity.oauth.as.token.OAuthErrorException;

class ClientAttributesProvider
{
	private final OAuthRequestValidator requestValidator;

	ClientAttributesProvider(OAuthRequestValidator requestValidator)
	{
		this.requestValidator = requestValidator;
	}

	Map getClientAttributes(EntityParam entity) throws OAuthErrorException
	{
		try
		{
			return requestValidator.getAttributesNoAuthZ(entity);
		} catch (Exception e)
		{
			throw new OAuthErrorException(BaseOAuthResource.makeError(OAuth2Error.SERVER_ERROR, e.getMessage()));
		}
	}

	String getClientName(EntityParam entity) throws OAuthErrorException
	{
		Map attributes = getClientAttributes(entity);
		AttributeExt nameA = attributes.get(OAuthSystemAttributesProvider.CLIENT_NAME);
		if (nameA != null)
			return ((String) nameA.getValues().get(0));
		else
			return null;
	}

	@Component
	static class ClientAttributesProviderFactory
	{
		private final OAuthRequestValidatorFactory requestValidatorFactory;

		@Autowired
		ClientAttributesProviderFactory(OAuthRequestValidatorFactory requestValidatorFactory)
		{
			this.requestValidatorFactory = requestValidatorFactory;
		}

		ClientAttributesProvider getClientAttributeProvider(OAuthASProperties config)
		{
			return new ClientAttributesProvider(requestValidatorFactory.getOAuthRequestValidator(config));

		}

	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy