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

import com.airlock.iam.base.api.domain.model.exception.FailureException;
import com.sun.identity.saml2.assertion.AuthnContext;
import com.sun.identity.saml2.assertion.impl.AuthnContextImpl;
import com.sun.identity.saml2.common.SAML2Exception;

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

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