/** * Checks that use attribute has only one of allowed values. * * @param keyDescriptor the key descriptor to validate * @throws ValidationException throw in use attribute does not have a legal value */ protected void validateUse(KeyDescriptor keyDescriptor) throws ValidationException { UsageType use = keyDescriptor.getUse(); if (use == null) { return; } if ( ! use.equals(UsageType.SIGNING) && ! use.equals(UsageType.ENCRYPTION) && ! use.equals(UsageType.UNSPECIFIED) ) { throw new ValidationException("Invalid value for use attribute: " + use.toString()); } } }
/** {@inheritDoc} */ public int hashCode() { int result = 17; result = 37 * result + id.hashCode(); result = 37 * result + role.hashCode(); if (protocol != null) { result = 37 * result + protocol.hashCode(); } result = 37 * result + usage.hashCode(); return result; }
/** * Parse the credential element attributes. * * @param element credential element * @param builder bean definition builder */ protected void parseAttributes(Element element, BeanDefinitionBuilder builder) { String usage = DatatypeHelper.safeTrimOrNullString(element.getAttributeNS(null, "usage")); if (usage != null) { builder.addPropertyValue("usageType", UsageType.valueOf(usage.toUpperCase())); } else { builder.addPropertyValue("usageType", UsageType.UNSPECIFIED); } String entityID = DatatypeHelper.safeTrimOrNullString(element.getAttributeNS(null, "entityID")); if (entityID != null) { builder.addPropertyValue("entityID", entityID); } }
String use = ""; try { use = descriptor.getUse().name().toString(); } catch (Exception ex) { log.error("Error !!!!", ex); KeyDescriptor descriptor = descriptors.get(i); if (descriptor != null) { if (descriptor.getUse() != null && "SIGNING".equals(descriptor.getUse().toString())) { try { String cert = null;
private void setX509Certificate(EntityDescriptor entityDescriptor,SPSSODescriptor spssoDescriptor, SAMLSSOServiceProviderDO samlssoServiceProviderDO){ List<KeyDescriptor> descriptors = spssoDescriptor.getKeyDescriptors(); if (descriptors != null && descriptors.size() > 0) { KeyDescriptor descriptor = descriptors.get(0); if (descriptor != null) { if (descriptor.getUse().toString().equals("SIGNING")) { try { samlssoServiceProviderDO.setX509Certificate(org.opensaml.xml.security.keyinfo.KeyInfoHelper.getCertificates(descriptor.getKeyInfo()).get(0)); samlssoServiceProviderDO.setCertAlias(entityDescriptor.getEntityID()); } catch (java.security.cert.CertificateException ex) { log.error("Error While setting Certificate and alias", ex); }catch(java.lang.Exception ex){ log.error("Error While setting Certificate and alias", ex); } } } } } private void setSigningAlgorithmUri(SPSSODescriptor spssoDescriptor, SAMLSSOServiceProviderDO samlssoServiceProviderDO){
if (usage.equals(UsageType.UNSPECIFIED)) { if (extendedMetadata.getSigningKey() != null) { log.debug("Using customized signing key {} from extended metadata for entityID {}", extendedMetadata.getSigningKey(), entityID); credentials.add(keyManager.getCredential(extendedMetadata.getTlsKey())); } else if (usage.equals(UsageType.SIGNING)) { if (extendedMetadata.getSigningKey() != null) { log.debug("Using customized signing key {} from extended metadata for entityID {}", extendedMetadata.getSigningKey(), entityID); credentials.add(keyManager.getCredential(extendedMetadata.getSigningKey())); } else if (usage.equals(UsageType.ENCRYPTION)) { if (extendedMetadata.getEncryptionKey() != null) { log.debug("Using customized encryption key {} from extended metadata for entityID {}", extendedMetadata.getEncryptionKey(), entityID);
private void setX509Certificate(EntityDescriptor entityDescriptor, SPSSODescriptor spssoDescriptor, SAMLSSOServiceProviderDO samlssoServiceProviderDO) { List<KeyDescriptor> descriptors = spssoDescriptor.getKeyDescriptors(); if (descriptors != null && descriptors.size() > 0) { KeyDescriptor descriptor = descriptors.get(0); if (descriptor != null) { if (descriptor.getUse().toString().equals("SIGNING")) { try { samlssoServiceProviderDO.setX509Certificate(org.opensaml.xml.security.keyinfo.KeyInfoHelper.getCertificates(descriptor.getKeyInfo()).get(0)); samlssoServiceProviderDO.setCertAlias(entityDescriptor.getEntityID()); } catch (java.security.cert.CertificateException ex) { log.error("Error While setting Certificate and alias", ex); } catch (java.lang.Exception ex) { log.error("Error While setting Certificate and alias", ex); } } } } }
/** {@inheritDoc} */ protected void marshallAttributes(XMLObject xmlObject, Element domElement) throws MarshallingException { KeyDescriptor keyDescriptor = (KeyDescriptor) xmlObject; if (keyDescriptor.getUse() != null) { UsageType use = keyDescriptor.getUse(); // UsageType enum contains more values than are allowed by SAML 2 schema if (use.equals(UsageType.SIGNING) || use.equals(UsageType.ENCRYPTION)) { domElement.setAttribute(KeyDescriptor.USE_ATTRIB_NAME, use.toString().toLowerCase()); } else if (use.equals(UsageType.UNSPECIFIED)) { // emit nothing for unspecified - this is semantically equivalent to non-existent attribute } else { // Just in case values are unknowingly added to UsageType in the future... throw new MarshallingException("KeyDescriptor had illegal value for use attribute: " + use.toString()); } } } }
/** {@inheritDoc} */ public int hashCode() { int result = 17; result = 37 * result + id.hashCode(); result = 37 * result + role.hashCode(); if (protocol != null) { result = 37 * result + protocol.hashCode(); } result = 37 * result + usage.hashCode(); return result; }
/** {@inheritDoc} */ protected void processAttribute(XMLObject samlObject, Attr attribute) throws UnmarshallingException { KeyDescriptor keyDescriptor = (KeyDescriptor) samlObject; if (attribute.getName().equals(KeyDescriptor.USE_ATTRIB_NAME)) { try { UsageType usageType = UsageType.valueOf(UsageType.class, attribute.getValue().toUpperCase()); // Only allow the enum values specified in the schema. if (usageType != UsageType.SIGNING && usageType != UsageType.ENCRYPTION) { throw new UnmarshallingException("Invalid key usage type: " + attribute.getValue()); } keyDescriptor.setUse(usageType); } catch (IllegalArgumentException e) { throw new UnmarshallingException("Invalid key usage type: " + attribute.getValue()); } } super.processAttribute(samlObject, attribute); } }
/** * {@inheritDoc} */ public int hashCode() { int result = 17; result = 37 * result + id.hashCode(); result = 37 * result + role.hashCode(); if (protocol != null) { result = 37 * result + protocol.hashCode(); } result = 37 * result + usage.hashCode(); return result; }