use of com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup in project phoss-smp by phax.
the class SMPServiceInformationMicroTypeConverter method convertToNative.
@Nonnull
public static SMPServiceInformation convertToNative(@Nonnull final IMicroElement aElement, @Nonnull final ISMPServiceGroupProvider aSGProvider) {
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final String sServiceGroupID = aElement.getAttributeValue(ATTR_SERVICE_GROUP_ID);
final ISMPServiceGroup aServiceGroup = aSGProvider.getSMPServiceGroupOfID(aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID));
if (aServiceGroup == null)
throw new IllegalStateException("Failed to resolve service group with ID '" + sServiceGroupID + "'");
final SimpleDocumentTypeIdentifier aDocTypeIdentifier = MicroTypeConverter.convertToNative(aElement.getFirstChildElement(ELEMENT_DOCUMENT_TYPE_IDENTIFIER), SimpleDocumentTypeIdentifier.class);
final ICommonsList<SMPProcess> aProcesses = new CommonsArrayList<>();
for (final IMicroElement aProcess : aElement.getAllChildElements(ELEMENT_PROCESS)) aProcesses.add(MicroTypeConverter.convertToNative(aProcess, SMPProcess.class));
final String sExtension = MicroHelper.getChildTextContentTrimmed(aElement, ELEMENT_EXTENSION);
return new SMPServiceInformation(aServiceGroup, aDocTypeIdentifier, aProcesses, sExtension);
}
use of com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup in project phoss-smp by phax.
the class SMPRedirectMicroTypeConverter method convertToNative.
@Nonnull
public static SMPRedirect convertToNative(@Nonnull final IMicroElement aElement, @Nonnull final ISMPServiceGroupProvider aSGProvider) {
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final String sServiceGroupID = aElement.getAttributeValue(ATTR_SERVICE_GROUPD_ID);
final ISMPServiceGroup aServiceGroup = aSGProvider.getSMPServiceGroupOfID(aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID));
if (aServiceGroup == null)
throw new IllegalStateException("Failed to resolve service group with ID '" + sServiceGroupID + "'");
final SimpleDocumentTypeIdentifier aDocTypeIdentifier = MicroTypeConverter.convertToNative(aElement.getFirstChildElement(ELEMENT_DOCUMENT_TYPE_IDENTIFIER), SimpleDocumentTypeIdentifier.class);
final String sTargetHref = aElement.getAttributeValue(ATTR_TARGET_HREF);
final String sSubjectUniqueIdentifier = MicroHelper.getChildTextContentTrimmed(aElement, ELEMENT_CERTIFICATE_SUID);
final X509Certificate aCertificate = CertificateHelper.convertStringToCertficateOrNull(MicroHelper.getChildTextContentTrimmed(aElement, ELEMENT_CERTIFICATE));
final String sExtension = MicroHelper.getChildTextContentTrimmed(aElement, ELEMENT_EXTENSION);
return new SMPRedirect(aServiceGroup, aDocTypeIdentifier, sTargetHref, sSubjectUniqueIdentifier, aCertificate, sExtension);
}
use of com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup in project phoss-smp by phax.
the class APIExecutorExportByOwnerXMLVer1 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 sPathUserLoginName = aPathVariables.get(SMPRestFilter.PARAM_USER_ID);
final String sLogPrefix = "[REST API Export-ByOwner-XML-V1] ";
LOGGER.info(sLogPrefix + "Starting Export for all of owner '" + sPathUserLoginName + "'");
// Only authenticated user may do so
final BasicAuthClientCredentials aBasicAuth = getMandatoryAuth(aRequestScope.headers());
final IUser aUser = SMPUserManagerPhoton.validateUserCredentials(aBasicAuth);
// Start action after authentication
final ISMPSettingsManager aSettingsMgr = SMPMetaManager.getSettingsMgr();
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, null);
if (!aBasicAuth.getUserName().equals(sPathUserLoginName)) {
throw new SMPUnauthorizedException("URL user '" + sPathUserLoginName + "' does not match HTTP Basic Auth user name '" + aBasicAuth.getUserName() + "'", aDataProvider.getCurrentURI());
}
// Now get all relevant service groups
final ICommonsList<ISMPServiceGroup> aAllServiceGroups = aServiceGroupMgr.getAllSMPServiceGroupsOfOwner(aUser.getID());
final boolean bIncludeBusinessCards = aRequestScope.params().getAsBoolean(PARAM_INCLUDE_BUSINESS_CARDS, aSettingsMgr.getSettings().isDirectoryIntegrationEnabled());
final IMicroDocument aDoc = ServiceGroupExport.createExportDataXMLVer10(aAllServiceGroups, 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.domain.servicegroup.ISMPServiceGroup in project phoss-smp by phax.
the class APIExecutorExportOutboundMigrationInProcessXMLVer 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 sLogPrefix = "[REST API Export-OutboundMigrationInProcess-XML-V1] ";
LOGGER.info(sLogPrefix + "Starting Export for all with outbound migration state 'in progress'");
// 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 ISMPParticipantMigrationManager aParticipantMigrationMgr = SMPMetaManager.getParticipantMigrationMgr();
final ICommonsList<ISMPParticipantMigration> aAllMigrations = aParticipantMigrationMgr.getAllOutboundParticipantMigrations(EParticipantMigrationState.IN_PROGRESS);
// Now get all relevant service groups
final ICommonsList<ISMPServiceGroup> aAllServiceGroups = new CommonsArrayList<>();
for (final ISMPParticipantMigration aMigration : aAllMigrations) {
final ISMPServiceGroup aSG = aServiceGroupMgr.getSMPServiceGroupOfID(aMigration.getParticipantIdentifier());
if (aSG != null)
aAllServiceGroups.add(aSG);
else
LOGGER.warn(sLogPrefix + "Failed to resolve PID '" + aMigration.getParticipantIdentifier().getURIEncoded() + "' to a Service Group");
}
final boolean bIncludeBusinessCards = aRequestScope.params().getAsBoolean(PARAM_INCLUDE_BUSINESS_CARDS, aSettingsMgr.getSettings().isDirectoryIntegrationEnabled());
final IMicroDocument aDoc = ServiceGroupExport.createExportDataXMLVer10(aAllServiceGroups, 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.domain.servicegroup.ISMPServiceGroup in project phoss-smp by phax.
the class APIExecutorMigrationInboundFromPathPut method migrationInbound.
public static void migrationInbound(@Nonnull final String sServiceGroupID, @Nonnull final String sMigrationKey, @Nonnull final String sLogPrefix, @Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final UnifiedResponse aUnifiedResponse) throws SMPServerException, GeneralSecurityException {
LOGGER.info(sLogPrefix + "Starting inbound migration for Service Group ID '" + sServiceGroupID + "' and migration key '" + sMigrationKey + "'");
// Only authenticated user may do so
final BasicAuthClientCredentials aBasicAuth = getMandatoryAuth(aRequestScope.headers());
final IUser aOwningUser = SMPUserManagerPhoton.validateUserCredentials(aBasicAuth);
final ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, sServiceGroupID);
final ISMPSettings aSettings = SMPMetaManager.getSettings();
final ISMLInfo aSMLInfo = aSettings.getSMLInfo();
final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
final ISMPParticipantMigrationManager aParticipantMigrationMgr = SMPMetaManager.getParticipantMigrationMgr();
if (aSMLInfo == null) {
throw new SMPPreconditionFailedException("Currently no SML is available. Please select it in the UI at the 'SMP Settings' page", aDataProvider.getCurrentURI());
}
if (!aSettings.isSMLEnabled()) {
throw new SMPPreconditionFailedException("SML Connection is not enabled hence no participant can be migrated", aDataProvider.getCurrentURI());
}
final IParticipantIdentifier aParticipantID = aIdentifierFactory.parseParticipantIdentifier(sServiceGroupID);
if (aParticipantID == null) {
// Invalid identifier
throw SMPBadRequestException.failedToParseSG(sServiceGroupID, aDataProvider.getCurrentURI());
}
// Check that service group does not exist yet
if (aServiceGroupMgr.containsSMPServiceGroupWithID(aParticipantID)) {
throw new SMPBadRequestException("The Service Group '" + sServiceGroupID + "' already exists.", aDataProvider.getCurrentURI());
}
if (false) {
// valid
if (aParticipantMigrationMgr.containsInboundMigration(aParticipantID)) {
throw new SMPBadRequestException("The inbound migration of the Service Group '" + sServiceGroupID + "' is already contained.", aDataProvider.getCurrentURI());
}
}
// create the Service Group locally
try {
final ManageParticipantIdentifierServiceCaller aCaller = new ManageParticipantIdentifierServiceCaller(aSettings.getSMLInfo());
aCaller.setSSLSocketFactory(SMPKeyManager.getInstance().createSSLContext().getSocketFactory());
// SML call
aCaller.migrate(aParticipantID, sMigrationKey, SMPServerConfiguration.getSMLSMPID());
LOGGER.info(sLogPrefix + "Successfully migrated '" + aParticipantID.getURIEncoded() + "' in the SML to this SMP using migration key '" + sMigrationKey + "'");
} catch (final BadRequestFault | InternalErrorFault | NotFoundFault | UnauthorizedFault | ClientTransportException ex) {
throw new SMPSMLException("Failed to confirm the migration for participant '" + aParticipantID.getURIEncoded() + "' in SML, hence the migration failed." + " Please check the participant identifier and the migration key.", ex);
}
// Now create the service group locally (it was already checked that the
// PID is available on this SMP)
ISMPServiceGroup aSG = null;
Exception aCaughtEx = null;
try {
// Do not allow any Extension here
// Do NOT create in SMK/SML
aSG = aServiceGroupMgr.createSMPServiceGroup(aOwningUser.getID(), aParticipantID, (String) null, false);
} catch (final Exception ex) {
aCaughtEx = ex;
}
if (aSG != null) {
LOGGER.info(sLogPrefix + "The new SMP Service Group for participant '" + aParticipantID.getURIEncoded() + "' was successfully created.");
} else {
// No exception here
LOGGER.error(sLogPrefix + "Error creating the new SMP Service Group for participant '" + aParticipantID.getURIEncoded() + "'.", aCaughtEx);
}
// Remember internally
final ISMPParticipantMigration aMigration = aParticipantMigrationMgr.createInboundParticipantMigration(aParticipantID, sMigrationKey);
if (aMigration != null) {
LOGGER.info(sLogPrefix + "The participant migration for '" + aParticipantID.getURIEncoded() + "' with migration key '" + sMigrationKey + "' was successfully performed. Please inform the source SMP that the migration was successful.");
} else {
// No exception here
LOGGER.error(sLogPrefix + "Failed to store the participant migration for '" + aParticipantID.getURIEncoded() + "'.");
}
final IMicroDocument aResponseDoc = new MicroDocument();
final IMicroElement eRoot = aResponseDoc.appendElement("migrationInboundResponse");
eRoot.setAttribute("success", aSG != null && aMigration != null);
eRoot.setAttribute("serviceGroupCreated", aSG != null);
eRoot.setAttribute("migrationCreated", aMigration != null);
final XMLWriterSettings aXWS = new XMLWriterSettings().setIndent(EXMLSerializeIndent.INDENT_AND_ALIGN);
aUnifiedResponse.setContentAndCharset(MicroWriter.getNodeAsString(aResponseDoc, aXWS), aXWS.getCharset()).setMimeType(new MimeType(CMimeType.APPLICATION_XML).addParameter(CMimeType.PARAMETER_NAME_CHARSET, aXWS.getCharset().name())).disableCaching();
}
Aggregations