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;
}
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();
}
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;
}
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() + "'");
}
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;
}
}
Aggregations