Search in sources :

Example 1 with SMPNotFoundException

use of com.helger.phoss.smp.exception.SMPNotFoundException in project phoss-smp by phax.

the class SMPServiceGroupManagerMongoDB method deleteSMPServiceGroup.

@Nonnull
public EChange deleteSMPServiceGroup(@Nonnull final IParticipantIdentifier aParticipantID, final boolean bDeleteInSML) throws SMPServerException {
    ValueEnforcer.notNull(aParticipantID, "ParticipantID");
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("deleteSMPServiceGroup (" + aParticipantID.getURIEncoded() + ", " + bDeleteInSML + ")");
    // Check first in memory, to avoid unnecessary deletion
    final ISMPServiceGroup aServiceGroup = getSMPServiceGroupOfID(aParticipantID);
    if (aServiceGroup == null)
        return EChange.UNCHANGED;
    final IRegistrationHook aHook = RegistrationHookFactory.getInstance();
    if (bDeleteInSML) {
        // Delete in SML - throws exception in case of error
        try {
            aHook.deleteServiceGroup(aParticipantID);
        } catch (final RegistrationHookException ex) {
            throw new SMPSMLException("Failed to delete '" + aParticipantID.getURIEncoded() + "' in SML", ex);
        }
    }
    // Delete all redirects (must be done before the SG is deleted)
    final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
    aRedirectMgr.deleteAllSMPRedirectsOfServiceGroup(aServiceGroup);
    // Delete all service information (must be done before the SG is deleted)
    final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
    aServiceInfoMgr.deleteAllSMPServiceInformationOfServiceGroup(aServiceGroup);
    final String sServiceGroupID = SMPServiceGroup.createSMPServiceGroupID(aParticipantID);
    final DeleteResult aDR = getCollection().deleteOne(new Document(BSON_ID, sServiceGroupID));
    if (!aDR.wasAcknowledged() || aDR.getDeletedCount() == 0) {
        AuditHelper.onAuditDeleteFailure(SMPServiceGroup.OT, aParticipantID, "no-such-id");
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("deleteSMPServiceGroup - failure");
        // restore in SML
        if (bDeleteInSML) {
            // Undo deletion in SML!
            try {
                aHook.undoDeleteServiceGroup(aParticipantID);
            } catch (final RegistrationHookException ex) {
                LOGGER.error("Failed to undoDeleteServiceGroup (" + aParticipantID.getURIEncoded() + ")", ex);
            }
        }
        throw new SMPNotFoundException("No such service group '" + aParticipantID.getURIEncoded() + "'");
    }
    AuditHelper.onAuditDeleteSuccess(SMPServiceGroup.OT, aParticipantID, Boolean.valueOf(bDeleteInSML));
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("deleteSMPServiceGroup - success");
    m_aCBs.forEach(x -> x.onSMPServiceGroupDeleted(aParticipantID, bDeleteInSML));
    return EChange.CHANGED;
}
Also used : IRegistrationHook(com.helger.phoss.smp.smlhook.IRegistrationHook) ISMPRedirectManager(com.helger.phoss.smp.domain.redirect.ISMPRedirectManager) SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) RegistrationHookException(com.helger.phoss.smp.smlhook.RegistrationHookException) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) Document(org.bson.Document) SMPSMLException(com.helger.phoss.smp.exception.SMPSMLException) DeleteResult(com.mongodb.client.result.DeleteResult) Nonnull(javax.annotation.Nonnull)

Example 2 with SMPNotFoundException

use of com.helger.phoss.smp.exception.SMPNotFoundException in project phoss-smp by phax.

the class APIExecutorExportSpecificXMLVer1 method invokeAPI.

public void invokeAPI(@Nonnull final IAPIDescriptor aAPIDescriptor, @Nonnull @Nonempty final String sPath, @Nonnull final Map<String, String> aPathVariables, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final UnifiedResponse aUnifiedResponse) throws Exception {
    final String sPathServiceGroupID = aPathVariables.get(SMPRestFilter.PARAM_SERVICE_GROUP_ID);
    final String sLogPrefix = "[REST API Export-Specific-XML-V1] ";
    LOGGER.info(sLogPrefix + "Starting Export of '" + sPathServiceGroupID + "'");
    // Only authenticated user may do so
    final BasicAuthClientCredentials aBasicAuth = getMandatoryAuth(aRequestScope.headers());
    SMPUserManagerPhoton.validateUserCredentials(aBasicAuth);
    // Start action after authentication
    final ISMPSettingsManager aSettingsMgr = SMPMetaManager.getSettingsMgr();
    final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
    final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, null);
    final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
    final IParticipantIdentifier aPathServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sPathServiceGroupID);
    if (aPathServiceGroupID == null) {
        // Invalid identifier
        throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, aDataProvider.getCurrentURI());
    }
    // Retrieve the service group
    final ISMPServiceGroup aServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aPathServiceGroupID);
    if (aServiceGroup == null) {
        // No such service group
        throw new SMPNotFoundException("Unknown Service Group '" + sPathServiceGroupID + "'", aDataProvider.getCurrentURI());
    }
    final boolean bIncludeBusinessCards = aRequestScope.params().getAsBoolean(PARAM_INCLUDE_BUSINESS_CARDS, aSettingsMgr.getSettings().isDirectoryIntegrationEnabled());
    final IMicroDocument aDoc = ServiceGroupExport.createExportDataXMLVer10(new CommonsArrayList<>(aServiceGroup), bIncludeBusinessCards);
    LOGGER.info(sLogPrefix + "Finished creating Export data");
    // Build the XML response
    final IXMLWriterSettings aXWS = new XMLWriterSettings();
    aUnifiedResponse.setContentAndCharset(MicroWriter.getNodeAsString(aDoc, aXWS), aXWS.getCharset()).setMimeType(new MimeType(CMimeType.APPLICATION_XML).addParameter(CMimeType.PARAMETER_NAME_CHARSET, aXWS.getCharset().name())).disableCaching();
}
Also used : ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ISMPSettingsManager(com.helger.phoss.smp.settings.ISMPSettingsManager) IXMLWriterSettings(com.helger.xml.serialize.write.IXMLWriterSettings) XMLWriterSettings(com.helger.xml.serialize.write.XMLWriterSettings) IXMLWriterSettings(com.helger.xml.serialize.write.IXMLWriterSettings) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) CMimeType(com.helger.commons.mime.CMimeType) MimeType(com.helger.commons.mime.MimeType) SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) BasicAuthClientCredentials(com.helger.http.basicauth.BasicAuthClientCredentials) ISMPServerAPIDataProvider(com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider) IMicroDocument(com.helger.xml.microdom.IMicroDocument) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 3 with SMPNotFoundException

use of com.helger.phoss.smp.exception.SMPNotFoundException in project phoss-smp by phax.

the class SMPServiceGroupManagerXML method updateSMPServiceGroup.

@Nonnull
public EChange updateSMPServiceGroup(@Nonnull final IParticipantIdentifier aParticipantID, @Nonnull @Nonempty final String sNewOwnerID, @Nullable final String sExtension) throws SMPServerException {
    ValueEnforcer.notNull(aParticipantID, "ParticipantID");
    ValueEnforcer.notEmpty(sNewOwnerID, "NewOwnerID");
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("updateSMPServiceGroup (" + aParticipantID.getURIEncoded() + ", " + sNewOwnerID + ", " + (StringHelper.hasText(sExtension) ? "with extension" : "without extension") + ")");
    final String sServiceGroupID = SMPServiceGroup.createSMPServiceGroupID(aParticipantID);
    final SMPServiceGroup aSMPServiceGroup = getOfID(sServiceGroupID);
    if (aSMPServiceGroup == null) {
        AuditHelper.onAuditModifyFailure(SMPServiceGroup.OT, "set-all", sServiceGroupID, "no-such-id");
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("updateSMPServiceGroup - failure");
        throw new SMPNotFoundException("No such service group '" + sServiceGroupID + "'");
    }
    m_aRWLock.writeLock().lock();
    try {
        EChange eChange = EChange.UNCHANGED;
        eChange = eChange.or(aSMPServiceGroup.setOwnerID(sNewOwnerID));
        eChange = eChange.or(aSMPServiceGroup.setExtensionAsString(sExtension));
        if (eChange.isUnchanged()) {
            if (LOGGER.isDebugEnabled())
                LOGGER.debug("updateSMPServiceGroup - unchanged");
            return EChange.UNCHANGED;
        }
        internalUpdateItem(aSMPServiceGroup);
    } finally {
        m_aRWLock.writeLock().unlock();
    }
    AuditHelper.onAuditModifySuccess(SMPServiceGroup.OT, "set-all", sServiceGroupID, sNewOwnerID, sExtension);
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("updateSMPServiceGroup - success");
    m_aCBs.forEach(x -> x.onSMPServiceGroupUpdated(aParticipantID));
    return EChange.CHANGED;
}
Also used : SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) SMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.SMPServiceGroup) EChange(com.helger.commons.state.EChange) Nonnull(javax.annotation.Nonnull)

Example 4 with SMPNotFoundException

use of com.helger.phoss.smp.exception.SMPNotFoundException in project phoss-smp by phax.

the class SMPUserManagerPhoton method verifyOwnership.

public static void verifyOwnership(@Nonnull final IParticipantIdentifier aServiceGroupID, @Nonnull final IUser aCurrentUser) throws SMPNotFoundException, SMPUnauthorizedException {
    // Resolve service group
    final ISMPServiceGroup aServiceGroup = SMPMetaManager.getServiceGroupMgr().getSMPServiceGroupOfID(aServiceGroupID);
    if (aServiceGroup == null) {
        throw new SMPNotFoundException("Service group " + aServiceGroupID.getURIEncoded() + " does not exist");
    }
    // Resolve user
    final String sOwnerID = aServiceGroup.getOwnerID();
    if (!sOwnerID.equals(aCurrentUser.getID())) {
        throw new SMPUnauthorizedException("User '" + aCurrentUser.getLoginName() + "' does not own " + aServiceGroupID.getURIEncoded());
    }
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Verified service group " + aServiceGroup.getID() + " is owned by user '" + aCurrentUser.getLoginName() + "'");
}
Also used : SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) SMPUnauthorizedException(com.helger.phoss.smp.exception.SMPUnauthorizedException)

Example 5 with SMPNotFoundException

use of com.helger.phoss.smp.exception.SMPNotFoundException in project phoss-smp by phax.

the class BDXR1ServerAPI method getServiceRegistration.

@Nonnull
public SignedServiceMetadataType getServiceRegistration(@Nonnull final String sPathServiceGroupID, @Nonnull final String sPathDocTypeID) throws SMPServerException {
    final String sLog = LOG_PREFIX + "GET /" + sPathServiceGroupID + "/services/" + sPathDocTypeID;
    final String sAction = "getServiceRegistration";
    if (LOGGER.isInfoEnabled())
        LOGGER.info(sLog);
    STATS_COUNTER_INVOCATION.increment(sAction);
    try {
        final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
        final IParticipantIdentifier aPathServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sPathServiceGroupID);
        if (aPathServiceGroupID == null) {
            // Invalid identifier
            throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, m_aAPIDataProvider.getCurrentURI());
        }
        final ISMPServiceGroup aPathServiceGroup = SMPMetaManager.getServiceGroupMgr().getSMPServiceGroupOfID(aPathServiceGroupID);
        if (aPathServiceGroup == null) {
            throw new SMPNotFoundException("No such Service Group '" + sPathServiceGroupID + "'", m_aAPIDataProvider.getCurrentURI());
        }
        final IDocumentTypeIdentifier aPathDocTypeID = aIdentifierFactory.parseDocumentTypeIdentifier(sPathDocTypeID);
        if (aPathDocTypeID == null) {
            throw SMPBadRequestException.failedToParseDocType(sPathDocTypeID, m_aAPIDataProvider.getCurrentURI());
        }
        // First check for redirection, then for actual service
        final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
        final ISMPRedirect aRedirect = aRedirectMgr.getSMPRedirectOfServiceGroupAndDocumentType(aPathServiceGroup, aPathDocTypeID);
        final SignedServiceMetadataType aSignedServiceMetadata = new SignedServiceMetadataType();
        if (aRedirect != null) {
            aSignedServiceMetadata.setServiceMetadata(aRedirect.getAsJAXBObjectBDXR1());
        } else {
            // Get as regular service information
            final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
            final ISMPServiceInformation aServiceInfo = aServiceInfoMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aPathServiceGroup, aPathDocTypeID);
            final ServiceMetadataType aSM = aServiceInfo == null ? null : aServiceInfo.getAsJAXBObjectBDXR1();
            if (aSM != null) {
                aSignedServiceMetadata.setServiceMetadata(aSM);
            } else {
                // Neither nor is present, or no endpoint is available
                throw new SMPNotFoundException("service(" + sPathServiceGroupID + "," + sPathDocTypeID + ")", m_aAPIDataProvider.getCurrentURI());
            }
        }
        if (LOGGER.isInfoEnabled())
            LOGGER.info(sLog + " SUCCESS");
        STATS_COUNTER_SUCCESS.increment(sAction);
        return aSignedServiceMetadata;
    } catch (final SMPServerException ex) {
        if (LOGGER.isWarnEnabled())
            LOGGER.warn(sLog + " ERROR - " + ex.getMessage());
        STATS_COUNTER_ERROR.increment(sAction);
        throw ex;
    }
}
Also used : ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) SignedServiceMetadataType(com.helger.xsds.bdxr.smp1.SignedServiceMetadataType) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) ISMPRedirectManager(com.helger.phoss.smp.domain.redirect.ISMPRedirectManager) SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) ISMPRedirect(com.helger.phoss.smp.domain.redirect.ISMPRedirect) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) SignedServiceMetadataType(com.helger.xsds.bdxr.smp1.SignedServiceMetadataType) ServiceMetadataType(com.helger.xsds.bdxr.smp1.ServiceMetadataType) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) SMPServerException(com.helger.phoss.smp.exception.SMPServerException) Nonnull(javax.annotation.Nonnull)

Aggregations

SMPNotFoundException (com.helger.phoss.smp.exception.SMPNotFoundException)22 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)21 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)17 SMPServerException (com.helger.phoss.smp.exception.SMPServerException)17 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)16 Nonnull (javax.annotation.Nonnull)15 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)14 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)14 ISMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation)11 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)10 ISMPRedirectManager (com.helger.phoss.smp.domain.redirect.ISMPRedirectManager)10 IUser (com.helger.photon.security.user.IUser)8 EChange (com.helger.commons.state.EChange)7 ISMPRedirect (com.helger.phoss.smp.domain.redirect.ISMPRedirect)5 SMPBadRequestException (com.helger.phoss.smp.exception.SMPBadRequestException)5 SMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.SMPServiceGroup)4 SMPSMLException (com.helger.phoss.smp.exception.SMPSMLException)4 IRegistrationHook (com.helger.phoss.smp.smlhook.IRegistrationHook)4 RegistrationHookException (com.helger.phoss.smp.smlhook.RegistrationHookException)4 ICommonsList (com.helger.commons.collection.impl.ICommonsList)3