org.opensaml.xml.schema.XSString Java Examples
The following examples show how to use
org.opensaml.xml.schema.XSString.
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: SAMLResponseBuilder.java From carbon-identity with Apache License 2.0 | 7 votes |
/** * Build Attribute Statement * * @param claims * @return AttributeStatement */ private AttributeStatement buildAttributeStatement(Map<String, String> claims) { AttributeStatement attStmt = null; if (claims != null) { attStmt = new AttributeStatementBuilder().buildObject(); Iterator<String> ite = claims.keySet().iterator(); for (int i = 0; i < claims.size(); i++) { Attribute attrib = new AttributeBuilder().buildObject(); String claimUri = ite.next(); attrib.setName(claimUri); // look // https://wiki.shibboleth.net/confluence/display/OpenSAML/OSTwoUsrManJavaAnyTypes XSStringBuilder stringBuilder = (XSStringBuilder) Configuration.getBuilderFactory() .getBuilder(XSString.TYPE_NAME); XSString stringValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); stringValue.setValue(claims.get(claimUri)); attrib.getAttributeValues().add(stringValue); attStmt.getAttributes().add(attrib); } } return attStmt; }
Example #2
Source File: SamlAssertionProducer.java From saml-generator with Apache License 2.0 | 6 votes |
private AttributeStatement createAttributeStatement(HashMap<String, List<String>> attributes) { // create authenticationstatement object AttributeStatementBuilder attributeStatementBuilder = new AttributeStatementBuilder(); AttributeStatement attributeStatement = attributeStatementBuilder.buildObject(); AttributeBuilder attributeBuilder = new AttributeBuilder(); if (attributes != null) { for (Map.Entry<String, List<String>> entry : attributes.entrySet()) { Attribute attribute = attributeBuilder.buildObject(); attribute.setName(entry.getKey()); for (String value : entry.getValue()) { XSStringBuilder stringBuilder = new XSStringBuilder(); XSString attributeValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); attributeValue.setValue(value); attribute.getAttributeValues().add(attributeValue); } attributeStatement.getAttributes().add(attribute); } } return attributeStatement; }
Example #3
Source File: FaultUnmarshaller.java From lams with GNU General Public License v2.0 | 5 votes |
/** {@inheritDoc} */ protected void processChildElement(XMLObject parentXMLObject, XMLObject childXMLObject) throws UnmarshallingException { Fault fault = (Fault) parentXMLObject; if(childXMLObject instanceof XSQName){ fault.setCode((FaultCode) childXMLObject); }else if(childXMLObject instanceof XSString){ fault.setMessage((FaultString) childXMLObject); }else if(childXMLObject instanceof XSURI){ fault.setActor((FaultActor) childXMLObject); }else if(childXMLObject instanceof Detail){ fault.setDetail((Detail) childXMLObject); } }
Example #4
Source File: DefaultsTypeUnmarshaller.java From lams with GNU General Public License v2.0 | 5 votes |
/** {@inheritDoc} */ protected void processChildElement(XMLObject parentXMLObject, XMLObject childXMLObject) throws UnmarshallingException { if (childXMLObject instanceof XSString) { DefaultsType defaultType = (DefaultsType) parentXMLObject; defaultType.setXPathVersion((XSString) childXMLObject); } else { super.processChildElement(parentXMLObject, childXMLObject); } }
Example #5
Source File: Saml10SuccessResponseView.java From cas4.0.x-server-wechat with Apache License 2.0 | 5 votes |
private XSString newAttributeValue(final Object value) { final XSString stringValue = this.attrValueBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); if (value instanceof String) { stringValue.setValue((String) value); } else { stringValue.setValue(value.toString()); } return stringValue; }
Example #6
Source File: XSStringMarshaller.java From lams with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ protected void marshallElementContent(XMLObject xmlObject, Element domElement) throws MarshallingException { XSString xsiString = (XSString) xmlObject; XMLHelper.appendTextContent(domElement, xsiString.getValue()); }
Example #7
Source File: XSStringUnmarshaller.java From lams with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ protected void processElementContent(XMLObject xmlObject, String elementContent) { XSString xsiString = (XSString) xmlObject; xsiString.setValue(elementContent); }
Example #8
Source File: DefaultsTypeImpl.java From lams with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public XSString getXPathVersion() { return xPathVersion; }
Example #9
Source File: DefaultsTypeImpl.java From lams with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public void setXPathVersion(XSString version) { this.xPathVersion = prepareForAssignment(this.xPathVersion, version); }
Example #10
Source File: AttributeStatementGenerator.java From MaxKey with Apache License 2.0 | 4 votes |
public XSString builderAttributeValue(String value) { XSString xsStringValue = new XSStringBuilder().buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); xsStringValue.setValue(value); return xsStringValue; }
Example #11
Source File: OAuth2SAMLWorkflowSample.java From jam-collaboration-sample with Apache License 2.0 | 4 votes |
private static Assertion buildSAML2Assertion(boolean includeClientKeyAttribute) { // Bootstrap the OpenSAML library try { DefaultBootstrap.bootstrap(); } catch (ConfigurationException e) { } DateTime issueInstant = new DateTime(); DateTime notOnOrAfter = issueInstant.plusMinutes(10); DateTime notBefore = issueInstant.minusMinutes(10); NameID nameID = (new NameIDBuilder().buildObject()); if (SUBJECT_NAME_ID_FORMAT.equals("email")) { nameID.setFormat(NameIDType.EMAIL); } else if (SUBJECT_NAME_ID_FORMAT.equals("unspecified")) { nameID.setFormat(NameIDType.UNSPECIFIED); } else { throw new IllegalArgumentException("SUBJECT_NAME_ID_FORMAT must be 'email' or 'unspecified'."); } if (subjectNameIdQualifier != null) { nameID.setNameQualifier(subjectNameIdQualifier); } nameID.setValue(SUBJECT_NAME_ID); SubjectConfirmationData subjectConfirmationData = (new SubjectConfirmationDataBuilder().buildObject()); subjectConfirmationData.setRecipient(BASE_URL + ACCESS_TOKEN_URL_PATH); subjectConfirmationData.setNotOnOrAfter(notOnOrAfter); SubjectConfirmation subjectConfirmation = (new SubjectConfirmationBuilder().buildObject()); subjectConfirmation.setMethod(SubjectConfirmation.METHOD_BEARER); subjectConfirmation.setSubjectConfirmationData(subjectConfirmationData); Subject subject = (new SubjectBuilder().buildObject()); subject.setNameID(nameID); subject.getSubjectConfirmations().add(subjectConfirmation); Issuer issuer = (new IssuerBuilder().buildObject()); issuer.setValue(IDP_ID); Audience audience = (new AudienceBuilder().buildObject()); audience.setAudienceURI(SP_ID_JAM); AudienceRestriction audienceRestriction = (new AudienceRestrictionBuilder().buildObject()); audienceRestriction.getAudiences().add(audience); Conditions conditions = (new ConditionsBuilder().buildObject()); conditions.setNotBefore(notBefore); conditions.setNotOnOrAfter(notOnOrAfter); conditions.getAudienceRestrictions().add(audienceRestriction); Assertion assertion = (new AssertionBuilder().buildObject()); assertion.setID(UUID.randomUUID().toString()); assertion.setVersion(SAMLVersion.VERSION_20); assertion.setIssueInstant(issueInstant); assertion.setIssuer(issuer); assertion.setSubject(subject); assertion.setConditions(conditions); if (includeClientKeyAttribute) { XSString attributeValue = (XSString)Configuration.getBuilderFactory().getBuilder(XSString.TYPE_NAME).buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); attributeValue.setValue(CLIENT_KEY); Attribute attribute = (new AttributeBuilder().buildObject()); attribute.setName("client_id"); attribute.getAttributeValues().add(attributeValue); AttributeStatement attributeStatement = (new AttributeStatementBuilder().buildObject()); attributeStatement.getAttributes().add(attribute); assertion.getAttributeStatements().add(attributeStatement); } return assertion; }
Example #12
Source File: OAuth2SAMLWorkflowSample.java From jam-collaboration-sample with Apache License 2.0 | 4 votes |
private static Assertion buildSAML2Assertion( String baseUrl, String subjectNameId, String subjectNameIdFormat, String subjectNameIdQualifier, String idpId, String clientKey, boolean includeClientKeyAttribute) { // Bootstrap the OpenSAML library try { DefaultBootstrap.bootstrap(); } catch (ConfigurationException e) { } DateTime issueInstant = new DateTime(); DateTime notOnOrAfter = issueInstant.plusMinutes(10); DateTime notBefore = issueInstant.minusMinutes(10); NameID nameID = (new NameIDBuilder().buildObject()); if (subjectNameIdFormat.equals("email")) { nameID.setFormat(NameIDType.EMAIL); } else if (subjectNameIdFormat.equals("unspecified")) { nameID.setFormat(NameIDType.UNSPECIFIED); } else { throw new IllegalArgumentException("subjectNameIdFormat must be 'email' or 'unspecified'."); } if (subjectNameIdQualifier != null) { nameID.setNameQualifier(subjectNameIdQualifier); } nameID.setValue(subjectNameId); SubjectConfirmationData subjectConfirmationData = (new SubjectConfirmationDataBuilder().buildObject()); subjectConfirmationData.setRecipient(baseUrl + ACCESS_TOKEN_URL_PATH); subjectConfirmationData.setNotOnOrAfter(notOnOrAfter); SubjectConfirmation subjectConfirmation = (new SubjectConfirmationBuilder().buildObject()); subjectConfirmation.setMethod(SubjectConfirmation.METHOD_BEARER); subjectConfirmation.setSubjectConfirmationData(subjectConfirmationData); Subject subject = (new SubjectBuilder().buildObject()); subject.setNameID(nameID); subject.getSubjectConfirmations().add(subjectConfirmation); Issuer issuer = (new IssuerBuilder().buildObject()); issuer.setValue(idpId); Audience audience = (new AudienceBuilder().buildObject()); audience.setAudienceURI(SP_ID_JAM); AudienceRestriction audienceRestriction = (new AudienceRestrictionBuilder().buildObject()); audienceRestriction.getAudiences().add(audience); Conditions conditions = (new ConditionsBuilder().buildObject()); conditions.setNotBefore(notBefore); conditions.setNotOnOrAfter(notOnOrAfter); conditions.getAudienceRestrictions().add(audienceRestriction); Assertion assertion = (new AssertionBuilder().buildObject()); assertion.setID(UUID.randomUUID().toString()); assertion.setVersion(SAMLVersion.VERSION_20); assertion.setIssueInstant(issueInstant); assertion.setIssuer(issuer); assertion.setSubject(subject); assertion.setConditions(conditions); if (includeClientKeyAttribute) { XSString attributeValue = (XSString)Configuration.getBuilderFactory().getBuilder(XSString.TYPE_NAME).buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); attributeValue.setValue(clientKey); Attribute attribute = (new AttributeBuilder().buildObject()); attribute.setName("client_id"); attribute.getAttributeValues().add(attributeValue); AttributeStatement attributeStatement = (new AttributeStatementBuilder().buildObject()); attributeStatement.getAttributes().add(attribute); assertion.getAttributeStatements().add(attributeStatement); } return assertion; }
Example #13
Source File: SAML2TokenBuilder.java From carbon-identity with Apache License 2.0 | 4 votes |
@Override public void createStatement(GenericIdentityProviderData ipData, RahasData rahasData) throws IdentityProviderException { if (log.isDebugEnabled()) { log.debug("Begin SAML statement creation."); } attributeStmt = (AttributeStatement) buildXMLObject(AttributeStatement.DEFAULT_ELEMENT_NAME); Map<String, RequestedClaimData> mapClaims = ipData.getRequestedClaims(); if (rahasData.getAppliesToAddress() != null) { appilesTo = rahasData.getAppliesToAddress(); } Iterator<RequestedClaimData> ite = mapClaims.values().iterator(); while (ite.hasNext()) { RequestedClaimData claim = ite.next(); String uri = claim.getUri(); int index = uri.lastIndexOf("/"); String attrName = uri.substring(index + 1, uri.length()); String attrNamespace = uri.substring(0, index); Attribute attribute = (Attribute) buildXMLObject(Attribute.DEFAULT_ELEMENT_NAME); attribute.setName(attrName); attribute.setNameFormat(attrNamespace); XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory(); // TODO remove this else if condition after WSO2 IS supports claim // types properly if (claim.getUri().equals(IdentityConstants.CLAIM_PPID)) { XSBase64BinaryBuilder ppidValueBuilder = (XSBase64BinaryBuilder) builderFactory .getBuilder(XSBase64Binary.TYPE_NAME); XSBase64Binary ppidValue = ppidValueBuilder.buildObject( AttributeValue.DEFAULT_ELEMENT_NAME, XSBase64Binary.TYPE_NAME); ppidValue.setValue(claim.getValue()); attribute.getAttributeValues().add(ppidValue); } else { XSStringBuilder attributeValueBuilder = (XSStringBuilder) builderFactory .getBuilder(XSString.TYPE_NAME); XSString stringValue = attributeValueBuilder.buildObject( AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); stringValue.setValue(claim.getValue()); attribute.getAttributeValues().add(stringValue); } attributeStmt.getAttributes().add(attribute); } }
Example #14
Source File: SAML1TokenBuilder.java From carbon-identity with Apache License 2.0 | 4 votes |
@Override public void createStatement(GenericIdentityProviderData ipData, RahasData rahasData) throws IdentityProviderException { if (log.isDebugEnabled()) { log.debug("Begin SAML statement creation."); } attributeStmt = (AttributeStatement) buildXMLObject(AttributeStatement.DEFAULT_ELEMENT_NAME); Subject subject = (Subject) buildXMLObject(Subject.DEFAULT_ELEMENT_NAME); SubjectConfirmation subjectConf = (SubjectConfirmation) buildXMLObject(SubjectConfirmation.DEFAULT_ELEMENT_NAME); ConfirmationMethod confMethod = (ConfirmationMethod) buildXMLObject(ConfirmationMethod.DEFAULT_ELEMENT_NAME); confMethod.setConfirmationMethod(CONF_KEY); subjectConf.getConfirmationMethods().add(confMethod); subject.setSubjectConfirmation(subjectConf); attributeStmt.setSubject(subject); Map<String, RequestedClaimData> mapClaims = ipData.getRequestedClaims(); if (rahasData.getAppliesToAddress() != null) { appilesTo = rahasData.getAppliesToAddress(); } Iterator<RequestedClaimData> ite = mapClaims.values().iterator(); while (ite.hasNext()) { RequestedClaimData claim = ite.next(); String uri = claim.getUri(); int index = uri.lastIndexOf("/"); String attrName = uri.substring(index + 1, uri.length()); String attrNamespace = uri.substring(0, index); Attribute attribute = (Attribute) buildXMLObject(Attribute.DEFAULT_ELEMENT_NAME); attribute.setAttributeName(attrName); attribute.setAttributeNamespace(attrNamespace); XMLObjectBuilderFactory builderFactory = Configuration.getBuilderFactory(); XSStringBuilder attributeValueBuilder = (XSStringBuilder) builderFactory.getBuilder(XSString.TYPE_NAME); XSString stringValue = attributeValueBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); stringValue.setValue(claim.getValue()); attribute.getAttributeValues().add(stringValue); attributeStmt.getAttributes().add(attribute); } }
Example #15
Source File: DefaultSAMLAssertionBuilder.java From carbon-identity with Apache License 2.0 | 4 votes |
private AttributeStatement buildAttributeStatement(Map<String, String> claims) { String claimSeparator = claims.get(IdentityCoreConstants.MULTI_ATTRIBUTE_SEPARATOR); if (StringUtils.isNotBlank(claimSeparator)) { userAttributeSeparator = claimSeparator; } claims.remove(IdentityCoreConstants.MULTI_ATTRIBUTE_SEPARATOR); AttributeStatement attStmt = new AttributeStatementBuilder().buildObject(); Iterator<Map.Entry<String, String>> iterator = claims.entrySet().iterator(); boolean atLeastOneNotEmpty = false; for (int i = 0; i < claims.size(); i++) { Map.Entry<String, String> claimEntry = iterator.next(); String claimUri = claimEntry.getKey(); String claimValue = claimEntry.getValue(); if (claimUri != null && !claimUri.trim().isEmpty() && claimValue != null && !claimValue.trim().isEmpty()) { atLeastOneNotEmpty = true; Attribute attribute = new AttributeBuilder().buildObject(); attribute.setName(claimUri); //setting NAMEFORMAT attribute value to basic attribute profile attribute.setNameFormat(SAMLSSOConstants.NAME_FORMAT_BASIC); // look // https://wiki.shibboleth.net/confluence/display/OpenSAML/OSTwoUsrManJavaAnyTypes XSStringBuilder stringBuilder = (XSStringBuilder) Configuration.getBuilderFactory(). getBuilder(XSString.TYPE_NAME); XSString stringValue; //Need to check if the claim has multiple values if (userAttributeSeparator != null && claimValue.contains(userAttributeSeparator)) { StringTokenizer st = new StringTokenizer(claimValue, userAttributeSeparator); while (st.hasMoreElements()) { String attValue = st.nextElement().toString(); if (attValue != null && attValue.trim().length() > 0) { stringValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); stringValue.setValue(attValue); attribute.getAttributeValues().add(stringValue); } } } else { stringValue = stringBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSString.TYPE_NAME); stringValue.setValue(claimValue); attribute.getAttributeValues().add(stringValue); } attStmt.getAttributes().add(attribute); } } if (atLeastOneNotEmpty) { return attStmt; } else { return null; } }
Example #16
Source File: XSStringBuilder.java From lams with GNU General Public License v2.0 | 4 votes |
/** {@inheritDoc} */ public XSString buildObject(String namespaceURI, String localName, String namespacePrefix) { return new XSStringImpl(namespaceURI, localName, namespacePrefix); }
Example #17
Source File: DefaultsType.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Gets the XPath version for this type. * * @return XPath version for this type */ public XSString getXPathVersion();
Example #18
Source File: DefaultsType.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Sets the XPath version for this type. * * @param version XPath version for this type */ public void setXPathVersion(XSString version);