Search in sources :

Example 11 with OAuth2Registration

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

the class OAuth2ServiceImpl method saveOAuth2Info.

@Override
@Transactional
public void saveOAuth2Info(OAuth2Info oauth2Info) {
    log.trace("Executing saveOAuth2Info [{}]", oauth2Info);
    oauth2InfoValidator.accept(oauth2Info);
    oauth2ParamsDao.deleteAll();
    oauth2Info.getOauth2ParamsInfos().forEach(oauth2ParamsInfo -> {
        OAuth2Params oauth2Params = OAuth2Utils.infoToOAuth2Params(oauth2Info);
        OAuth2Params savedOauth2Params = oauth2ParamsDao.save(TenantId.SYS_TENANT_ID, oauth2Params);
        oauth2ParamsInfo.getClientRegistrations().forEach(registrationInfo -> {
            OAuth2Registration registration = OAuth2Utils.toOAuth2Registration(savedOauth2Params.getId(), registrationInfo);
            oauth2RegistrationDao.save(TenantId.SYS_TENANT_ID, registration);
        });
        oauth2ParamsInfo.getDomainInfos().forEach(domainInfo -> {
            OAuth2Domain domain = OAuth2Utils.toOAuth2Domain(savedOauth2Params.getId(), domainInfo);
            oauth2DomainDao.save(TenantId.SYS_TENANT_ID, domain);
        });
        if (oauth2ParamsInfo.getMobileInfos() != null) {
            oauth2ParamsInfo.getMobileInfos().forEach(mobileInfo -> {
                OAuth2Mobile mobile = OAuth2Utils.toOAuth2Mobile(savedOauth2Params.getId(), mobileInfo);
                oauth2MobileDao.save(TenantId.SYS_TENANT_ID, mobile);
            });
        }
    });
}
Also used : OAuth2Params(org.thingsboard.server.common.data.oauth2.OAuth2Params) OAuth2Registration(org.thingsboard.server.common.data.oauth2.OAuth2Registration) OAuth2Mobile(org.thingsboard.server.common.data.oauth2.OAuth2Mobile) OAuth2Domain(org.thingsboard.server.common.data.oauth2.OAuth2Domain) Transactional(javax.transaction.Transactional)

Aggregations

OAuth2MapperConfig (org.thingsboard.server.common.data.oauth2.OAuth2MapperConfig)8 OAuth2Registration (org.thingsboard.server.common.data.oauth2.OAuth2Registration)6 OAuth2User (org.thingsboard.server.dao.oauth2.OAuth2User)5 Arrays (java.util.Arrays)3 UUID (java.util.UUID)3 Collectors (java.util.stream.Collectors)3 MapperType (org.thingsboard.server.common.data.oauth2.MapperType)3 OAuth2CustomMapperConfig (org.thingsboard.server.common.data.oauth2.OAuth2CustomMapperConfig)3 OAuth2Info (org.thingsboard.server.common.data.oauth2.OAuth2Info)3 PlatformType (org.thingsboard.server.common.data.oauth2.PlatformType)3 IOException (java.io.IOException)2 Collections (java.util.Collections)2 List (java.util.List)2 Transactional (javax.transaction.Transactional)2 Test (org.junit.Test)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 OAuth2BasicMapperConfig (org.thingsboard.server.common.data.oauth2.OAuth2BasicMapperConfig)2 OAuth2ClientInfo (org.thingsboard.server.common.data.oauth2.OAuth2ClientInfo)2 OAuth2DomainInfo (org.thingsboard.server.common.data.oauth2.OAuth2DomainInfo)2 OAuth2MobileInfo (org.thingsboard.server.common.data.oauth2.OAuth2MobileInfo)2