Search in sources :

Example 11 with OAuth2Info

use of org.thingsboard.server.common.data.oauth2.OAuth2Info in project thingsboard by thingsboard.

the class BaseOAuth2ServiceTest method testSaveHttpsAndMixedDomainsTogether.

@Test(expected = DataValidationException.class)
public void testSaveHttpsAndMixedDomainsTogether() {
    OAuth2Info oAuth2Info = new OAuth2Info(true, Lists.newArrayList(OAuth2ParamsInfo.builder().domainInfos(Lists.newArrayList(OAuth2DomainInfo.builder().name("first-domain").scheme(SchemeType.HTTPS).build(), OAuth2DomainInfo.builder().name("first-domain").scheme(SchemeType.MIXED).build(), OAuth2DomainInfo.builder().name("third-domain").scheme(SchemeType.HTTPS).build())).clientRegistrations(Lists.newArrayList(validRegistrationInfo(), validRegistrationInfo(), validRegistrationInfo())).build()));
    oAuth2Service.saveOAuth2Info(oAuth2Info);
}
Also used : OAuth2Info(org.thingsboard.server.common.data.oauth2.OAuth2Info) Test(org.junit.Test)

Example 12 with OAuth2Info

use of org.thingsboard.server.common.data.oauth2.OAuth2Info in project thingsboard by thingsboard.

the class BaseOAuth2ServiceTest method testUpdateClientsParams.

@Test
public void testUpdateClientsParams() {
    OAuth2Info oAuth2Info = createDefaultOAuth2Info();
    oAuth2Service.saveOAuth2Info(oAuth2Info);
    OAuth2Info foundOAuth2Info = oAuth2Service.findOAuth2Info();
    Assert.assertNotNull(foundOAuth2Info);
    Assert.assertEquals(oAuth2Info, foundOAuth2Info);
    OAuth2Info newOAuth2Info = new OAuth2Info(true, Lists.newArrayList(OAuth2ParamsInfo.builder().domainInfos(Lists.newArrayList(OAuth2DomainInfo.builder().name("another-domain").scheme(SchemeType.HTTPS).build())).mobileInfos(Collections.emptyList()).clientRegistrations(Lists.newArrayList(validRegistrationInfo())).build(), OAuth2ParamsInfo.builder().domainInfos(Lists.newArrayList(OAuth2DomainInfo.builder().name("test-domain").scheme(SchemeType.MIXED).build())).mobileInfos(Collections.emptyList()).clientRegistrations(Lists.newArrayList(validRegistrationInfo())).build()));
    oAuth2Service.saveOAuth2Info(newOAuth2Info);
    OAuth2Info foundAfterUpdateOAuth2Info = oAuth2Service.findOAuth2Info();
    Assert.assertNotNull(foundAfterUpdateOAuth2Info);
    Assert.assertEquals(newOAuth2Info, foundAfterUpdateOAuth2Info);
}
Also used : OAuth2Info(org.thingsboard.server.common.data.oauth2.OAuth2Info) Test(org.junit.Test)

Example 13 with OAuth2Info

use of org.thingsboard.server.common.data.oauth2.OAuth2Info in project thingsboard by thingsboard.

the class BaseOAuth2ServiceTest method testGetDisabledOAuth2Clients.

@Test
public void testGetDisabledOAuth2Clients() {
    OAuth2Info oAuth2Info = new OAuth2Info(true, Lists.newArrayList(OAuth2ParamsInfo.builder().domainInfos(Lists.newArrayList(OAuth2DomainInfo.builder().name("first-domain").scheme(SchemeType.HTTP).build(), OAuth2DomainInfo.builder().name("second-domain").scheme(SchemeType.MIXED).build(), OAuth2DomainInfo.builder().name("third-domain").scheme(SchemeType.HTTPS).build())).clientRegistrations(Lists.newArrayList(validRegistrationInfo(), validRegistrationInfo(), validRegistrationInfo())).build(), OAuth2ParamsInfo.builder().domainInfos(Lists.newArrayList(OAuth2DomainInfo.builder().name("second-domain").scheme(SchemeType.HTTP).build(), OAuth2DomainInfo.builder().name("fourth-domain").scheme(SchemeType.MIXED).build())).clientRegistrations(Lists.newArrayList(validRegistrationInfo(), validRegistrationInfo())).build()));
    oAuth2Service.saveOAuth2Info(oAuth2Info);
    List<OAuth2ClientInfo> secondDomainHttpClients = oAuth2Service.getOAuth2Clients("http", "second-domain", null, null);
    Assert.assertEquals(5, secondDomainHttpClients.size());
    oAuth2Info.setEnabled(false);
    oAuth2Service.saveOAuth2Info(oAuth2Info);
    List<OAuth2ClientInfo> secondDomainHttpDisabledClients = oAuth2Service.getOAuth2Clients("http", "second-domain", null, null);
    Assert.assertEquals(0, secondDomainHttpDisabledClients.size());
}
Also used : OAuth2Info(org.thingsboard.server.common.data.oauth2.OAuth2Info) OAuth2ClientInfo(org.thingsboard.server.common.data.oauth2.OAuth2ClientInfo) Test(org.junit.Test)

Example 14 with OAuth2Info

use of org.thingsboard.server.common.data.oauth2.OAuth2Info in project thingsboard by thingsboard.

the class BaseOAuth2ServiceTest method testDisableParams.

@Test
public void testDisableParams() {
    OAuth2Info oAuth2Info = createDefaultOAuth2Info();
    oAuth2Info.setEnabled(true);
    oAuth2Service.saveOAuth2Info(oAuth2Info);
    OAuth2Info foundOAuth2Info = oAuth2Service.findOAuth2Info();
    Assert.assertNotNull(foundOAuth2Info);
    Assert.assertEquals(oAuth2Info, foundOAuth2Info);
    oAuth2Info.setEnabled(false);
    oAuth2Service.saveOAuth2Info(oAuth2Info);
    OAuth2Info foundDisabledOAuth2Info = oAuth2Service.findOAuth2Info();
    Assert.assertEquals(oAuth2Info, foundDisabledOAuth2Info);
}
Also used : OAuth2Info(org.thingsboard.server.common.data.oauth2.OAuth2Info) Test(org.junit.Test)

Example 15 with OAuth2Info

use of org.thingsboard.server.common.data.oauth2.OAuth2Info in project thingsboard by thingsboard.

the class BaseOAuth2ServiceTest method testFindAppSecret.

@Test
public void testFindAppSecret() {
    OAuth2Info oAuth2Info = new OAuth2Info(true, Lists.newArrayList(OAuth2ParamsInfo.builder().domainInfos(Lists.newArrayList(OAuth2DomainInfo.builder().name("first-domain").scheme(SchemeType.HTTP).build(), OAuth2DomainInfo.builder().name("second-domain").scheme(SchemeType.MIXED).build(), OAuth2DomainInfo.builder().name("third-domain").scheme(SchemeType.HTTPS).build())).mobileInfos(Lists.newArrayList(validMobileInfo("com.test.pkg1", "testPkg1AppSecret"), validMobileInfo("com.test.pkg2", "testPkg2AppSecret"))).clientRegistrations(Lists.newArrayList(validRegistrationInfo(), validRegistrationInfo(), validRegistrationInfo())).build(), OAuth2ParamsInfo.builder().domainInfos(Lists.newArrayList(OAuth2DomainInfo.builder().name("second-domain").scheme(SchemeType.HTTP).build(), OAuth2DomainInfo.builder().name("fourth-domain").scheme(SchemeType.MIXED).build())).mobileInfos(Collections.emptyList()).clientRegistrations(Lists.newArrayList(validRegistrationInfo(), validRegistrationInfo())).build()));
    oAuth2Service.saveOAuth2Info(oAuth2Info);
    OAuth2Info foundOAuth2Info = oAuth2Service.findOAuth2Info();
    Assert.assertEquals(oAuth2Info, foundOAuth2Info);
    List<OAuth2ClientInfo> firstDomainHttpClients = oAuth2Service.getOAuth2Clients("http", "first-domain", "com.test.pkg1", null);
    Assert.assertEquals(3, firstDomainHttpClients.size());
    for (OAuth2ClientInfo clientInfo : firstDomainHttpClients) {
        String[] segments = clientInfo.getUrl().split("/");
        String registrationId = segments[segments.length - 1];
        String appSecret = oAuth2Service.findAppSecret(UUID.fromString(registrationId), "com.test.pkg1");
        Assert.assertNotNull(appSecret);
        Assert.assertEquals("testPkg1AppSecret", appSecret);
        appSecret = oAuth2Service.findAppSecret(UUID.fromString(registrationId), "com.test.pkg2");
        Assert.assertNotNull(appSecret);
        Assert.assertEquals("testPkg2AppSecret", appSecret);
        appSecret = oAuth2Service.findAppSecret(UUID.fromString(registrationId), "com.test.pkg3");
        Assert.assertNull(appSecret);
    }
}
Also used : OAuth2Info(org.thingsboard.server.common.data.oauth2.OAuth2Info) OAuth2ClientInfo(org.thingsboard.server.common.data.oauth2.OAuth2ClientInfo) Test(org.junit.Test)

Aggregations

OAuth2Info (org.thingsboard.server.common.data.oauth2.OAuth2Info)14 Test (org.junit.Test)13 OAuth2ClientInfo (org.thingsboard.server.common.data.oauth2.OAuth2ClientInfo)7 OAuth2Registration (org.thingsboard.server.common.data.oauth2.OAuth2Registration)7 Arrays (java.util.Arrays)5 List (java.util.List)5 UUID (java.util.UUID)5 Collectors (java.util.stream.Collectors)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 MapperType (org.thingsboard.server.common.data.oauth2.MapperType)5 OAuth2CustomMapperConfig (org.thingsboard.server.common.data.oauth2.OAuth2CustomMapperConfig)5 OAuth2DomainInfo (org.thingsboard.server.common.data.oauth2.OAuth2DomainInfo)5 OAuth2MapperConfig (org.thingsboard.server.common.data.oauth2.OAuth2MapperConfig)5 OAuth2MobileInfo (org.thingsboard.server.common.data.oauth2.OAuth2MobileInfo)5 OAuth2ParamsInfo (org.thingsboard.server.common.data.oauth2.OAuth2ParamsInfo)5 OAuth2RegistrationInfo (org.thingsboard.server.common.data.oauth2.OAuth2RegistrationInfo)5 PlatformType (org.thingsboard.server.common.data.oauth2.PlatformType)5 SchemeType (org.thingsboard.server.common.data.oauth2.SchemeType)5 DataValidationException (org.thingsboard.server.dao.exception.DataValidationException)5 Lists (com.google.common.collect.Lists)4