use of org.keycloak.saml.common.exceptions.ConfigurationException in project keycloak by keycloak.
the class SAML2ErrorResponseBuilder method buildDocument.
public Document buildDocument() throws ProcessingException {
try {
StatusResponseType statusResponse = new ResponseType(IDGenerator.create("ID_"), XMLTimeUtil.getIssueInstant());
statusResponse.setStatus(JBossSAMLAuthnResponseFactory.createStatusTypeForResponder(status));
statusResponse.setIssuer(issuer);
statusResponse.setDestination(destination);
if (!this.extensions.isEmpty()) {
ExtensionsType extensionsType = new ExtensionsType();
for (NodeGenerator extension : this.extensions) {
extensionsType.addExtension(extension);
}
statusResponse.setExtensions(extensionsType);
}
SAML2Response saml2Response = new SAML2Response();
return saml2Response.convert(statusResponse);
} catch (ConfigurationException e) {
throw new ProcessingException(e);
} catch (ParsingException e) {
throw new ProcessingException(e);
}
}
use of org.keycloak.saml.common.exceptions.ConfigurationException in project keycloak by keycloak.
the class BrokerTest method createAuthnResponse.
private SAML2Object createAuthnResponse(SAML2Object so) {
AuthnRequestType req = (AuthnRequestType) so;
try {
final ResponseType res = new SAML2LoginResponseBuilder().requestID(req.getID()).destination(req.getAssertionConsumerServiceURL().toString()).issuer("https://saml.idp/saml").assertionExpiration(1000000).subjectExpiration(1000000).requestIssuer(getAuthServerRealmBase(REALM_NAME).toString()).sessionIndex("idp:" + UUID.randomUUID()).buildModel();
AttributeStatementType attrStatement = new AttributeStatementType();
AttributeType attribute = new AttributeType("mail");
attribute.addAttributeValue("v@w.x");
attrStatement.addAttribute(new ASTChoiceType(attribute));
res.getAssertions().get(0).getAssertion().addStatement(attrStatement);
return res;
} catch (ConfigurationException | ProcessingException ex) {
throw new RuntimeException(ex);
}
}
use of org.keycloak.saml.common.exceptions.ConfigurationException in project keycloak by keycloak.
the class BasicSamlTest method testPropertyValueInAssertion.
// KEYCLOAK-4160
@Test
public void testPropertyValueInAssertion() throws ParsingException, ConfigurationException, ProcessingException {
SAMLDocumentHolder document = new SamlClientBuilder().authnRequest(getAuthServerSamlEndpoint(REALM_NAME), SAML_CLIENT_ID_SALES_POST, SAML_ASSERTION_CONSUMER_URL_SALES_POST, Binding.POST).transformDocument(doc -> {
setDocElementAttributeValue(doc, "samlp:AuthnRequest", "ID", "${java.version}");
return doc;
}).build().login().user(bburkeUser).build().getSamlResponse(Binding.POST);
assertThat(documentToString(document.getSamlDocument()), not(containsString("InResponseTo=\"" + System.getProperty("java.version") + "\"")));
}
use of org.keycloak.saml.common.exceptions.ConfigurationException in project keycloak by keycloak.
the class AbstractSamlAuthenticationHandler method getAssertionDocumentFromElement.
private Document getAssertionDocumentFromElement(final Element assertionElement) {
if (assertionElement == null) {
return null;
}
try {
Document assertionDoc = DocumentUtil.createDocument();
assertionDoc.adoptNode(assertionElement);
assertionDoc.appendChild(assertionElement);
return assertionDoc;
} catch (ConfigurationException e) {
log.warn("Cannot obtain DOM assertion document", e);
return null;
}
}
use of org.keycloak.saml.common.exceptions.ConfigurationException in project keycloak by keycloak.
the class SamlSPFacade method getSamlAuthnRequest.
/*
* https://idp.ssocircle.com/sso/toolbox/samlEncode.jsp
*
* returns (https instead of http in case ssl is required)
*
* <samlp:AuthnRequest
* xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
* xmlns="urn:oasis:names:tc:SAML:2.0:assertion"
* AssertionConsumerServiceURL="http://localhost:8280/employee/"
* Destination="http://localhost:8180/auth/realms/demo/protocol/saml"
* ForceAuthn="false"
* ID="ID_4d8e5ce2-7206-472b-a897-2d837090c005"
* IsPassive="false"
* IssueInstant="2015-03-06T22:22:17.854Z"
* ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
* Version="2.0">
* <saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">saml-employee</saml:Issuer>
* <samlp:NameIDPolicy AllowCreate="true" Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified"/>
* </samlp:AuthnRequest>
*/
private URI getSamlAuthnRequest(HttpServletRequest req) {
try {
BaseSAML2BindingBuilder binding = new BaseSAML2BindingBuilder();
SAML2Request samlReq = new SAML2Request();
String appServerUrl = ServletTestUtils.getUrlBase() + "/employee/";
String authServerUrl = ServletTestUtils.getAuthServerUrlBase() + "/auth/realms/demo/protocol/saml";
AuthnRequestType loginReq;
loginReq = samlReq.createAuthnRequestType(UUID.randomUUID().toString(), appServerUrl, authServerUrl, "http://localhost:8280/employee/");
loginReq.getNameIDPolicy().setFormat(JBossSAMLURIConstants.NAMEID_FORMAT_UNSPECIFIED.getUri());
return binding.redirectBinding(SAML2Request.convert(loginReq)).requestURI(authServerUrl);
} catch (IOException | ConfigurationException | ParsingException | ProcessingException ex) {
throw new RuntimeException(ex);
}
}
Aggregations