Search in sources :

Example 6 with SMPUnauthorizedException

use of com.helger.phoss.smp.exception.SMPUnauthorizedException 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();
}
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) BasicAuthClientCredentials(com.helger.http.basicauth.BasicAuthClientCredentials) ISMPServerAPIDataProvider(com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider) IUser(com.helger.photon.security.user.IUser) IMicroDocument(com.helger.xml.microdom.IMicroDocument) SMPUnauthorizedException(com.helger.phoss.smp.exception.SMPUnauthorizedException)

Aggregations

SMPUnauthorizedException (com.helger.phoss.smp.exception.SMPUnauthorizedException)6 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)4 IUser (com.helger.photon.security.user.IUser)4 Nonnull (javax.annotation.Nonnull)4 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)3 BasicAuthClientCredentials (com.helger.http.basicauth.BasicAuthClientCredentials)2 SMPServerException (com.helger.phoss.smp.exception.SMPServerException)2 CMimeType (com.helger.commons.mime.CMimeType)1 MimeType (com.helger.commons.mime.MimeType)1 SMPNotFoundException (com.helger.phoss.smp.exception.SMPNotFoundException)1 SMPUnknownUserException (com.helger.phoss.smp.exception.SMPUnknownUserException)1 ISMPServerAPIDataProvider (com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider)1 ISMPSettingsManager (com.helger.phoss.smp.settings.ISMPSettingsManager)1 IUserManager (com.helger.photon.security.user.IUserManager)1 IMicroDocument (com.helger.xml.microdom.IMicroDocument)1 IXMLWriterSettings (com.helger.xml.serialize.write.IXMLWriterSettings)1 XMLWriterSettings (com.helger.xml.serialize.write.XMLWriterSettings)1 ServiceGroupReferenceListType (com.helger.xsds.bdxr.smp1.ServiceGroupReferenceListType)1 ServiceGroupReferenceType (com.helger.xsds.bdxr.smp1.ServiceGroupReferenceType)1 ServiceGroupReferenceListType (com.helger.xsds.peppol.smp1.ServiceGroupReferenceListType)1