Search in sources :

Example 1 with AdminUserImpl

use of org.broadleafcommerce.openadmin.server.security.domain.AdminUserImpl in project BroadleafCommerce by BroadleafCommerce.

the class AdminUserDataProvider method createAdminUser.

@DataProvider(name = "setupAdminUser")
public static Object[][] createAdminUser() {
    AdminUser adminUser = new AdminUserImpl();
    adminUser.setName("TestAdminUserName");
    adminUser.setLogin("TestAdminUserLogin");
    adminUser.setEmail("TestAdminUserEmail@broadleafcommerce.org");
    adminUser.setPassword("TestAdminUserPassword");
    return new Object[][] { new Object[] { adminUser } };
}
Also used : AdminUserImpl(org.broadleafcommerce.openadmin.server.security.domain.AdminUserImpl) AdminUser(org.broadleafcommerce.openadmin.server.security.domain.AdminUser) DataProvider(org.testng.annotations.DataProvider)

Example 2 with AdminUserImpl

use of org.broadleafcommerce.openadmin.server.security.domain.AdminUserImpl in project BroadleafCommerce by BroadleafCommerce.

the class AdminUserProvisioningServiceImpl method provisionAdminUser.

@Override
public AdminUserDetails provisionAdminUser(BroadleafExternalAuthenticationUserDetails details) {
    HashSet<String> parsedRoleNames = parseRolesFromUserDetails(details);
    HashSet<AdminRole> parsedRoles = new HashSet<AdminRole>();
    List<AdminRole> adminRoles = securityService.readAllAdminRoles();
    if (adminRoles != null) {
        for (AdminRole role : adminRoles) {
            if (parsedRoleNames.contains(role.getName())) {
                parsedRoles.add(role);
            }
        }
    }
    Set<SimpleGrantedAuthority> adminUserAuthorities = extractAdminUserAuthorities(parsedRoles);
    AdminUser adminUser = securityService.readAdminUserByUserName(details.getUsername());
    if (adminUser == null) {
        adminUser = new AdminUserImpl();
        adminUser.setLogin(details.getUsername());
    }
    if (StringUtils.isNotBlank(details.getEmail())) {
        adminUser.setEmail(details.getEmail());
    }
    StringBuilder name = new StringBuilder();
    if (StringUtils.isNotBlank(details.getFirstName())) {
        name.append(details.getFirstName()).append(" ");
    }
    if (StringUtils.isNotBlank(details.getLastName())) {
        name.append(details.getLastName());
    }
    String fullName = name.toString();
    if (StringUtils.isNotBlank(fullName)) {
        adminUser.setName(fullName);
    } else {
        adminUser.setName(details.getUsername());
    }
    // set the roles for the admin user to our new set of roles
    adminUser.setAllRoles(new HashSet<>(parsedRoles));
    // Add optional support for things like Multi-Tenant, etc...
    adminExternalLoginExtensionManager.getProxy().performAdditionalAuthenticationTasks(adminUser, details);
    // Save the user data and all of the roles...
    adminUser = securityService.saveAdminUser(adminUser);
    return new AdminUserDetails(adminUser.getId(), details.getUsername(), "", true, true, true, true, adminUserAuthorities);
}
Also used : SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) AdminUserImpl(org.broadleafcommerce.openadmin.server.security.domain.AdminUserImpl) AdminUser(org.broadleafcommerce.openadmin.server.security.domain.AdminUser) AdminRole(org.broadleafcommerce.openadmin.server.security.domain.AdminRole) HashSet(java.util.HashSet)

Aggregations

AdminUser (org.broadleafcommerce.openadmin.server.security.domain.AdminUser)2 AdminUserImpl (org.broadleafcommerce.openadmin.server.security.domain.AdminUserImpl)2 HashSet (java.util.HashSet)1 AdminRole (org.broadleafcommerce.openadmin.server.security.domain.AdminRole)1 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)1 DataProvider (org.testng.annotations.DataProvider)1