Package org.opensaml.saml.metadata.support

# Class AttributeConsumingServiceSelector

java.lang.Object
org.opensaml.saml.metadata.support.AttributeConsumingServiceSelector

public class AttributeConsumingServiceSelector extends Object
Metadata support class which selects an `AttributeConsumingService` based on input of a mandatory `RoleDescriptor` and an optional index.

This implementation supports selecting an AttributeConsumingService from parent role descriptors of the following types:

1. the standard SAML 2 metadata type `SPSSODescriptor`
2. the extension type `AttributeQueryDescriptorType`

Subclasses should override `getCandidates()` if support for additional sources of attribute consuming services is needed.

The selection algorithm is:

1. If an index is supplied, the service with that index is returned. If no such service exists in metadata: if `isOnBadIndexUseDefault()` is true, then the default service is returned as described below; otherwise null is returned.
2. If an index is not supplied, then the default service is returned as follows: The service with an explicit isDefault of true is returned. If no such service exists, then the first service without an explicit isDefault is returned. If no service is yet selected, then the first service listed in metadata is returned.

## Field Summary

Fields
Modifier and Type
Field
Description
`private Integer`
`index`
The requested service index.
`private org.slf4j.Logger`
`log`
Class logger.
`private boolean`
`onBadIndexUseDefault`
Flag which determines whether, in the case of an invalid index, to return the default AttributeConsumingService.
`private RoleDescriptor`
`roleDescriptor`
The AttributeConsumingService's parent role descriptor.

## Constructor Summary

Constructors
Constructor
Description
`AttributeConsumingServiceSelector()`

## Method Summary

Modifier and Type
Method
Description
`protected List<AttributeConsumingService>`
`getCandidates()`
Get the list of candidate attribute consuming services.
`Integer`
`getIndex()`
Get the index of the desired service.
`RoleDescriptor`
`getRoleDescriptor()`
Get the AttributeConsumingServie's parent RoleDescriptor.
`boolean`
`isOnBadIndexUseDefault()`
Get the flag which determines whether, in the case of an invalid index, to return the default AttributeConsumingService.
`private AttributeConsumingService`
`selectByIndex(List<AttributeConsumingService> candidates)`
Select the service based on the index value.
`private AttributeConsumingService`
`selectDefault(List<AttributeConsumingService> candidates)`
Select the default service.
`AttributeConsumingService`
`selectService()`
Select the AttributeConsumingService.
`void`
`setIndex(Integer requestedIndex)`
Set the index of the desired service.
`void`
`setOnBadIndexUseDefault(boolean flag)`
Set the flag which determines whether, in the case of an invalid index, to return the default AttributeConsumingService.
`void`
`setRoleDescriptor(RoleDescriptor descriptor)`
Set the AttributeConsumingServie's parent RoleDescriptor.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### log

@Nonnull private org.slf4j.Logger log
Class logger.

### index

@Nullable private Integer index
The requested service index.

### roleDescriptor

@Nullable private RoleDescriptor roleDescriptor
The AttributeConsumingService's parent role descriptor.

### onBadIndexUseDefault

private boolean onBadIndexUseDefault
Flag which determines whether, in the case of an invalid index, to return the default AttributeConsumingService.

## Constructor Details

### AttributeConsumingServiceSelector

public AttributeConsumingServiceSelector()

## Method Details

### getIndex

@Nullable public Integer getIndex()
Get the index of the desired service.

Returns:
  Returns the index.

### setIndex

public void setIndex(@Nullable Integer requestedIndex)
Set the index of the desired service.

Parameters:
  `requestedIndex` - The index to set.

### getRoleDescriptor

@Nullable public RoleDescriptor getRoleDescriptor()
Get the AttributeConsumingServie's parent RoleDescriptor.

Returns:
  Returns the spSSODescriptor.

### setRoleDescriptor

public void setRoleDescriptor(@Nullable RoleDescriptor descriptor)
Set the AttributeConsumingServie's parent RoleDescriptor.

Parameters:
  `descriptor` - The roleDescriptor to set.

### setOnBadIndexUseDefault

public void setOnBadIndexUseDefault(boolean flag)
Set the flag which determines whether, in the case of an invalid index, to return the default AttributeConsumingService. Defaults to false.

Parameters:
  `flag` - The onBadIndexUseDefault to set.

### isOnBadIndexUseDefault

public boolean isOnBadIndexUseDefault()
Get the flag which determines whether, in the case of an invalid index, to return the default AttributeConsumingService. Defaults to false.

Returns:
  Returns the onBadIndexUseDefault.

### selectService

@Nullable public AttributeConsumingService selectService()
Select the AttributeConsumingService.

Returns:
  the selected AttributeConsumingService, or null

### getCandidates

@Nullable @Unmodifiable @NotLive protected List<AttributeConsumingService> getCandidates()
Get the list of candidate attribute consuming services.

This implementation supports selecting an AttributeConsumingService from parent role descriptors of the following types:

1. the standard SAML 2 metadata type `SPSSODescriptor`
2. the extension type `AttributeQueryDescriptorType`

Subclasses should override if support for additional sources of attribute consuming services is needed.

Returns:
  the list of candidate AttributeConsumingServices, or null if none could be resolved

### selectByIndex

@Nullable private AttributeConsumingService selectByIndex(List<AttributeConsumingService> candidates)
Select the service based on the index value.

Parameters:
  `candidates` - the list of candiate services
Returns:
  the selected candidate or null

### selectDefault

@Nonnull private AttributeConsumingService selectDefault(List<AttributeConsumingService> candidates)
Select the default service.

Parameters:
  `candidates` - the list of candiate services
Returns:
  the selected candidate or null