test_class.file: adapters/saml/core/src/test/java/org/keycloak/adapters/saml/PropertiesBasedRoleMapperTest.java
test_class.identifier: PropertiesBasedRoleMapperTest
test_case.body: @Test
      public void testPropertiesBasedRoleMapper() throws Exception {
          InputStream is = getClass().getResourceAsStream("config/parsers/keycloak-saml-with-role-mappings-provider.xml");
          SamlDeployment deployment = new DeploymentBuilder().build(is, new ResourceLoader() {
              @Override
              public InputStream getResourceAsStream(String resource) {
                  return this.getClass().getClassLoader().getResourceAsStream(resource);
              }
          });
          // retrieve the configured role mappings provider - in this case we know it is the properties-based implementation.
          RoleMappingsProvider provider = deployment.getRoleMappingsProvider();
  
          // if provider was properly configured we should be able to see the mappings as specified in the properties file.
          final Set<String> samlRoles = new HashSet<>(Arrays.asList(new String[]{"samlRoleA", "samlRoleB", "samlRoleC"}));
          final Set<String> mappedRoles = provider.map("kc-user", samlRoles);
  
          // we expect samlRoleB to be removed, samlRoleA to be mapped into two roles (jeeRoleX, jeeRoleY) and also the principal should
          // be granted an extra role (jeeRoleZ).
          assertNotNull(mappedRoles);
          assertEquals(4, mappedRoles.size());
          Set<String> expectedRoles = new HashSet<>(Arrays.asList(new String[]{"samlRoleC", "jeeRoleX", "jeeRoleY", "jeeRoleZ"}));
          assertEquals(expectedRoles, mappedRoles);
      }
test_case.class_method_signature: PropertiesBasedRoleMapperTest.testPropertiesBasedRoleMapper()
test_case.full_signature: @Test public void testPropertiesBasedRoleMapper()
test_case.identifier: testPropertiesBasedRoleMapper
test_case.invocations: getResourceAsStream getClass build getResourceAsStream getClassLoader getClass getRoleMappingsProvider asList map assertNotNull assertEquals size asList assertEquals
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testPropertiesBasedRoleMapper()
focal_class.declarator: logger = Logger.getLogger(PropertiesBasedRoleMapper.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger logger = Logger.getLogger(PropertiesBasedRoleMapper.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.declarator: PROVIDER_ID = "properties-based-role-mapper"
focal_class.modifier: public static final
focal_class.original_string: public static final String PROVIDER_ID = "properties-based-role-mapper";
focal_class.type: String
focal_class.var_name: PROVIDER_ID
focal_class.declarator: PROPERTIES_FILE_LOCATION = "properties.file.location"
focal_class.modifier: private static final
focal_class.original_string: private static final String PROPERTIES_FILE_LOCATION = "properties.file.location";
focal_class.type: String
focal_class.var_name: PROPERTIES_FILE_LOCATION
focal_class.declarator: PROPERTIES_RESOURCE_LOCATION = "properties.resource.location"
focal_class.modifier: private static final
focal_class.original_string: private static final String PROPERTIES_RESOURCE_LOCATION = "properties.resource.location";
focal_class.type: String
focal_class.var_name: PROPERTIES_RESOURCE_LOCATION
focal_class.declarator: DEFAULT_RESOURCE_LOCATION = "/WEB-INF/role-mappings.properties"
focal_class.modifier: private static final
focal_class.original_string: private static final String DEFAULT_RESOURCE_LOCATION = "/WEB-INF/role-mappings.properties";
focal_class.type: String
focal_class.var_name: DEFAULT_RESOURCE_LOCATION
focal_class.declarator: roleMappings
focal_class.modifier: private
focal_class.original_string: private Properties roleMappings;
focal_class.type: Properties
focal_class.var_name: roleMappings
focal_class.file: adapters/saml/core/src/main/java/org/keycloak/adapters/saml/PropertiesBasedRoleMapper.java
focal_class.identifier: PropertiesBasedRoleMapper
focal_class.interfaces: implements RoleMappingsProvider
focal_class.class_method_signature: PropertiesBasedRoleMapper.getId()
focal_class.full_signature: @Override public String getId()
focal_class.identifier: getId
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String getId()
focal_class.class_method_signature: PropertiesBasedRoleMapper.init(final SamlDeployment deployment, final ResourceLoader loader, final Properties config)
focal_class.full_signature: @Override public void init(final SamlDeployment deployment, final ResourceLoader loader, final Properties config)
focal_class.identifier: init
focal_class.modifiers: @Override public
focal_class.parameters: (final SamlDeployment deployment, final ResourceLoader loader, final Properties config)
focal_class.return: void
focal_class.signature: void init(final SamlDeployment deployment, final ResourceLoader loader, final Properties config)
focal_class.class_method_signature: PropertiesBasedRoleMapper.map(final String principalName, final Set<String> roles)
focal_class.full_signature: @Override public Set<String> map(final String principalName, final Set<String> roles)
focal_class.identifier: map
focal_class.modifiers: @Override public
focal_class.parameters: (final String principalName, final Set<String> roles)
focal_class.return: Set<String>
focal_class.signature: Set<String> map(final String principalName, final Set<String> roles)
focal_class.class_method_signature: PropertiesBasedRoleMapper.extractRolesIntoSet(final String entry, final Set<String> roles)
focal_class.full_signature: private void extractRolesIntoSet(final String entry, final Set<String> roles)
focal_class.identifier: extractRolesIntoSet
focal_class.modifiers: private
focal_class.parameters: (final String entry, final Set<String> roles)
focal_class.return: void
focal_class.signature: void extractRolesIntoSet(final String entry, final Set<String> roles)
focal_method.body: @Override
      public Set<String> map(final String principalName, final Set<String> roles) {
          if (this.roleMappings == null || this.roleMappings.isEmpty())
              return roles;
  
          Set<String> resolvedRoles = new HashSet<>();
          // first check if we have role -> role(s) mappings.
          for (String role : roles) {
              if (this.roleMappings.containsKey(role)) {
                  // role that was mapped to empty string is not considered (it is discarded from the set of specified roles).
                  this.extractRolesIntoSet(role, resolvedRoles);
              } else {
                  // no mapping found for role - add it as is.
                  resolvedRoles.add(role);
              }
          }
  
          // now check if we have a principal -> role(s) mapping with additional roles to be added.
          if (this.roleMappings.containsKey(principalName)) {
              this.extractRolesIntoSet(principalName, resolvedRoles);
          }
          return resolvedRoles;
      }
focal_method.class_method_signature: PropertiesBasedRoleMapper.map(final String principalName, final Set<String> roles)
focal_method.full_signature: @Override public Set<String> map(final String principalName, final Set<String> roles)
focal_method.identifier: map
focal_method.invocations: isEmpty containsKey extractRolesIntoSet add containsKey extractRolesIntoSet
focal_method.modifiers: @Override public
focal_method.parameters: (final String principalName, final Set<String> roles)
focal_method.return: Set<String>
focal_method.signature: Set<String> map(final String principalName, final Set<String> roles)