Search in sources :

Example 31 with IUser

use of com.helger.photon.security.user.IUser in project phoss-smp by phax.

the class SMPRedirectManagerXMLTest method testRedirectBasic.

@Test
public void testRedirectBasic() throws SMPServerException {
    // Ensure the user is present
    final IUser aTestUser = PhotonSecurityManager.getUserMgr().getUserOfID(CSecurity.USER_ADMINISTRATOR_ID);
    assertNotNull(aTestUser);
    final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
    final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
    final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
    assertEquals(0, aRedirectMgr.getSMPRedirectCount());
    // Delete existing service group
    final IParticipantIdentifier aPI = aIdentifierFactory.createParticipantIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "0088:dummy");
    aServiceGroupMgr.deleteSMPServiceGroupNoEx(aPI, true);
    final ISMPServiceGroup aSG = aServiceGroupMgr.createSMPServiceGroup(aTestUser.getID(), aPI, null, true);
    assertNotNull(aSG);
    try {
        final IDocumentTypeIdentifier aDocTypeID = aIdentifierFactory.createDocumentTypeIdentifier(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_BUSDOX_DOCID_QNS, "doctype4711");
        final ISMPRedirect aRedirect = aRedirectMgr.createOrUpdateSMPRedirect(aSG, aDocTypeID, "bla", "foo", null, "<ext/>");
        assertNotNull(aRedirect);
        assertSame(aSG, aRedirect.getServiceGroup());
        assertEquals(aDocTypeID, aRedirect.getDocumentTypeIdentifier());
        assertEquals("bla", aRedirect.getTargetHref());
        assertEquals("foo", aRedirect.getSubjectUniqueIdentifier());
        assertNull(aRedirect.getCertificate());
        assertEquals("<ext />", aRedirect.getFirstExtensionXML().trim());
        XMLTestHelper.testMicroTypeConversion(aRedirect);
    } finally {
        aServiceGroupMgr.deleteSMPServiceGroup(aPI, true);
    }
}
Also used : ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ISMPRedirectManager(com.helger.phoss.smp.domain.redirect.ISMPRedirectManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) ISMPRedirect(com.helger.phoss.smp.domain.redirect.ISMPRedirect) IUser(com.helger.photon.security.user.IUser) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Example 32 with IUser

use of com.helger.photon.security.user.IUser in project phoss-smp by phax.

the class SMPRedirectManagerXMLTest method testRedirectUpperCaseSG.

@Test
public void testRedirectUpperCaseSG() throws SMPServerException {
    // Ensure the user is present
    final IUser aTestUser = PhotonSecurityManager.getUserMgr().getUserOfID(CSecurity.USER_ADMINISTRATOR_ID);
    assertNotNull(aTestUser);
    final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
    assertFalse(aIdentifierFactory.isParticipantIdentifierCaseInsensitive("bla-sch-eme"));
    final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
    final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
    assertEquals(0, aRedirectMgr.getSMPRedirectCount());
    // Delete existing service group
    final IParticipantIdentifier aPI = aIdentifierFactory.createParticipantIdentifier("bla-sch-eme", "0088:UpperCase");
    assertNotNull(aPI);
    aServiceGroupMgr.deleteSMPServiceGroupNoEx(aPI, true);
    final ISMPServiceGroup aSG = aServiceGroupMgr.createSMPServiceGroup(aTestUser.getID(), aPI, null, true);
    assertNotNull(aSG);
    try {
        final IDocumentTypeIdentifier aDocTypeID = aIdentifierFactory.createDocumentTypeIdentifier(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_BUSDOX_DOCID_QNS, "DocType4711");
        final ISMPRedirect aRedirect = aRedirectMgr.createOrUpdateSMPRedirect(aSG, aDocTypeID, "bla", "foo", null, "<ext/>");
        assertNotNull(aRedirect);
        assertSame(aSG, aRedirect.getServiceGroup());
        assertEquals(aDocTypeID, aRedirect.getDocumentTypeIdentifier());
        assertEquals("bla", aRedirect.getTargetHref());
        assertEquals("foo", aRedirect.getSubjectUniqueIdentifier());
        assertNull(aRedirect.getCertificate());
        assertEquals("<ext />", aRedirect.getFirstExtensionXML().trim());
        XMLTestHelper.testMicroTypeConversion(aRedirect);
    } finally {
        aServiceGroupMgr.deleteSMPServiceGroup(aPI, true);
    }
}
Also used : ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ISMPRedirectManager(com.helger.phoss.smp.domain.redirect.ISMPRedirectManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) ISMPRedirect(com.helger.phoss.smp.domain.redirect.ISMPRedirect) IUser(com.helger.photon.security.user.IUser) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Example 33 with IUser

use of com.helger.photon.security.user.IUser in project phoss-smp by phax.

the class SMPServiceInformationManagerXMLTest method testServiceRegistration.

@Test
public void testServiceRegistration() throws SMPServerException {
    // Ensure the user is present
    final IUser aTestUser = PhotonSecurityManager.getUserMgr().getUserOfID(CSecurity.USER_ADMINISTRATOR_ID);
    assertNotNull(aTestUser);
    final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
    final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
    final ISMPServiceInformationManager aServiceInformationMgr = SMPMetaManager.getServiceInformationMgr();
    assertEquals(0, aServiceInformationMgr.getSMPServiceInformationCount());
    // Delete existing service group
    final IParticipantIdentifier aPI = aIdentifierFactory.createParticipantIdentifier(PeppolIdentifierHelper.DEFAULT_PARTICIPANT_SCHEME, "0088:dummy");
    aServiceGroupMgr.deleteSMPServiceGroupNoEx(aPI, true);
    final ISMPServiceGroup aSG = aServiceGroupMgr.createSMPServiceGroup(aTestUser.getID(), aPI, null, true);
    assertNotNull(aSG);
    try {
        final XMLOffsetDateTime aStartDT = PDTFactory.getCurrentXMLOffsetDateTime();
        final XMLOffsetDateTime aEndDT = aStartDT.plusYears(1);
        final IProcessIdentifier aProcessID = aIdentifierFactory.createProcessIdentifier(PeppolIdentifierHelper.DEFAULT_PROCESS_SCHEME, "testproc");
        final IDocumentTypeIdentifier aDocTypeID = aIdentifierFactory.createDocumentTypeIdentifier(PeppolIdentifierHelper.DOCUMENT_TYPE_SCHEME_BUSDOX_DOCID_QNS, "testdoctype");
        {
            // Create a new service information
            final SMPEndpoint aEP = new SMPEndpoint("tp", "http://localhost/as2", false, "minauth", aStartDT, aEndDT, "cert", "sd", "tc", "ti", "<extep />");
            final SMPProcess aProcess = new SMPProcess(aProcessID, new CommonsArrayList<>(aEP), "<extproc />");
            assertTrue(aServiceInformationMgr.mergeSMPServiceInformation(new SMPServiceInformation(aSG, aDocTypeID, new CommonsArrayList<>(aProcess), "<extsi />")).isSuccess());
            assertEquals(1, aServiceInformationMgr.getSMPServiceInformationCount());
            assertEquals(1, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getProcessCount());
            assertEquals(1, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getAllProcesses().get(0).getEndpointCount());
        }
        {
            // Replace endpoint URL with equal transport profile -> replace
            final ISMPServiceInformation aSI = aServiceInformationMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aSG, aDocTypeID);
            assertNotNull(aSI);
            final ISMPProcess aProcess = aSI.getProcessOfID(aProcessID);
            assertNotNull(aProcess);
            aProcess.setEndpoint(new SMPEndpoint("tp", "http://localhost/as2-ver2", false, "minauth", aStartDT, aEndDT, "cert", "sd", "tc", "ti", "<extep />"));
            assertTrue(aServiceInformationMgr.mergeSMPServiceInformation(aSI).isSuccess());
            assertEquals(1, aServiceInformationMgr.getSMPServiceInformationCount());
            assertEquals(1, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getProcessCount());
            assertEquals(1, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getAllProcesses().get(0).getEndpointCount());
            assertEquals("http://localhost/as2-ver2", CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getAllProcesses().get(0).getAllEndpoints().get(0).getEndpointReference());
        }
        {
            // Add endpoint with different transport profile -> added to existing
            // process
            final ISMPServiceInformation aSI = aServiceInformationMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aSG, aDocTypeID);
            assertNotNull(aSI);
            final ISMPProcess aProcess = aSI.getProcessOfID(aProcessID);
            assertNotNull(aProcess);
            aProcess.addEndpoint(new SMPEndpoint("tp2", "http://localhost/as2-tp2", false, "minauth", aStartDT, aEndDT, "cert", "sd", "tc", "ti", "<extep />"));
            assertTrue(aServiceInformationMgr.mergeSMPServiceInformation(aSI).isSuccess());
            assertEquals(1, aServiceInformationMgr.getSMPServiceInformationCount());
            assertEquals(1, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getProcessCount());
            assertEquals(2, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getAllProcesses().get(0).getEndpointCount());
        }
        {
            // Add endpoint with different process - add to existing
            // serviceGroup+docType part
            final ISMPServiceInformation aSI = aServiceInformationMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aSG, aDocTypeID);
            assertNotNull(aSI);
            final SMPEndpoint aEP = new SMPEndpoint("tp", "http://localhost/as2", false, "minauth", aStartDT, aEndDT, "cert", "sd", "tc", "ti", "<extep />");
            aSI.addProcess(new SMPProcess(PeppolIdentifierFactory.INSTANCE.createProcessIdentifierWithDefaultScheme("testproc2"), new CommonsArrayList<>(aEP), "<extproc />"));
            assertTrue(aServiceInformationMgr.mergeSMPServiceInformation(aSI).isSuccess());
            assertEquals(1, aServiceInformationMgr.getSMPServiceInformationCount());
            assertEquals(2, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getProcessCount());
            assertEquals(2, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getAllProcesses().get(0).getEndpointCount());
            assertEquals(1, CollectionHelper.getFirstElement(aServiceInformationMgr.getAllSMPServiceInformation()).getAllProcesses().get(1).getEndpointCount());
        }
    } finally {
        aServiceGroupMgr.deleteSMPServiceGroup(aPI, true);
    }
}
Also used : ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) XMLOffsetDateTime(com.helger.commons.datetime.XMLOffsetDateTime) SMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) SMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) IProcessIdentifier(com.helger.peppolid.IProcessIdentifier) SMPProcess(com.helger.phoss.smp.domain.serviceinfo.SMPProcess) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) IUser(com.helger.photon.security.user.IUser) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) ISMPProcess(com.helger.phoss.smp.domain.serviceinfo.ISMPProcess) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Example 34 with IUser

use of com.helger.photon.security.user.IUser in project phoss-smp by phax.

the class SMPServiceGroupFuncTest method testBasic.

@Test
public void testBasic() {
    final IUser aTestUser = PhotonSecurityManager.getUserMgr().getUserOfID(CSecurity.USER_ADMINISTRATOR_ID);
    assertNotNull(aTestUser);
    final IParticipantIdentifier aPI = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("0088:dummy");
    final SMPServiceGroup aSG = new SMPServiceGroup(CSecurity.USER_ADMINISTRATOR_ID, aPI, null);
    XMLTestHelper.testMicroTypeConversion(aSG);
}
Also used : IUser(com.helger.photon.security.user.IUser) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Example 35 with IUser

use of com.helger.photon.security.user.IUser in project phoss-smp by phax.

the class SMPUserManagerPhoton method validateUserCredentials.

/**
 * Check if the provided credentials are valid. This checks if the user
 * exists, if it is not deleted, if the password matches and if the user is
 * not disabled. If valid, the resolved user is returned.
 *
 * @param aCredentials
 *        The credentials to check. May not be <code>null</code>.
 * @return <code>null</code> if something does wrong, the user on success
 *         only.
 * @throws SMPUnknownUserException
 *         if the user does not exist or if the user is marked as deleted.
 * @throws SMPUnauthorizedException
 *         If the password is invalid or if the user is marked as disabled
 */
@Nonnull
public static IUser validateUserCredentials(@Nonnull final BasicAuthClientCredentials aCredentials) throws SMPUnknownUserException, SMPUnauthorizedException {
    final IUserManager aUserMgr = PhotonSecurityManager.getUserMgr();
    final IUser aUser = aUserMgr.getUserOfLoginName(aCredentials.getUserName());
    if (aUser == null || aUser.isDeleted()) {
        // Deleted users are handled like non-existing users
        LOGGER.warn("Invalid login name provided: '" + aCredentials.getUserName() + "'");
        throw new SMPUnknownUserException(aCredentials.getUserName());
    }
    if (!aUserMgr.areUserIDAndPasswordValid(aUser.getID(), aCredentials.getPassword())) {
        LOGGER.warn("Invalid password provided for '" + aCredentials.getUserName() + "'");
        throw new SMPUnauthorizedException("Username and/or password are invalid!");
    }
    if (aUser.isDisabled()) {
        LOGGER.warn("User '" + aCredentials.getUserName() + "' is disabled");
        throw new SMPUnauthorizedException("User is disabled!");
    }
    return aUser;
}
Also used : IUserManager(com.helger.photon.security.user.IUserManager) IUser(com.helger.photon.security.user.IUser) SMPUnknownUserException(com.helger.phoss.smp.exception.SMPUnknownUserException) SMPUnauthorizedException(com.helger.phoss.smp.exception.SMPUnauthorizedException) Nonnull(javax.annotation.Nonnull)

Aggregations

IUser (com.helger.photon.security.user.IUser)44 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)25 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)22 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)20 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)19 Nonnull (javax.annotation.Nonnull)18 SMPServerException (com.helger.phoss.smp.exception.SMPServerException)17 Locale (java.util.Locale)14 ISMPRedirectManager (com.helger.phoss.smp.domain.redirect.ISMPRedirectManager)11 IRequestWebScopeWithoutResponse (com.helger.web.scope.IRequestWebScopeWithoutResponse)9 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)8 BootstrapButton (com.helger.photon.bootstrap4.button.BootstrapButton)8 HCStrong (com.helger.html.hc.html.textlevel.HCStrong)7 HCNodeList (com.helger.html.hc.impl.HCNodeList)7 ISMPRedirect (com.helger.phoss.smp.domain.redirect.ISMPRedirect)7 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)7 SMPBadRequestException (com.helger.phoss.smp.exception.SMPBadRequestException)7 SMPNotFoundException (com.helger.phoss.smp.exception.SMPNotFoundException)7 IUserManager (com.helger.photon.security.user.IUserManager)7 IMicroDocument (com.helger.xml.microdom.IMicroDocument)6