use of org.thingsboard.server.common.data.oauth2.OAuth2Info in project thingsboard by thingsboard.
the class OAuth2ServiceImpl method findOAuth2Info.
@Override
public OAuth2Info findOAuth2Info() {
log.trace("Executing findOAuth2Info");
OAuth2Info oauth2Info = new OAuth2Info();
List<OAuth2Params> oauth2ParamsList = oauth2ParamsDao.find(TenantId.SYS_TENANT_ID);
oauth2Info.setEnabled(oauth2ParamsList.stream().anyMatch(param -> param.isEnabled()));
List<OAuth2ParamsInfo> oauth2ParamsInfos = new ArrayList<>();
oauth2Info.setOauth2ParamsInfos(oauth2ParamsInfos);
oauth2ParamsList.stream().sorted(Comparator.comparing(BaseData::getUuidId)).forEach(oauth2Params -> {
List<OAuth2Registration> registrations = oauth2RegistrationDao.findByOAuth2ParamsId(oauth2Params.getId().getId());
List<OAuth2Domain> domains = oauth2DomainDao.findByOAuth2ParamsId(oauth2Params.getId().getId());
List<OAuth2Mobile> mobiles = oauth2MobileDao.findByOAuth2ParamsId(oauth2Params.getId().getId());
oauth2ParamsInfos.add(OAuth2Utils.toOAuth2ParamsInfo(registrations, domains, mobiles));
});
return oauth2Info;
}
use of org.thingsboard.server.common.data.oauth2.OAuth2Info in project thingsboard by thingsboard.
the class BaseOAuth2ServiceTest method testFindAllRegistrations.
@Test
public void testFindAllRegistrations() {
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(), OAuth2ParamsInfo.builder().domainInfos(Lists.newArrayList(OAuth2DomainInfo.builder().name("second-domain").scheme(SchemeType.HTTPS).build(), OAuth2DomainInfo.builder().name("fifth-domain").scheme(SchemeType.HTTP).build())).clientRegistrations(Lists.newArrayList(validRegistrationInfo())).build()));
oAuth2Service.saveOAuth2Info(oAuth2Info);
List<OAuth2Registration> foundRegistrations = oAuth2Service.findAllRegistrations();
Assert.assertEquals(6, foundRegistrations.size());
oAuth2Info.getOauth2ParamsInfos().stream().flatMap(paramsInfo -> paramsInfo.getClientRegistrations().stream()).forEach(registrationInfo -> Assert.assertTrue(foundRegistrations.stream().anyMatch(registration -> registration.getClientId().equals(registrationInfo.getClientId()))));
}
use of org.thingsboard.server.common.data.oauth2.OAuth2Info in project thingsboard by thingsboard.
the class BaseOAuth2ServiceTest method testFindClientsByPackageAndPlatform.
@Test
public void testFindClientsByPackageAndPlatform() {
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", "testPkg1Callback"), validMobileInfo("com.test.pkg2", "testPkg2Callback"))).clientRegistrations(Lists.newArrayList(validRegistrationInfo("Google", Arrays.asList(PlatformType.WEB, PlatformType.ANDROID)), validRegistrationInfo("Facebook", Arrays.asList(PlatformType.IOS)), validRegistrationInfo("GitHub", Collections.emptyList()))).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", null, null);
Assert.assertEquals(3, firstDomainHttpClients.size());
List<OAuth2ClientInfo> pkg1Clients = oAuth2Service.getOAuth2Clients("http", "first-domain", "com.test.pkg1", null);
Assert.assertEquals(3, pkg1Clients.size());
List<OAuth2ClientInfo> pkg1AndroidClients = oAuth2Service.getOAuth2Clients("http", "first-domain", "com.test.pkg1", PlatformType.ANDROID);
Assert.assertEquals(2, pkg1AndroidClients.size());
Assert.assertTrue(pkg1AndroidClients.stream().anyMatch(client -> client.getName().equals("Google")));
Assert.assertTrue(pkg1AndroidClients.stream().anyMatch(client -> client.getName().equals("GitHub")));
List<OAuth2ClientInfo> pkg1IOSClients = oAuth2Service.getOAuth2Clients("http", "first-domain", "com.test.pkg1", PlatformType.IOS);
Assert.assertEquals(2, pkg1IOSClients.size());
Assert.assertTrue(pkg1IOSClients.stream().anyMatch(client -> client.getName().equals("Facebook")));
Assert.assertTrue(pkg1IOSClients.stream().anyMatch(client -> client.getName().equals("GitHub")));
}
use of org.thingsboard.server.common.data.oauth2.OAuth2Info in project thingsboard by thingsboard.
the class BaseOAuth2ServiceTest method testClearDomainParams.
@Test
public void testClearDomainParams() {
OAuth2Info oAuth2Info = createDefaultOAuth2Info();
oAuth2Service.saveOAuth2Info(oAuth2Info);
OAuth2Info foundOAuth2Info = oAuth2Service.findOAuth2Info();
Assert.assertNotNull(foundOAuth2Info);
Assert.assertEquals(oAuth2Info, foundOAuth2Info);
oAuth2Service.saveOAuth2Info(EMPTY_PARAMS);
OAuth2Info foundAfterClearClientsParams = oAuth2Service.findOAuth2Info();
Assert.assertNotNull(foundAfterClearClientsParams);
Assert.assertEquals(EMPTY_PARAMS, foundAfterClearClientsParams);
}
use of org.thingsboard.server.common.data.oauth2.OAuth2Info in project thingsboard by thingsboard.
the class BaseOAuth2ServiceTest method testGetOAuth2ClientsForHttpAndHttps.
@Test
public void testGetOAuth2ClientsForHttpAndHttps() {
List<OAuth2RegistrationInfo> firstGroup = Lists.newArrayList(validRegistrationInfo(), validRegistrationInfo(), validRegistrationInfo(), validRegistrationInfo());
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("first-domain").scheme(SchemeType.HTTPS).build())).mobileInfos(Collections.emptyList()).clientRegistrations(firstGroup).build()));
oAuth2Service.saveOAuth2Info(oAuth2Info);
OAuth2Info foundOAuth2Info = oAuth2Service.findOAuth2Info();
Assert.assertNotNull(foundOAuth2Info);
Assert.assertEquals(oAuth2Info, foundOAuth2Info);
List<OAuth2ClientInfo> firstGroupClientInfos = firstGroup.stream().map(registrationInfo -> new OAuth2ClientInfo(registrationInfo.getLoginButtonLabel(), registrationInfo.getLoginButtonIcon(), null)).collect(Collectors.toList());
List<OAuth2ClientInfo> firstDomainHttpClients = oAuth2Service.getOAuth2Clients("http", "first-domain", null, null);
Assert.assertEquals(firstGroupClientInfos.size(), firstDomainHttpClients.size());
firstGroupClientInfos.forEach(firstGroupClientInfo -> {
Assert.assertTrue(firstDomainHttpClients.stream().anyMatch(clientInfo -> clientInfo.getIcon().equals(firstGroupClientInfo.getIcon()) && clientInfo.getName().equals(firstGroupClientInfo.getName())));
});
List<OAuth2ClientInfo> firstDomainHttpsClients = oAuth2Service.getOAuth2Clients("https", "first-domain", null, null);
Assert.assertEquals(firstGroupClientInfos.size(), firstDomainHttpsClients.size());
firstGroupClientInfos.forEach(firstGroupClientInfo -> {
Assert.assertTrue(firstDomainHttpsClients.stream().anyMatch(clientInfo -> clientInfo.getIcon().equals(firstGroupClientInfo.getIcon()) && clientInfo.getName().equals(firstGroupClientInfo.getName())));
});
}
Aggregations