SMPClient extends SMPClientReadOnly { public void saveServiceGroup (@Nonnull final ServiceGroupType aServiceGroup, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPClientException { ValueEnforcer.notNull (aServiceGroup, "ServiceGroup"); ValueEnforcer.notNull (aCredentials, "Credentials"); final String sBody = new SMPMarshallerServiceGroupType (isXMLSchemaValidation ()).getAsString (aServiceGroup); if (sBody == null) throw new IllegalArgumentException ("Failed to serialize ServiceGroup: " + aServiceGroup); final String sURI = getSMPHostURI () + CIdentifier.getURIPercentEncoded (aServiceGroup.getParticipantIdentifier ()); if (LOGGER.isDebugEnabled ()) LOGGER.debug ("SMPClient saveServiceGroup@" + sURI); final HttpPut aRequest = new HttpPut (sURI); aRequest.addHeader (CHttpHeader.AUTHORIZATION, aCredentials.getRequestValue ()); aRequest.setEntity (new StringEntity (sBody, CONTENT_TYPE_TEXT_XML)); executeGenericRequest (aRequest, new SMPHttpResponseHandlerWriteOperations ()); } SMPClient(@Nonnull final ISMPURLProvider aURLProvider,
                    @Nonnull final IParticipantIdentifier aParticipantIdentifier,
                    @Nonnull final ISMLInfo aSMLInfo);  SMPClient(@Nonnull final ISMPURLProvider aURLProvider,
                    @Nonnull final IParticipantIdentifier aParticipantIdentifier,
                    @Nonnull @Nonempty final String sSMLZoneName);  SMPClient(@Nonnull final URI aSMPHost); void saveServiceGroup(@Nonnull final ServiceGroupType aServiceGroup,
                                @Nonnull final BasicAuthClientCredentials aCredentials); @Nonnull ServiceGroupType saveServiceGroup(@Nonnull final IParticipantIdentifier aParticipantID,
                                            @Nonnull final BasicAuthClientCredentials aCredentials); void deleteServiceGroup(@Nonnull final IParticipantIdentifier aServiceGroupID,
                                  @Nonnull final BasicAuthClientCredentials aCredentials); void saveServiceInformation(@Nonnull final ServiceInformationType aServiceInformation,
                                      @Nonnull final BasicAuthClientCredentials aCredentials); void saveServiceRedirect(@Nonnull final IParticipantIdentifier aServiceGroupID,
                                   @Nonnull final IDocumentTypeIdentifier aDocumentTypeID,
                                   @Nonnull final RedirectType aRedirect,
                                   @Nonnull final BasicAuthClientCredentials aCredentials); void deleteServiceRegistration(@Nonnull final IParticipantIdentifier aServiceGroupID,
                                         @Nonnull final IDocumentTypeIdentifier aDocumentTypeID,
                                         @Nonnull final BasicAuthClientCredentials aCredentials);  }
@Test public void testUnauthorizedUser () throws SMPClientException { final SMPClient aSMPClient = new SMPClient (SMP_URI); final BasicAuthClientCredentials aCredentials = new BasicAuthClientCredentials (SMP_USERNAME + "wronguser", SMP_PASSWORD); try { aSMPClient.saveServiceGroup (MockSMPClientConfig.getParticipantID (), aCredentials); fail (); } catch (final SMPClientUnauthorizedException ex) {} }
@Test public void testUnauthorizedPassword () throws SMPClientException { final SMPClient aSMPClient = new SMPClient (SMP_URI); final BasicAuthClientCredentials aCredentials = new BasicAuthClientCredentials (SMP_USERNAME, SMP_PASSWORD + "wrongpass"); try { aSMPClient.saveServiceGroup (MockSMPClientConfig.getParticipantID (), aCredentials); fail (); } catch (final SMPClientUnauthorizedException ex) {} }