package com.airlock.iam.saml2.infrastructure.state;

import com.airlock.iam.base.api.domain.model.exception.FailureException;
import com.sun.identity.saml2.common.SAML2Exception;
import com.sun.identity.saml2.protocol.AuthnRequest;
import com.sun.identity.saml2.protocol.impl.AuthnRequestImpl;

final class AuthnRequestSerializer implements Serializer<AuthnRequest> {
   public String mapToStore(AuthnRequest value) {
      try {
         return value.toXMLString(true, true);
      } catch (SAML2Exception e) {
         throw new FailureException(e);
      }
   }

   public AuthnRequest mapFromStore(String xmlString) {
      try {
         return new AuthnRequestImpl(xmlString);
      } catch (SAML2Exception e) {
         throw new FailureException(e);
      }
   }
}
