Search in sources :

Example 1 with IUserGroupManager

use of com.helger.photon.security.usergroup.IUserGroupManager in project phoss-smp by phax.

the class SMPSecurity method init.

public static void init() {
    LOGGER.info("Starting to initialize SMP security");
    final IUserManager aUserMgr = PhotonSecurityManager.getUserMgr();
    final IUserGroupManager aUserGroupMgr = PhotonSecurityManager.getUserGroupMgr();
    final IRoleManager aRoleMgr = PhotonSecurityManager.getRoleMgr();
    // Standard users
    if (!aUserMgr.containsWithID(CSMP.USER_ADMINISTRATOR_ID)) {
        final boolean bDisabled = false;
        aUserMgr.createPredefinedUser(CSMP.USER_ADMINISTRATOR_ID, CSMP.USER_ADMINISTRATOR_LOGINNAME, CSMP.USER_ADMINISTRATOR_EMAIL, CSMP.USER_ADMINISTRATOR_PASSWORD, CSMP.USER_ADMINISTRATOR_FIRSTNAME, CSMP.USER_ADMINISTRATOR_LASTNAME, CSMP.USER_ADMINISTRATOR_DESCRIPTION, CSMP.USER_ADMINISTRATOR_LOCALE, CSMP.USER_ADMINISTRATOR_CUSTOMATTRS, bDisabled);
    }
    // Create all roles
    if (!aRoleMgr.containsWithID(CSMP.ROLE_CONFIG_ID))
        aRoleMgr.createPredefinedRole(CSMP.ROLE_CONFIG_ID, CSMP.ROLE_CONFIG_NAME, CSMP.ROLE_CONFIG_DESCRIPTION, CSMP.ROLE_CONFIG_CUSTOMATTRS);
    if (!aRoleMgr.containsWithID(CSMP.ROLE_WRITABLERESTAPI_ID))
        aRoleMgr.createPredefinedRole(CSMP.ROLE_WRITABLERESTAPI_ID, CSMP.ROLE_WRITABLERESTAPI_NAME, CSMP.ROLE_WRITABLERESTAPI_DESCRIPTION, CSMP.ROLE_WRITABLERESTAPI_CUSTOMATTRS);
    // User group Administrators
    if (!aUserGroupMgr.containsWithID(CSMP.USERGROUP_ADMINISTRATORS_ID)) {
        aUserGroupMgr.createPredefinedUserGroup(CSMP.USERGROUP_ADMINISTRATORS_ID, CSMP.USERGROUP_ADMINISTRATORS_NAME, CSMP.USERGROUP_ADMINISTRATORS_DESCRIPTION, CSMP.USERGROUP_ADMINISTRATORS_CUSTOMATTRS);
        // Assign administrator user to administrators user group
        aUserGroupMgr.assignUserToUserGroup(CSMP.USERGROUP_ADMINISTRATORS_ID, CSMP.USER_ADMINISTRATOR_ID);
    }
    aUserGroupMgr.assignRoleToUserGroup(CSMP.USERGROUP_ADMINISTRATORS_ID, CSMP.ROLE_CONFIG_ID);
    aUserGroupMgr.assignRoleToUserGroup(CSMP.USERGROUP_ADMINISTRATORS_ID, CSMP.ROLE_WRITABLERESTAPI_ID);
    // User group for Config users
    if (!aUserGroupMgr.containsWithID(CSMP.USERGROUP_CONFIG_ID))
        aUserGroupMgr.createPredefinedUserGroup(CSMP.USERGROUP_CONFIG_ID, CSMP.USERGROUP_CONFIG_NAME, CSMP.USERGROUP_CONFIG_DESCRIPTION, CSMP.USERGROUP_CONFIG_CUSTOMATTRS);
    aUserGroupMgr.assignRoleToUserGroup(CSMP.USERGROUP_CONFIG_ID, CSMP.ROLE_CONFIG_ID);
    // User group for Writable REST API users
    if (!aUserGroupMgr.containsWithID(CSMP.USERGROUP_WRITABLERESTAPI_ID))
        aUserGroupMgr.createPredefinedUserGroup(CSMP.USERGROUP_WRITABLERESTAPI_ID, CSMP.USERGROUP_WRITABLERESTAPI_NAME, CSMP.USERGROUP_WRITABLERESTAPI_DESCRIPTION, CSMP.USERGROUP_WRITABLERESTAPI_CUSTOMATTRS);
    aUserGroupMgr.assignRoleToUserGroup(CSMP.USERGROUP_WRITABLERESTAPI_ID, CSMP.ROLE_WRITABLERESTAPI_ID);
    // New login logs out old user
    LoggedInUserManager.getInstance().setLogoutAlreadyLoggedInUser(true);
    // Setup internal error handler (if configured)
    SMPInternalErrorHandler.doSetup();
    LOGGER.info("Finished initializing SMP security");
}
Also used : IUserManager(com.helger.photon.security.user.IUserManager) IRoleManager(com.helger.photon.security.role.IRoleManager) IUserGroupManager(com.helger.photon.security.usergroup.IUserGroupManager)

Example 2 with IUserGroupManager

use of com.helger.photon.security.usergroup.IUserGroupManager 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 3 with IUserGroupManager

use of com.helger.photon.security.usergroup.IUserGroupManager 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 4 with IUserGroupManager

use of com.helger.photon.security.usergroup.IUserGroupManager in project peppol-practical by phax.

the class PagePublicSignUp method validateAndSaveInputParameters.

protected void validateAndSaveInputParameters(@Nonnull final WebPageExecutionContext aWPEC, @Nonnull final FormErrorList aFormErrors) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final IUserManager aUserMgr = PhotonSecurityManager.getUserMgr();
    final IUserGroupManager aUserGroupMgr = PhotonSecurityManager.getUserGroupMgr();
    final String sFirstName = aWPEC.params().getAsString(FIELD_FIRSTNAME);
    final String sLastName = aWPEC.params().getAsString(FIELD_LASTNAME);
    final String sEmailAddress = aWPEC.params().getAsString(FIELD_EMAIL1);
    final String sEmailAddressConfirm = aWPEC.params().getAsString(FIELD_EMAIL2);
    final String sPlainTextPassword = aWPEC.params().getAsString(FIELD_PASSWORD);
    final String sPlainTextPasswordConfirm = aWPEC.params().getAsString(FIELD_PASSWORD_CONFIRM);
    if (StringHelper.hasNoText(sFirstName))
        aFormErrors.addFieldError(FIELD_FIRSTNAME, "A first name must be provded!!");
    if (StringHelper.hasNoText(sLastName))
        aFormErrors.addFieldError(FIELD_LASTNAME, "A last name must be provded!!");
    if (StringHelper.hasNoText(sEmailAddress))
        aFormErrors.addFieldError(FIELD_EMAIL1, "An email address must be provded!!");
    else if (!EmailAddressHelper.isValid(sEmailAddress))
        aFormErrors.addFieldError(FIELD_EMAIL1, "The provided email address is not valid!");
    else if (!sEmailAddress.equals(sEmailAddressConfirm)) {
        aFormErrors.addFieldError(FIELD_EMAIL2, "The two provided email addresses don't match!");
    } else {
        IUser aUser = aUserMgr.getUserOfLoginName(sEmailAddress);
        if (aUser == null)
            aUser = aUserMgr.getUserOfEmailAddress(sEmailAddress);
        if (aUser != null)
            aFormErrors.addFieldError(FIELD_EMAIL1, "Another user with the same email address is already registered!");
    }
    final List<String> aPasswordErrors = GlobalPasswordSettings.getPasswordConstraintList().getInvalidPasswordDescriptions(sPlainTextPassword, aDisplayLocale);
    for (final String sPasswordError : aPasswordErrors) aFormErrors.addFieldError(FIELD_PASSWORD, "Error: " + sPasswordError);
    if (!aFormErrors.hasEntryForField(FIELD_PASSWORD) && !EqualsHelper.equals(sPlainTextPassword, sPlainTextPasswordConfirm))
        aFormErrors.addFieldError(FIELD_PASSWORD_CONFIRM, "The two provided passwords don't match!");
    if (aFormErrors.isEmpty()) {
        final String sDescription = "User signed up at " + PDTFactory.getCurrentLocalDateTime().toString() + " from " + aWPEC.getRequestScope().getRemoteAddr();
        // Create new user
        final IUser aCreatedUser = aUserMgr.createNewUser(sEmailAddress, sEmailAddress, sPlainTextPassword, sFirstName, sLastName, sDescription, aDisplayLocale, (Map<String, String>) null, false);
        if (aCreatedUser == null)
            aNodeList.addChild(error("Error creating the new user!"));
        else {
            // Assign new user to user group
            if (aUserGroupMgr.assignUserToUserGroup(CPPApp.USERGROUP_VIEW_ID, aCreatedUser.getID()).isUnchanged())
                aNodeList.addChild(error("Error assigning the user to the user group!"));
            else {
                aNodeList.addChild(success("You have been registered successfully! You may now login with your email address '" + sEmailAddress + "' and the selected password."));
                // Show login form
                aNodeList.addChild(AppCommonUI.createViewLoginForm(aWPEC, sEmailAddress, false));
            }
        }
    }
}
Also used : Locale(java.util.Locale) HCNodeList(com.helger.html.hc.impl.HCNodeList) IUserManager(com.helger.photon.security.user.IUserManager) IUser(com.helger.photon.security.user.IUser) IUserGroupManager(com.helger.photon.security.usergroup.IUserGroupManager)

Aggregations

IUserManager (com.helger.photon.security.user.IUserManager)4 IUserGroupManager (com.helger.photon.security.usergroup.IUserGroupManager)4 IRoleManager (com.helger.photon.security.role.IRoleManager)3 HCNodeList (com.helger.html.hc.impl.HCNodeList)1 IUser (com.helger.photon.security.user.IUser)1 Locale (java.util.Locale)1