Search in sources :

Example 1 with IUser

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

the class SecureHTMLProvider method _getNavbar.

@Nonnull
private static IHCNode _getNavbar(@Nonnull final SimpleWebExecutionContext aSWEC) {
    final Locale aDisplayLocale = aSWEC.getDisplayLocale();
    final IRequestWebScopeWithoutResponse aRequestScope = aSWEC.getRequestScope();
    final ISimpleURL aLinkToStartPage = aSWEC.getLinkToMenuItem(aSWEC.getMenuTree().getDefaultMenuItemID());
    final BootstrapNavbar aNavbar = new BootstrapNavbar();
    aNavbar.addBrand(new HCNodeList().addChild(new HCSpan().addClass(AppCommonUI.CSS_CLASS_LOGO1).addChild(CPDPublisher.getApplicationTitle())).addChild(new HCSpan().addClass(AppCommonUI.CSS_CLASS_LOGO2).addChild(" Administration")), aLinkToStartPage);
    final BootstrapNavbarToggleable aToggleable = aNavbar.addAndReturnToggleable();
    {
        final IUser aUser = LoggedInUserManager.getInstance().getCurrentUser();
        aToggleable.addAndReturnText().addClass(CBootstrapCSS.ML_AUTO).addClass(CBootstrapCSS.MX_2).addChild("Welcome ").addChild(new HCStrong().addChild(SecurityHelper.getUserDisplayName(aUser, aDisplayLocale)));
        aToggleable.addChild(new BootstrapButton().addClass(CBootstrapCSS.MX_2).addChild("Goto public area").setOnClick(LinkHelper.getURLWithContext(AbstractPublicApplicationServlet.SERVLET_DEFAULT_PATH + "/")));
        aToggleable.addChild(new BootstrapButton().addClass(CBootstrapCSS.MX_2).setOnClick(LinkHelper.getURLWithContext(aRequestScope, LogoutServlet.SERVLET_DEFAULT_PATH)).addChild(EPhotonCoreText.LOGIN_LOGOUT.getDisplayText(aDisplayLocale)));
    }
    return aNavbar;
}
Also used : Locale(java.util.Locale) IRequestWebScopeWithoutResponse(com.helger.web.scope.IRequestWebScopeWithoutResponse) HCSpan(com.helger.html.hc.html.textlevel.HCSpan) HCStrong(com.helger.html.hc.html.textlevel.HCStrong) HCNodeList(com.helger.html.hc.impl.HCNodeList) BootstrapNavbar(com.helger.photon.bootstrap4.navbar.BootstrapNavbar) ISimpleURL(com.helger.commons.url.ISimpleURL) BootstrapNavbarToggleable(com.helger.photon.bootstrap4.navbar.BootstrapNavbarToggleable) IUser(com.helger.photon.security.user.IUser) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) Nonnull(javax.annotation.Nonnull)

Example 2 with IUser

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

the class SMPRedirectManagerMongoDBTest 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());
    } 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 3 with IUser

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

the class SMPRendererPublic method _addNavbarLoginLogout.

private static void _addNavbarLoginLogout(@Nonnull final ILayoutExecutionContext aLEC, @Nonnull final BootstrapNavbar aNavbar) {
    if (!SMPWebAppConfiguration.isPublicLoginEnabled())
        return;
    final IRequestWebScopeWithoutResponse aRequestScope = aLEC.getRequestScope();
    final IUser aUser = aLEC.getLoggedInUser();
    final BootstrapNavbarToggleable aToggleable = aNavbar.addAndReturnToggleable();
    if (aUser != null) {
        final Locale aDisplayLocale = aLEC.getDisplayLocale();
        aToggleable.addChild(new BootstrapButton().addClass(CBootstrapCSS.ML_AUTO).addClass(CBootstrapCSS.MR_2).addChild("Goto manager").setOnClick(LinkHelper.getURLWithContext(AbstractSecureApplicationServlet.SERVLET_DEFAULT_PATH + "/")));
        aToggleable.addAndReturnText().addClass(CBootstrapCSS.MX_2).addChild("Logged in as ").addChild(new HCStrong().addChild(SecurityHelper.getUserDisplayName(aUser, aDisplayLocale)));
        aToggleable.addChild(new BootstrapButton().addClass(CBootstrapCSS.MX_2).setOnClick(LinkHelper.getURLWithContext(aRequestScope, SMPLogoutServlet.SERVLET_DEFAULT_PATH)).addChild(EPhotonCoreText.LOGIN_LOGOUT.getDisplayText(aDisplayLocale)));
    } else {
        final BootstrapNavbarNav aNav = aToggleable.addAndReturnNav();
        final BootstrapDropdownMenu aDropDown = new BootstrapDropdownMenu();
        {
            final HCDiv aDiv = new HCDiv().addClass(CBootstrapCSS.P_2).addStyle(CCSSProperties.MIN_WIDTH.newValue("400px"));
            aDiv.addChild(SMPCommonUI.createViewLoginForm(aLEC, null));
            aDropDown.addChild(aDiv);
        }
        aNav.addItem().addNavDropDown("Login", aDropDown);
    }
}
Also used : Locale(java.util.Locale) HCDiv(com.helger.html.hc.html.grouping.HCDiv) IRequestWebScopeWithoutResponse(com.helger.web.scope.IRequestWebScopeWithoutResponse) HCStrong(com.helger.html.hc.html.textlevel.HCStrong) BootstrapNavbarNav(com.helger.photon.bootstrap4.navbar.BootstrapNavbarNav) BootstrapDropdownMenu(com.helger.photon.bootstrap4.dropdown.BootstrapDropdownMenu) IUser(com.helger.photon.security.user.IUser) BootstrapNavbarToggleable(com.helger.photon.bootstrap4.navbar.BootstrapNavbarToggleable) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton)

Example 4 with IUser

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

the class V15__MigrateDBUsersToPhotonUsers method migrate.

public void migrate(@Nonnull final Context context) throws Exception {
    try (final WebScoped aWS = new WebScoped()) {
        LOGGER.info("Migrating all old DB users to ph-oton users");
        final EDatabaseType eDBType = SMPDataSourceSingleton.getDatabaseType();
        // Old JDBC user manager
        final SMPUserManagerJDBC aSQLUserMgr = new SMPUserManagerJDBC(SMPDBExecutor::new);
        final ICommonsList<DBUser> aSQLUsers = aSQLUserMgr.getAllUsers();
        LOGGER.info("Found " + aSQLUsers.size() + " DB user to migrate");
        final ICommonsOrderedMap<String, String> aCreatedMappings = new CommonsLinkedHashMap<>();
        // New JDBC user manager
        final IUserManager aPhotonUserMgr = PhotonSecurityManager.getUserMgr();
        for (final DBUser aSQLUser : aSQLUsers) {
            final DBUser aDBUser = aSQLUser;
            IUser aPhotonUser = null;
            int nIndex = 0;
            while (true) {
                final String sUserName = aDBUser.getUserName() + (nIndex > 0 ? Integer.toString(nIndex) : "");
                // The suffix "@example.org" is added to make it an email-address
                final String sEmailAddress = sUserName + "@example.org";
                aPhotonUser = aPhotonUserMgr.createNewUser(sEmailAddress, sEmailAddress, aDBUser.getPassword(), null, sUserName, null, CSMPServer.DEFAULT_LOCALE, null, false);
                if (aPhotonUser != null) {
                    // New user was successfully created
                    break;
                }
                // User name already taken
                ++nIndex;
                if (nIndex > 1000) {
                    // Avoid endless loop
                    throw new IllegalStateException("Too many iterations mapping the DB user '" + aDBUser.getUserName() + "' to a ph-oton user");
                }
            }
            aCreatedMappings.put(aDBUser.getUserName(), aPhotonUser.getID());
            LOGGER.info("Mapped DB user '" + aDBUser.getUserName() + "' to ph-oton user " + aPhotonUser.getID());
        }
        // Update the ownership in "smp_ownership"
        // Remove the table "smp_user"
        aSQLUserMgr.updateOwnershipsAndKillUsers(aCreatedMappings);
        if (XMLMapHandler.writeMap(aCreatedMappings, new FileSystemResource(WebFileIO.getDataIO().getFile("migrations/db-photon-user-mapping-" + eDBType.getID() + ".xml"))).isFailure())
            LOGGER.error("Failed to store mapping of DB users to ph-oton users as XML");
        LOGGER.info("Finished migrating all DB users to ph-oton users");
    }
}
Also used : WebScoped(com.helger.web.scope.mgr.WebScoped) CommonsLinkedHashMap(com.helger.commons.collection.impl.CommonsLinkedHashMap) IUserManager(com.helger.photon.security.user.IUserManager) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) SMPDBExecutor(com.helger.phoss.smp.backend.sql.SMPDBExecutor) IUser(com.helger.photon.security.user.IUser) DBUser(com.helger.phoss.smp.backend.sql.domain.DBUser) EDatabaseType(com.helger.phoss.smp.backend.sql.EDatabaseType)

Example 5 with IUser

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

the class SMPServiceGroupMicroTypeConverter method convertToNative.

@Nonnull
public static SMPServiceGroup convertToNative(@Nonnull final IMicroElement aElement, @Nonnull final Function<String, IUser> aOwningUserProvider) {
    final String sOwnerID = aElement.getAttributeValue(ATTR_OWNER_ID);
    final IUser aOwner = aOwningUserProvider.apply(sOwnerID);
    if (aOwner == null)
        throw new IllegalStateException("Failed to resolve user ID '" + sOwnerID + "'");
    final SimpleParticipantIdentifier aParticipantIdentifier = MicroTypeConverter.convertToNative(aElement.getFirstChildElement(ELEMENT_PARTICIPANT_ID), SimpleParticipantIdentifier.class);
    if (aParticipantIdentifier == null)
        throw new IllegalStateException("Failed to parse participant identifier " + MicroHelper.getChildTextContent(aElement, ELEMENT_PARTICIPANT_ID));
    final String sExtension = MicroHelper.getChildTextContentTrimmed(aElement, ELEMENT_EXTENSION);
    // Use the new ID in case the ID was changed!
    return new SMPServiceGroup(aOwner.getID(), aParticipantIdentifier, sExtension);
}
Also used : IUser(com.helger.photon.security.user.IUser) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) Nonnull(javax.annotation.Nonnull)

Aggregations

IUser (com.helger.photon.security.user.IUser)35 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 SMPServerException (com.helger.phoss.smp.exception.SMPServerException)17 Nonnull (javax.annotation.Nonnull)13 ISMPRedirectManager (com.helger.phoss.smp.domain.redirect.ISMPRedirectManager)11 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)8 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 EChange (com.helger.commons.state.EChange)6 IMicroDocument (com.helger.xml.microdom.IMicroDocument)6 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)5 ISMPBusinessCardManager (com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager)5 ISMPServiceInformation (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation)5 IUserManager (com.helger.photon.security.user.IUserManager)5 IRequestWebScopeWithoutResponse (com.helger.web.scope.IRequestWebScopeWithoutResponse)5