Search in sources :

Example 6 with OAuth2ClientInfo

use of org.thingsboard.server.common.data.oauth2.OAuth2ClientInfo 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 7 with OAuth2ClientInfo

use of org.thingsboard.server.common.data.oauth2.OAuth2ClientInfo 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

Test (org.junit.Test)5 OAuth2ClientInfo (org.thingsboard.server.common.data.oauth2.OAuth2ClientInfo)5 OAuth2Info (org.thingsboard.server.common.data.oauth2.OAuth2Info)5 PlatformType (org.thingsboard.server.common.data.oauth2.PlatformType)4 SchemeType (org.thingsboard.server.common.data.oauth2.SchemeType)4 Lists (com.google.common.collect.Lists)3 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 List (java.util.List)3 UUID (java.util.UUID)3 Collectors (java.util.stream.Collectors)3 RandomStringUtils (org.apache.commons.lang3.RandomStringUtils)3 After (org.junit.After)3 Assert (org.junit.Assert)3 Before (org.junit.Before)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 MapperType (org.thingsboard.server.common.data.oauth2.MapperType)3 OAuth2CustomMapperConfig (org.thingsboard.server.common.data.oauth2.OAuth2CustomMapperConfig)3 OAuth2DomainInfo (org.thingsboard.server.common.data.oauth2.OAuth2DomainInfo)3 OAuth2MapperConfig (org.thingsboard.server.common.data.oauth2.OAuth2MapperConfig)3