/******************************************************************************* *******************************************************************************/ package at.gv.egiz.eaaf.modules.pvp2.idp.impl; import javax.annotation.PostConstruct; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; import at.gv.egiz.eaaf.core.api.IRequest; import at.gv.egiz.eaaf.core.api.idp.IAction; import at.gv.egiz.eaaf.core.api.idp.IAuthData; import at.gv.egiz.eaaf.core.api.idp.slo.SLOInformationInterface; import at.gv.egiz.eaaf.core.api.logging.IRevisionLogger; import at.gv.egiz.eaaf.modules.pvp2.PVPEventConstants; import at.gv.egiz.eaaf.modules.pvp2.api.metadata.IPVPMetadataBuilderConfiguration; import at.gv.egiz.eaaf.modules.pvp2.api.metadata.IPVPMetadataConfigurationFactory; import at.gv.egiz.eaaf.modules.pvp2.exception.PVP2MetadataException; import at.gv.egiz.eaaf.modules.pvp2.impl.builder.PVPMetadataBuilder; import at.gv.egiz.eaaf.modules.pvp2.impl.utils.AbstractCredentialProvider; @Service("pvpMetadataService") public class MetadataAction implements IAction { private static final Logger log = LoggerFactory.getLogger(MetadataAction.class); @Autowired private IRevisionLogger revisionsLogger; @Autowired private PVPMetadataBuilder metadatabuilder; @Autowired private IPVPMetadataConfigurationFactory configFactory; private AbstractCredentialProvider pvpIDPCredentials; /** * Sets a specific credential provider for PVP S-Profile IDP component. * @param pvpIDPCredentials credential provider */ public void setPvpIDPCredentials(AbstractCredentialProvider pvpIDPCredentials) { this.pvpIDPCredentials = pvpIDPCredentials; } public SLOInformationInterface processRequest(IRequest req, HttpServletRequest httpReq, HttpServletResponse httpResp, IAuthData authData) throws PVP2MetadataException { try { revisionsLogger.logEvent(req, PVPEventConstants.AUTHPROTOCOL_PVP_METADATA); //build metadata IPVPMetadataBuilderConfiguration metadataConfig = configFactory.generateMetadataBuilderConfiguration( req.getAuthURLWithOutSlash(), pvpIDPCredentials); ; String metadataXML = metadatabuilder.buildPVPMetadata(metadataConfig); log.debug("METADATA: " + metadataXML); byte[] content = metadataXML.getBytes("UTF-8"); httpResp.setStatus(HttpServletResponse.SC_OK); httpResp.setContentLength(content.length); httpResp.setContentType(MediaType.APPLICATION_XML_VALUE); httpResp.getOutputStream().write(content); return null; } catch (Exception e) { log.error("Failed to generate metadata", e); throw new PVP2MetadataException("pvp2.13", null); } } public boolean needAuthentication(IRequest req, HttpServletRequest httpReq, HttpServletResponse httpResp) { return false; } /* (non-Javadoc) * @see at.gv.egovernment.moa.id.moduls.IAction#getDefaultActionName() */ @Override public String getDefaultActionName() { return "IDP - PVP Metadata action"; } @PostConstruct private void verifyInitialization() { if (pvpIDPCredentials == null) { log.error("No SAML2 credentialProvider injected!"); throw new RuntimeException("No SAML2 credentialProvider injected!"); } } }