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;
}
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);
}
}
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);
}
}
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");
}
}
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);
}
Aggregations