Java Code Examples for org.opensaml.xml.security.credential.UsageType#UNSPECIFIED

The following examples show how to use org.opensaml.xml.security.credential.UsageType#UNSPECIFIED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UsageCriteria.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set the key usage criteria.
 * 
 * @param usage The usage to set.
 */
public void setUsage(UsageType usage) {
    if (usage != null) {
        credUsage = usage;
    } else {
        credUsage = UsageType.UNSPECIFIED;
    }
}
 
Example 2
Source File: MetadataCredentialResolver.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
protected Iterable<Credential> resolveFromSource(CriteriaSet criteriaSet) throws SecurityException {

    checkCriteriaRequirements(criteriaSet);

    String entityID = criteriaSet.get(EntityIDCriteria.class).getEntityID();
    MetadataCriteria mdCriteria = criteriaSet.get(MetadataCriteria.class);
    QName role = mdCriteria.getRole();
    String protocol = mdCriteria.getProtocol();
    UsageCriteria usageCriteria = criteriaSet.get(UsageCriteria.class);
    UsageType usage = null;
    if (usageCriteria != null) {
        usage = usageCriteria.getUsage();
    } else {
        usage = UsageType.UNSPECIFIED;
    }
    
    // See Jira issue SIDP-229.
    log.debug("Forcing on-demand metadata provider refresh if necessary");
    try {
        metadata.getMetadata();
    } catch (MetadataProviderException e) {
        // don't care about errors at this level
    }

    MetadataCacheKey cacheKey = new MetadataCacheKey(entityID, role, protocol, usage);
    Collection<Credential> credentials = retrieveFromCache(cacheKey);

    if (credentials == null) {
        credentials = retrieveFromMetadata(entityID, role, protocol, usage);
        cacheCredentials(cacheKey, credentials);
    }

    return credentials;
}
 
Example 3
Source File: MetadataCredentialResolver.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Retrieves credentials from the provided metadata.
 * 
 * @param entityID entityID of the credential owner
 * @param role role in which the entity is operating
 * @param protocol protocol over which the entity is operating (may be null)
 * @param usage intended usage of resolved credentials
 * 
 * @return the resolved credentials or null
 * 
 * @throws SecurityException thrown if the key, certificate, or CRL information is represented in an unsupported
 *             format
 */
protected Collection<Credential> retrieveFromMetadata(String entityID, QName role, String protocol, UsageType usage)
        throws SecurityException {

    log.debug("Attempting to retrieve credentials from metadata for entity: {}", entityID);
    Collection<Credential> credentials = new HashSet<Credential>(3);

    List<RoleDescriptor> roleDescriptors = getRoleDescriptors(entityID, role, protocol);
    if(roleDescriptors == null || roleDescriptors.isEmpty()){
        return credentials;
    }
        
    for (RoleDescriptor roleDescriptor : roleDescriptors) {
        List<KeyDescriptor> keyDescriptors = roleDescriptor.getKeyDescriptors();
        if(keyDescriptors == null || keyDescriptors.isEmpty()){
            return credentials;
        }            
        for (KeyDescriptor keyDescriptor : keyDescriptors) {
            UsageType mdUsage = keyDescriptor.getUse();
            if (mdUsage == null) {
                mdUsage = UsageType.UNSPECIFIED;
            }
            if (matchUsage(mdUsage, usage)) {
                if (keyDescriptor.getKeyInfo() != null) {
                    CriteriaSet critSet = new CriteriaSet();
                    critSet.add(new KeyInfoCriteria(keyDescriptor.getKeyInfo()));

                    Iterable<Credential> creds = getKeyInfoCredentialResolver().resolve(critSet);
                    if(credentials == null){
                        continue;
                    }
                    for (Credential cred : creds) {
                        if (cred instanceof BasicCredential) {
                            BasicCredential basicCred = (BasicCredential) cred;
                            basicCred.setEntityId(entityID);
                            basicCred.setUsageType(mdUsage);
                            basicCred.getCredentalContextSet().add(new SAMLMDCredentialContext(keyDescriptor));
                        }
                        credentials.add(cred);
                    }
                }
            }
        }

    }

    return credentials;
}
 
Example 4
Source File: EvaluableUsageCredentialCriteria.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Match usage enum type values from credential and criteria.
 * 
 * @param credentialUsage the usage value from the credential
 * @param criteriaUsage the usage value from the criteria
 * @return true if the two usage specifiers match for purposes of resolving credentials, false otherwise
 */
protected boolean matchUsage(UsageType credentialUsage, UsageType criteriaUsage) {
    if (credentialUsage == UsageType.UNSPECIFIED || criteriaUsage == UsageType.UNSPECIFIED) {
        return true;
    }
    return credentialUsage == criteriaUsage;
}
 
Example 5
Source File: MetadataCredentialResolver.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Match usage enum type values from metadata KeyDescriptor and from credential criteria.
 * 
 * @param metadataUsage the value from the 'use' attribute of a metadata KeyDescriptor element
 * @param criteriaUsage the value from credential criteria
 * @return true if the two usage specifiers match for purposes of resolving credentials, false otherwise
 */
protected boolean matchUsage(UsageType metadataUsage, UsageType criteriaUsage) {
    if (metadataUsage == UsageType.UNSPECIFIED || criteriaUsage == UsageType.UNSPECIFIED) {
        return true;
    }
    return metadataUsage == criteriaUsage;
}
 
Example 6
Source File: KeyDescriptorImpl.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructor.
 * 
 * @param namespaceURI the namespace the element is in
 * @param elementLocalName the local name of the XML element this Object represents
 * @param namespacePrefix the prefix for the given namespace
 */
protected KeyDescriptorImpl(String namespaceURI, String elementLocalName, String namespacePrefix) {
    super(namespaceURI, elementLocalName, namespacePrefix);
    encryptionMethods = new XMLObjectChildrenList<EncryptionMethod>(this);
    keyUseType = UsageType.UNSPECIFIED;
}