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

com.xlrit.gears.plugin.scim.ScimConfig Maven / Gradle / Ivy

There is a newer version: 1.17.6
Show newest version
package com.xlrit.gears.plugin.scim;

import java.util.Collections;
import java.util.Map;
import java.util.stream.Collectors;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.xlrit.gears.base.repository.RoleRepository;
import com.xlrit.gears.base.repository.UserRepository;

import de.captaingoldfish.scim.sdk.common.resources.ServiceProvider;
import de.captaingoldfish.scim.sdk.common.resources.complex.*;
import de.captaingoldfish.scim.sdk.common.resources.multicomplex.AuthenticationScheme;
import de.captaingoldfish.scim.sdk.server.endpoints.ResourceEndpoint;
import de.captaingoldfish.scim.sdk.server.endpoints.base.GroupEndpointDefinition;
import de.captaingoldfish.scim.sdk.server.endpoints.base.UserEndpointDefinition;
import de.captaingoldfish.scim.sdk.server.schemas.ResourceType;
import de.captaingoldfish.scim.sdk.server.schemas.custom.ResourceTypeFeatures;
import lombok.RequiredArgsConstructor;

@Configuration
@RequiredArgsConstructor
public class ScimConfig {

	private final UserRepository users;
	private final RoleRepository roles;
	private final ScimProperties properties;

	@Bean
	public ServiceProvider getServiceProviderConfig() {
		AuthenticationScheme authScheme = AuthenticationScheme.builder()
			.name("Bearer")
			.description("Authentication scheme using the OAuth Bearer Token Standard")
			.specUri("http://www.rfc-editor.org/info/rfc6750")
			.type("oauthbearertoken")
			.build();
		return ServiceProvider.builder()
			.filterConfig(FilterConfig.builder().supported(true).maxResults(50).build())
			.sortConfig(SortConfig.builder().supported(true).build())
			.changePasswordConfig(ChangePasswordConfig.builder().supported(true).build())
			.bulkConfig(BulkConfig.builder().supported(true).maxOperations(10).build())
			.patchConfig(PatchConfig.builder().supported(true).build())
			.authenticationSchemes(Collections.singletonList(authScheme))
			.eTagConfig(ETagConfig.builder().supported(true).build())
			.build();
	}

	@Bean
	public ResourceEndpoint getResourceEndpoint(ServiceProvider serviceProvider) {
		return new ResourceEndpoint(serviceProvider);
	}

	@Bean
	public ResourceType getUserResourceType(ResourceEndpoint resourceEndpoint) {
		UserHandler userHandler = new UserHandler(users);
		ResourceType userResourceType = resourceEndpoint.registerEndpoint(new UserEndpointDefinition(userHandler));
		userResourceType.setFeatures(
			ResourceTypeFeatures.builder()
				.autoFiltering(true)
				.autoSorting(true)
				.build()
		);
		return userResourceType;
	}

	@Bean
	public ResourceType getGroupResourceType(ResourceEndpoint resourceEndpoint) {
		Map roleMapping = properties.getRoleMappings().stream()
			.collect(Collectors.toMap(ScimProperties.RoleMapping::getGroupName, ScimProperties.RoleMapping::getRoleName));

		GroupHandler groupHandler = new GroupHandler(roles, users, roleMapping);
		ResourceType groupResourceType = resourceEndpoint.registerEndpoint(new GroupEndpointDefinition(groupHandler));
		groupResourceType.setFeatures(
			ResourceTypeFeatures.builder()
				.autoFiltering(true)
				.autoSorting(true)
				.build()
		);
		return groupResourceType;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy