Search in sources :

Example 6 with IUserManager

use of com.helger.photon.security.user.IUserManager in project peppol-practical by phax.

the class AppSecurity method init.

public static void init() {
    final IUserManager aUserMgr = PhotonSecurityManager.getUserMgr();
    final IUserGroupManager aUserGroupMgr = PhotonSecurityManager.getUserGroupMgr();
    final IRoleManager aRoleMgr = PhotonSecurityManager.getRoleMgr();
    // Standard users
    if (!aUserMgr.containsWithID(CPPApp.USER_ADMINISTRATOR_ID)) {
        final boolean bDisabled = false;
        aUserMgr.createPredefinedUser(CPPApp.USER_ADMINISTRATOR_ID, CPPApp.USER_ADMINISTRATOR_LOGINNAME, CPPApp.USER_ADMINISTRATOR_EMAIL, CPPApp.USER_ADMINISTRATOR_PASSWORD, CPPApp.USER_ADMINISTRATOR_FIRSTNAME, CPPApp.USER_ADMINISTRATOR_LASTNAME, CPPApp.USER_ADMINISTRATOR_DESCRIPTION, CPPApp.USER_ADMINISTRATOR_LOCALE, CPPApp.USER_ADMINISTRATOR_CUSTOMATTRS, bDisabled);
    }
    // Create all roles
    if (!aRoleMgr.containsWithID(CPPApp.ROLE_CONFIG_ID))
        aRoleMgr.createPredefinedRole(CPPApp.ROLE_CONFIG_ID, CPPApp.ROLE_CONFIG_NAME, CPPApp.ROLE_CONFIG_DESCRIPTION, CPPApp.ROLE_CONFIG_CUSTOMATTRS);
    if (!aRoleMgr.containsWithID(CPPApp.ROLE_VIEW_ID))
        aRoleMgr.createPredefinedRole(CPPApp.ROLE_VIEW_ID, CPPApp.ROLE_VIEW_NAME, CPPApp.ROLE_VIEW_DESCRIPTION, CPPApp.ROLE_VIEW_CUSTOMATTRS);
    if (!aRoleMgr.containsWithID(CPPApp.ROLE_COMMENT_MODERATOR_ID))
        aRoleMgr.createPredefinedRole(CPPApp.ROLE_COMMENT_MODERATOR_ID, CPPApp.ROLE_COMMENT_MODERATOR_NAME, CPPApp.ROLE_COMMENT_MODERATOR_DESCRIPTION, CPPApp.ROLE_COMMENT_MODERATOR_CUSTOMATTRS);
    if (!aRoleMgr.containsWithID(CPPApp.ROLE_PEPPOL_SENDERS_ID))
        aRoleMgr.createPredefinedRole(CPPApp.ROLE_PEPPOL_SENDERS_ID, CPPApp.ROLE_PEPPOL_SENDERS_NAME, CPPApp.ROLE_PEPPOL_SENDERS_DESCRIPTION, CPPApp.ROLE_PEPPOL_SENDERS_CUSTOMATTRS);
    // User group Administrators
    if (!aUserGroupMgr.containsWithID(CPPApp.USERGROUP_ADMINISTRATORS_ID)) {
        aUserGroupMgr.createPredefinedUserGroup(CPPApp.USERGROUP_ADMINISTRATORS_ID, CPPApp.USERGROUP_ADMINISTRATORS_NAME, CPPApp.USERGROUP_ADMINISTRATORS_DESCRIPTION, CPPApp.USERGROUP_ADMINISTRATORS_CUSTOMATTRS);
        // Assign administrator user to administrators user group
        aUserGroupMgr.assignUserToUserGroup(CPPApp.USERGROUP_ADMINISTRATORS_ID, CPPApp.USER_ADMINISTRATOR_ID);
    }
    aUserGroupMgr.assignRoleToUserGroup(CPPApp.USERGROUP_ADMINISTRATORS_ID, CPPApp.ROLE_CONFIG_ID);
    aUserGroupMgr.assignRoleToUserGroup(CPPApp.USERGROUP_ADMINISTRATORS_ID, CPPApp.ROLE_VIEW_ID);
    aUserGroupMgr.assignRoleToUserGroup(CPPApp.USERGROUP_ADMINISTRATORS_ID, CPPApp.ROLE_COMMENT_MODERATOR_ID);
    aUserGroupMgr.assignRoleToUserGroup(CPPApp.USERGROUP_ADMINISTRATORS_ID, CPPApp.ROLE_PEPPOL_SENDERS_ID);
    // User group for Config users
    if (!aUserGroupMgr.containsWithID(CPPApp.USERGROUP_CONFIG_ID))
        aUserGroupMgr.createPredefinedUserGroup(CPPApp.USERGROUP_CONFIG_ID, CPPApp.USERGROUP_CONFIG_NAME, CPPApp.USERGROUP_CONFIG_DESCRIPTION, CPPApp.USERGROUP_CONFIG_CUSTOMATTRS);
    aUserGroupMgr.assignRoleToUserGroup(CPPApp.USERGROUP_CONFIG_ID, CPPApp.ROLE_CONFIG_ID);
    // User group for View users
    if (!aUserGroupMgr.containsWithID(CPPApp.USERGROUP_VIEW_ID))
        aUserGroupMgr.createPredefinedUserGroup(CPPApp.USERGROUP_VIEW_ID, CPPApp.USERGROUP_VIEW_NAME, CPPApp.USERGROUP_VIEW_DESCRIPTION, CPPApp.USERGROUP_VIEW_CUSTOMATTRS);
    aUserGroupMgr.assignRoleToUserGroup(CPPApp.USERGROUP_VIEW_ID, CPPApp.ROLE_VIEW_ID);
}
Also used : IUserManager(com.helger.photon.security.user.IUserManager) IRoleManager(com.helger.photon.security.role.IRoleManager) IUserGroupManager(com.helger.photon.security.usergroup.IUserGroupManager)

Example 7 with IUserManager

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

the class AppSecurity method init.

public static void init() {
    final IUserManager aUserMgr = PhotonSecurityManager.getUserMgr();
    final IUserGroupManager aUserGroupMgr = PhotonSecurityManager.getUserGroupMgr();
    final IRoleManager aRoleMgr = PhotonSecurityManager.getRoleMgr();
    // Standard users
    if (!aUserMgr.containsWithID(USER_ADMINISTRATOR_ID)) {
        final boolean bDisabled = false;
        aUserMgr.createPredefinedUser(USER_ADMINISTRATOR_ID, USER_ADMINISTRATOR_LOGINNAME, USER_ADMINISTRATOR_EMAIL, USER_ADMINISTRATOR_PASSWORD, USER_ADMINISTRATOR_FIRSTNAME, USER_ADMINISTRATOR_LASTNAME, USER_ADMINISTRATOR_DESCRIPTION, USER_ADMINISTRATOR_LOCALE, USER_ADMINISTRATOR_CUSTOMATTRS, bDisabled);
    }
    // Create all roles
    if (!aRoleMgr.containsWithID(ROLE_CONFIG_ID))
        aRoleMgr.createPredefinedRole(ROLE_CONFIG_ID, ROLE_CONFIG_NAME, ROLE_CONFIG_DESCRIPTION, ROLE_CONFIG_CUSTOMATTRS);
    if (!aRoleMgr.containsWithID(ROLE_VIEW_ID))
        aRoleMgr.createPredefinedRole(ROLE_VIEW_ID, ROLE_VIEW_NAME, ROLE_VIEW_DESCRIPTION, ROLE_VIEW_CUSTOMATTRS);
    if (!aRoleMgr.containsWithID(ROLE_SG_OWNER_ID))
        aRoleMgr.createPredefinedRole(ROLE_SG_OWNER_ID, ROLE_SG_OWNER_NAME, ROLE_SG_OWNER_DESCRIPTION, ROLE_SG_OWNER_CUSTOMATTRS);
    // User group Administrators
    if (!aUserGroupMgr.containsWithID(USERGROUP_ADMINISTRATORS_ID)) {
        aUserGroupMgr.createPredefinedUserGroup(USERGROUP_ADMINISTRATORS_ID, USERGROUP_ADMINISTRATORS_NAME, USERGROUP_ADMINISTRATORS_DESCRIPTION, USERGROUP_ADMINISTRATORS_CUSTOMATTRS);
        // Assign administrator user to administrators user group
        aUserGroupMgr.assignUserToUserGroup(USERGROUP_ADMINISTRATORS_ID, USER_ADMINISTRATOR_ID);
    }
    aUserGroupMgr.assignRoleToUserGroup(USERGROUP_ADMINISTRATORS_ID, ROLE_CONFIG_ID);
    aUserGroupMgr.assignRoleToUserGroup(USERGROUP_ADMINISTRATORS_ID, ROLE_VIEW_ID);
    aUserGroupMgr.assignRoleToUserGroup(USERGROUP_ADMINISTRATORS_ID, ROLE_SG_OWNER_ID);
    // User group for Config users
    if (!aUserGroupMgr.containsWithID(USERGROUP_CONFIG_ID))
        aUserGroupMgr.createPredefinedUserGroup(USERGROUP_CONFIG_ID, USERGROUP_CONFIG_NAME, USERGROUP_CONFIG_DESCRIPTION, USERGROUP_CONFIG_CUSTOMATTRS);
    aUserGroupMgr.assignRoleToUserGroup(USERGROUP_CONFIG_ID, ROLE_CONFIG_ID);
    // User group for View users
    if (!aUserGroupMgr.containsWithID(USERGROUP_VIEW_ID))
        aUserGroupMgr.createPredefinedUserGroup(USERGROUP_VIEW_ID, USERGROUP_VIEW_NAME, USERGROUP_VIEW_DESCRIPTION, USERGROUP_VIEW_CUSTOMATTRS);
    aUserGroupMgr.assignRoleToUserGroup(USERGROUP_VIEW_ID, ROLE_VIEW_ID);
    // Allow to kick old sessions
    LoggedInUserManager.getInstance().setLogoutAlreadyLoggedInUser(true);
}
Also used : IUserManager(com.helger.photon.security.user.IUserManager) IRoleManager(com.helger.photon.security.role.IRoleManager) IUserGroupManager(com.helger.photon.security.usergroup.IUserGroupManager)

Example 8 with IUserManager

use of com.helger.photon.security.user.IUserManager 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)

Example 9 with IUserManager

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

the class APIExecutorImportXMLVer1 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 ISMPServerAPIDataProvider aDataProvider = new SMPRestDataProvider(aRequestScope, null);
    // Is the writable API disabled?
    if (SMPMetaManager.getSettings().isRESTWritableAPIDisabled()) {
        throw new SMPPreconditionFailedException("The writable REST API is disabled. importServiceGroups will not be executed", aDataProvider.getCurrentURI());
    }
    final String sLogPrefix = "[REST API Import-XML-V1] ";
    final String sPathUserLoginName = aPathVariables.get(SMPRestFilter.PARAM_USER_ID);
    LOGGER.info(sLogPrefix + "Starting Import");
    // Only authenticated user may do so
    final BasicAuthClientCredentials aBasicAuth = getMandatoryAuth(aRequestScope.headers());
    SMPUserManagerPhoton.validateUserCredentials(aBasicAuth);
    // Start action after authentication
    final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
    final ISMPBusinessCardManager aBusinessCardMgr = SMPMetaManager.getBusinessCardMgr();
    final IUserManager aUserMgr = PhotonSecurityManager.getUserMgr();
    final ICommonsSet<String> aAllServiceGroupIDs = aServiceGroupMgr.getAllSMPServiceGroupIDs();
    final ICommonsSet<String> aAllBusinessCardIDs = aBusinessCardMgr.getAllSMPBusinessCardIDs();
    // Try to use ID or login name
    IUser aDefaultOwner = aUserMgr.getUserOfID(sPathUserLoginName);
    if (aDefaultOwner == null)
        aDefaultOwner = aUserMgr.getUserOfLoginName(sPathUserLoginName);
    if (aDefaultOwner == null || aDefaultOwner.isDeleted()) {
        // Setting the owner to a disabled user might make sense
        throw new SMPBadRequestException(sLogPrefix + "The user ID or login name '" + sPathUserLoginName + "' does not exist", aDataProvider.getCurrentURI());
    }
    LOGGER.info(sLogPrefix + "Using '" + aDefaultOwner.getID() + "' / '" + aDefaultOwner.getLoginName() + "' as the default owner");
    final boolean bOverwriteExisting = aRequestScope.params().getAsBoolean(PARAM_OVERVWRITE_EXISTING, DEFAULT_OVERWRITE_EXISTING);
    final byte[] aPayload = StreamHelper.getAllBytes(aRequestScope.getRequest().getInputStream());
    final IMicroDocument aDoc = MicroReader.readMicroXML(aPayload);
    if (aDoc == null || aDoc.getDocumentElement() == null) {
        // Cannot parse
        throw new SMPBadRequestException("Failed to parse XML payload", aDataProvider.getCurrentURI());
    }
    final String sVersion = aDoc.getDocumentElement().getAttributeValue(CSMPExchange.ATTR_VERSION);
    if (!CSMPExchange.VERSION_10.equals(sVersion)) {
        throw new SMPBadRequestException("The provided payload is not an XML file version 1.0", aDataProvider.getCurrentURI());
    }
    // Version 1.0
    LOGGER.info(sLogPrefix + "The provided payload is an XML file version 1.0");
    final ZonedDateTime aQueryDT = PDTFactory.getCurrentZonedDateTimeUTC();
    final StopWatch aSW = StopWatch.createdStarted();
    // Start the import
    final ICommonsList<ImportActionItem> aActionList = new CommonsArrayList<>();
    final ImportSummary aImportSummary = new ImportSummary();
    ServiceGroupImport.importXMLVer10(aDoc.getDocumentElement(), bOverwriteExisting, aDefaultOwner, aAllServiceGroupIDs, aAllBusinessCardIDs, aActionList, aImportSummary);
    aSW.stop();
    LOGGER.info(sLogPrefix + "Finished import after " + aSW.getMillis() + " milliseconds");
    // Everything added to the action list is already logged
    final boolean bResponseAsXML = true;
    if (bResponseAsXML) {
        // Create XML version
        final IMicroDocument aResponseDoc = new MicroDocument();
        final IMicroElement eRoot = aResponseDoc.appendElement("importResult");
        eRoot.setAttribute("version", "1");
        eRoot.setAttribute("importStartDateTime", PDTWebDateHelper.getAsStringXSD(aQueryDT));
        final IMicroElement eSettings = eRoot.appendElement("settings");
        eSettings.setAttribute("overwriteExisting", bOverwriteExisting);
        eSettings.setAttribute("defaultOwnerID", aDefaultOwner.getID());
        eSettings.setAttribute("defaultOwnerLoginName", aDefaultOwner.getLoginName());
        final ICommonsMap<String, MutableInt> aErrorLevelCount = new CommonsTreeMap<>();
        for (final ImportActionItem aAction : aActionList) {
            eRoot.appendChild(aAction.getAsMicroElement("action"));
            aErrorLevelCount.computeIfAbsent(aAction.getErrorLevelName(), k -> new MutableInt(0)).inc();
        }
        {
            final IMicroElement eSummary = eRoot.appendElement("summary");
            eSummary.setAttribute("durationMillis", aSW.getMillis());
            for (final Map.Entry<String, MutableInt> aEntry : aErrorLevelCount.entrySet()) eSummary.appendElement("errorlevel").setAttribute("id", aEntry.getKey()).setAttribute("count", aEntry.getValue().intValue());
            aImportSummary.appendTo(eSummary);
        }
        final XMLWriterSettings aXWS = new XMLWriterSettings().setIndent(EXMLSerializeIndent.INDENT_AND_ALIGN);
        aUnifiedResponse.setContentAndCharset(MicroWriter.getNodeAsString(aResponseDoc, aXWS), aXWS.getCharset()).setMimeType(new MimeType(CMimeType.APPLICATION_XML).addParameter(CMimeType.PARAMETER_NAME_CHARSET, aXWS.getCharset().name()));
    } else {
        // Create JSON version
        final IJsonObject aJson = new JsonObject();
        aJson.add("version", "1");
        aJson.add("importStartDateTime", DateTimeFormatter.ISO_ZONED_DATE_TIME.format(aQueryDT));
        aJson.addJson("settings", new JsonObject().add("overwriteExisting", bOverwriteExisting).add("defaultOwnerID", aDefaultOwner.getID()).add("defaultOwnerLoginName", aDefaultOwner.getLoginName()));
        final IJsonArray aActions = new JsonArray();
        final ICommonsMap<String, MutableInt> aLevelCount = new CommonsTreeMap<>();
        for (final ImportActionItem aAction : aActionList) {
            aActions.add(aAction.getAsJsonObject());
            aLevelCount.computeIfAbsent(aAction.getErrorLevelName(), k -> new MutableInt(0)).inc();
        }
        aJson.addJson("actions", aActions);
        {
            final IJsonObject aSummary = new JsonObject();
            aSummary.add("durationMillis", aSW.getMillis());
            final IJsonArray aLevels = new JsonArray();
            for (final Map.Entry<String, MutableInt> aEntry : aLevelCount.entrySet()) aLevels.add(new JsonObject().add("id", aEntry.getKey()).add("count", aEntry.getValue().intValue()));
            aSummary.addJson("errorlevels", aLevels);
            aImportSummary.appendTo(aSummary);
            aJson.addJson("summary", aSummary);
        }
        final String sRet = new JsonWriter(JsonWriterSettings.DEFAULT_SETTINGS_FORMATTED).writeAsString(aJson);
        aUnifiedResponse.setContentAndCharset(sRet, StandardCharsets.UTF_8).setMimeType(CMimeType.APPLICATION_JSON);
    }
    aUnifiedResponse.disableCaching();
}
Also used : IAPIDescriptor(com.helger.photon.api.IAPIDescriptor) StreamHelper(com.helger.commons.io.stream.StreamHelper) ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) CommonsTreeMap(com.helger.commons.collection.impl.CommonsTreeMap) IMicroDocument(com.helger.xml.microdom.IMicroDocument) IUserManager(com.helger.photon.security.user.IUserManager) JsonWriterSettings(com.helger.json.serialize.JsonWriterSettings) CMimeType(com.helger.commons.mime.CMimeType) Nonempty(com.helger.commons.annotation.Nonempty) PDTFactory(com.helger.commons.datetime.PDTFactory) ISMPServerAPIDataProvider(com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider) IUser(com.helger.photon.security.user.IUser) IMicroElement(com.helger.xml.microdom.IMicroElement) Map(java.util.Map) XMLWriterSettings(com.helger.xml.serialize.write.XMLWriterSettings) StandardCharsets(java.nio.charset.StandardCharsets) JsonObject(com.helger.json.JsonObject) ICommonsList(com.helger.commons.collection.impl.ICommonsList) IJsonArray(com.helger.json.IJsonArray) UnifiedResponse(com.helger.servlet.response.UnifiedResponse) MimeType(com.helger.commons.mime.MimeType) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) PhotonSecurityManager(com.helger.photon.security.mgr.PhotonSecurityManager) ImportSummary(com.helger.phoss.smp.exchange.ImportSummary) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) ICommonsSet(com.helger.commons.collection.impl.ICommonsSet) SMPBadRequestException(com.helger.phoss.smp.exception.SMPBadRequestException) BasicAuthClientCredentials(com.helger.http.basicauth.BasicAuthClientCredentials) CSMPExchange(com.helger.phoss.smp.exchange.CSMPExchange) IJsonObject(com.helger.json.IJsonObject) ImportActionItem(com.helger.phoss.smp.exchange.ImportActionItem) MicroDocument(com.helger.xml.microdom.MicroDocument) JsonArray(com.helger.json.JsonArray) Nonnull(javax.annotation.Nonnull) IRequestWebScopeWithoutResponse(com.helger.web.scope.IRequestWebScopeWithoutResponse) Logger(org.slf4j.Logger) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) MutableInt(com.helger.commons.mutable.MutableInt) SMPPreconditionFailedException(com.helger.phoss.smp.exception.SMPPreconditionFailedException) SMPMetaManager(com.helger.phoss.smp.domain.SMPMetaManager) PDTWebDateHelper(com.helger.commons.datetime.PDTWebDateHelper) ServiceGroupImport(com.helger.phoss.smp.exchange.ServiceGroupImport) JsonWriter(com.helger.json.serialize.JsonWriter) MicroWriter(com.helger.xml.microdom.serialize.MicroWriter) StopWatch(com.helger.commons.timing.StopWatch) DateTimeFormatter(java.time.format.DateTimeFormatter) EXMLSerializeIndent(com.helger.xml.serialize.write.EXMLSerializeIndent) MicroReader(com.helger.xml.microdom.serialize.MicroReader) SMPUserManagerPhoton(com.helger.phoss.smp.domain.user.SMPUserManagerPhoton) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) IUserManager(com.helger.photon.security.user.IUserManager) ImportSummary(com.helger.phoss.smp.exchange.ImportSummary) ImportActionItem(com.helger.phoss.smp.exchange.ImportActionItem) JsonObject(com.helger.json.JsonObject) IJsonObject(com.helger.json.IJsonObject) CMimeType(com.helger.commons.mime.CMimeType) MimeType(com.helger.commons.mime.MimeType) IMicroDocument(com.helger.xml.microdom.IMicroDocument) MicroDocument(com.helger.xml.microdom.MicroDocument) ZonedDateTime(java.time.ZonedDateTime) IJsonObject(com.helger.json.IJsonObject) ISMPServerAPIDataProvider(com.helger.phoss.smp.restapi.ISMPServerAPIDataProvider) IUser(com.helger.photon.security.user.IUser) SMPBadRequestException(com.helger.phoss.smp.exception.SMPBadRequestException) XMLWriterSettings(com.helger.xml.serialize.write.XMLWriterSettings) JsonWriter(com.helger.json.serialize.JsonWriter) CommonsTreeMap(com.helger.commons.collection.impl.CommonsTreeMap) StopWatch(com.helger.commons.timing.StopWatch) IJsonArray(com.helger.json.IJsonArray) JsonArray(com.helger.json.JsonArray) ISMPBusinessCardManager(com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager) SMPPreconditionFailedException(com.helger.phoss.smp.exception.SMPPreconditionFailedException) BasicAuthClientCredentials(com.helger.http.basicauth.BasicAuthClientCredentials) IMicroElement(com.helger.xml.microdom.IMicroElement) MutableInt(com.helger.commons.mutable.MutableInt) IJsonArray(com.helger.json.IJsonArray) IMicroDocument(com.helger.xml.microdom.IMicroDocument) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList)

Example 10 with IUserManager

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

the class PageSecureServiceGroup method isValidToDisplayPage.

@Override
@Nonnull
protected IValidityIndicator isValidToDisplayPage(@Nonnull final WebPageExecutionContext aWPEC) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final IUserManager aUserMgr = PhotonSecurityManager.getUserMgr();
    if (aUserMgr.getActiveUserCount() == 0) {
        aNodeList.addChild(warn("No user is present! At least one user must be present to create a service group."));
        aNodeList.addChild(new BootstrapButton().addChild("Create new user").setOnClick(createCreateURL(aWPEC, BootstrapPagesMenuConfigurator.MENU_ADMIN_SECURITY_USER)).setIcon(EDefaultIcon.YES));
        return EValidity.INVALID;
    }
    return super.isValidToDisplayPage(aWPEC);
}
Also used : HCNodeList(com.helger.html.hc.impl.HCNodeList) IUserManager(com.helger.photon.security.user.IUserManager) BootstrapButton(com.helger.photon.bootstrap4.button.BootstrapButton) Nonnull(javax.annotation.Nonnull)

Aggregations

IUserManager (com.helger.photon.security.user.IUserManager)12 IUser (com.helger.photon.security.user.IUser)7 IRoleManager (com.helger.photon.security.role.IRoleManager)4 Nonnull (javax.annotation.Nonnull)4 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)3 HCNodeList (com.helger.html.hc.impl.HCNodeList)3 IUserGroupManager (com.helger.photon.security.usergroup.IUserGroupManager)3 CommonsLinkedHashMap (com.helger.commons.collection.impl.CommonsLinkedHashMap)2 ICommonsList (com.helger.commons.collection.impl.ICommonsList)2 ICommonsMap (com.helger.commons.collection.impl.ICommonsMap)2 ICommonsSet (com.helger.commons.collection.impl.ICommonsSet)2 SMPDBExecutor (com.helger.phoss.smp.backend.sql.SMPDBExecutor)2 ISMPBusinessCardManager (com.helger.phoss.smp.domain.businesscard.ISMPBusinessCardManager)2 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)2 ISMPSettings (com.helger.phoss.smp.settings.ISMPSettings)2 BootstrapButton (com.helger.photon.bootstrap4.button.BootstrapButton)2 IRequestWebScopeWithoutResponse (com.helger.web.scope.IRequestWebScopeWithoutResponse)2 WebScoped (com.helger.web.scope.mgr.WebScoped)2 Locale (java.util.Locale)2 ValueEnforcer (com.helger.commons.ValueEnforcer)1