* @throws MarshallingException thrown if the given request can not be marshalled and serialized into a string
*/
public Saml2LoginContext(String relyingParty, AuthnRequest request) throws MarshallingException {
+ super();
+
if (relyingParty == null || request == null) {
throw new IllegalArgumentException("SAML 2 authentication request and relying party ID may not be null");
}
-
- serialAuthnRequest = serializeRequest(request);
+ setRelyingParty(relyingParty);
authnRequest = request;
+ serialAuthnRequest = serializeRequest(request);
+
setForceAuth(authnRequest.isForceAuthn());
setPassiveAuth(authnRequest.isPassive());
- setRelyingParty(relyingParty);
+ getRequestedAuthenticationMethods().addAll(extractRequestedAuthenticationMethods());
}
/**
}
/**
- * This method evaluates a SAML2 {@link RequestedAuthnContext} and returns the list of requested authentication
- * method URIs.
+ * Serializes an authentication request into a string.
+ *
+ * @param request the request to serialize
+ *
+ * @return the serialized form of the string
+ *
+ * @throws MarshallingException thrown if the request can not be marshalled and serialized
+ */
+ protected String serializeRequest(AuthnRequest request) throws MarshallingException {
+ Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(request);
+ Element requestElem = marshaller.marshall(request);
+ StringWriter writer = new StringWriter();
+ XMLHelper.writeNode(requestElem, writer);
+ return writer.toString();
+ }
+
+ /**
+ * Deserailizes an authentication request from a string.
+ *
+ * @param request request to deserialize
+ *
+ * @return the request XMLObject
*
- * If the AuthnQuery did not contain a RequestedAuthnContext, this method will return <code>null</code>.
+ * @throws UnmarshallingException thrown if the request can no be deserialized and unmarshalled
+ */
+ protected AuthnRequest deserializeRequest(String request) throws UnmarshallingException {
+ DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
+ try {
+ DocumentBuilder docBuilder = builderFactory.newDocumentBuilder();
+ InputSource requestInput = new InputSource(new StringReader(request));
+ Element requestElem = docBuilder.parse(requestInput).getDocumentElement();
+ Unmarshaller unmarshaller = Configuration.getUnmarshallerFactory().getUnmarshaller(requestElem);
+ return (AuthnRequest) unmarshaller.unmarshall(requestElem);
+ } catch (Exception e) {
+ throw new UnmarshallingException("Unable to read serialized authentication request");
+ }
+ }
+
+ /**
+ * Extracts the authentication methods requested within the request.
*
- * @return An array of authentication method URIs, or <code>null</code>.
+ * @return requested authentication methods
*/
- public List<String> getRequestedAuthenticationMethods() {
+ protected List<String> extractRequestedAuthenticationMethods(){
ArrayList<String> requestedMethods = new ArrayList<String>();
RequestedAuthnContext authnContext = getRequestedAuthenticationContext();
if (comparator != null && comparator != AuthnContextComparisonTypeEnumeration.EXACT) {
log.error("Unsupported comparision operator ( " + comparator
+ ") in RequestedAuthnContext. Only exact comparisions are supported.");
- return null;
+ return requestedMethods;
}
// build a list of all requested authn classes and declrefs
return requestedMethods;
}
-
- /**
- * Serializes an authentication request into a string.
- *
- * @param request the request to serialize
- *
- * @return the serialized form of the string
- *
- * @throws MarshallingException thrown if the request can not be marshalled and serialized
- */
- protected String serializeRequest(AuthnRequest request) throws MarshallingException {
- Marshaller marshaller = Configuration.getMarshallerFactory().getMarshaller(request);
- Element requestElem = marshaller.marshall(request);
- StringWriter writer = new StringWriter();
- XMLHelper.writeNode(requestElem, writer);
- return writer.toString();
- }
-
- /**
- * Deserailizes an authentication request from a string.
- *
- * @param request request to deserialize
- *
- * @return the request XMLObject
- *
- * @throws UnmarshallingException thrown if the request can no be deserialized and unmarshalled
- */
- protected AuthnRequest deserializeRequest(String request) throws UnmarshallingException {
- DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
- try {
- DocumentBuilder docBuilder = builderFactory.newDocumentBuilder();
- InputSource requestInput = new InputSource(new StringReader(request));
- Element requestElem = docBuilder.parse(requestInput).getDocumentElement();
- Unmarshaller unmarshaller = Configuration.getUnmarshallerFactory().getUnmarshaller(requestElem);
- return (AuthnRequest) unmarshaller.unmarshall(requestElem);
- } catch (Exception e) {
- throw new UnmarshallingException("Unable to read serialized authentication request");
- }
- }
}
\ No newline at end of file