Search in sources :

Example 61 with User

use of org.thingsboard.server.common.data.User in project thingsboard by thingsboard.

the class BaseWidgetsBundleControllerTest method beforeTest.

@Before
public void beforeTest() throws Exception {
    loginSysAdmin();
    Tenant tenant = new Tenant();
    tenant.setTitle("My tenant");
    savedTenant = doPost("/api/tenant", tenant, Tenant.class);
    Assert.assertNotNull(savedTenant);
    tenantAdmin = new User();
    tenantAdmin.setAuthority(Authority.TENANT_ADMIN);
    tenantAdmin.setTenantId(savedTenant.getId());
    tenantAdmin.setEmail("tenant2@thingsboard.org");
    tenantAdmin.setFirstName("Joe");
    tenantAdmin.setLastName("Downs");
    tenantAdmin = createUserAndLogin(tenantAdmin, "testPassword1");
}
Also used : Tenant(org.thingsboard.server.common.data.Tenant) User(org.thingsboard.server.common.data.User) Before(org.junit.Before)

Example 62 with User

use of org.thingsboard.server.common.data.User in project thingsboard by thingsboard.

the class RestAuthenticationProvider method authenticateByUsernameAndPassword.

private Authentication authenticateByUsernameAndPassword(UserPrincipal userPrincipal, String username, String password) {
    User user = userService.findUserByEmail(username);
    if (user == null) {
        throw new UsernameNotFoundException("User not found: " + username);
    }
    UserCredentials userCredentials = userService.findUserCredentialsByUserId(user.getId());
    if (userCredentials == null) {
        throw new UsernameNotFoundException("User credentials not found");
    }
    if (!userCredentials.isEnabled()) {
        throw new DisabledException("User is not active");
    }
    if (!encoder.matches(password, userCredentials.getPassword())) {
        throw new BadCredentialsException("Authentication Failed. Username or Password not valid.");
    }
    if (user.getAuthority() == null)
        throw new InsufficientAuthenticationException("User has no authority assigned");
    SecurityUser securityUser = new SecurityUser(user, userCredentials.isEnabled(), userPrincipal);
    return new UsernamePasswordAuthenticationToken(securityUser, null, securityUser.getAuthorities());
}
Also used : UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) SecurityUser(org.thingsboard.server.service.security.model.SecurityUser) User(org.thingsboard.server.common.data.User) SecurityUser(org.thingsboard.server.service.security.model.SecurityUser) UserCredentials(org.thingsboard.server.common.data.security.UserCredentials)

Example 63 with User

use of org.thingsboard.server.common.data.User in project thingsboard by thingsboard.

the class AbstractMqttServerSideRpcIntegrationTest method beforeTest.

@Before
public void beforeTest() throws Exception {
    loginSysAdmin();
    asyncContextTimeoutToUseRpcPlugin = getAsyncContextTimeoutToUseRpcPlugin();
    Tenant tenant = new Tenant();
    tenant.setTitle("My tenant");
    savedTenant = doPost("/api/tenant", tenant, Tenant.class);
    Assert.assertNotNull(savedTenant);
    tenantAdmin = new User();
    tenantAdmin.setAuthority(Authority.TENANT_ADMIN);
    tenantAdmin.setTenantId(savedTenant.getId());
    tenantAdmin.setEmail("tenant2@thingsboard.org");
    tenantAdmin.setFirstName("Joe");
    tenantAdmin.setLastName("Downs");
    createUserAndLogin(tenantAdmin, "testPassword1");
}
Also used : Tenant(org.thingsboard.server.common.data.Tenant) User(org.thingsboard.server.common.data.User)

Aggregations

User (org.thingsboard.server.common.data.User)63 Test (org.junit.Test)37 Tenant (org.thingsboard.server.common.data.Tenant)33 Customer (org.thingsboard.server.common.data.Customer)16 TenantId (org.thingsboard.server.common.data.id.TenantId)14 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)12 UserCredentials (org.thingsboard.server.common.data.security.UserCredentials)12 ArrayList (java.util.ArrayList)10 CustomerId (org.thingsboard.server.common.data.id.CustomerId)10 SecurityUser (org.thingsboard.server.service.security.model.SecurityUser)10 Matchers.containsString (org.hamcrest.Matchers.containsString)9 Before (org.junit.Before)9 UserId (org.thingsboard.server.common.data.id.UserId)9 TypeReference (com.fasterxml.jackson.core.type.TypeReference)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)4