Search in sources :

Example 1 with OAuth2Mobile

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

the class OAuth2MobileEntity method toData.

@Override
public OAuth2Mobile toData() {
    OAuth2Mobile mobile = new OAuth2Mobile();
    mobile.setId(new OAuth2MobileId(id));
    mobile.setCreatedTime(createdTime);
    mobile.setOauth2ParamsId(new OAuth2ParamsId(oauth2ParamsId));
    mobile.setPkgName(pkgName);
    mobile.setAppSecret(appSecret);
    return mobile;
}
Also used : OAuth2ParamsId(org.thingsboard.server.common.data.id.OAuth2ParamsId) OAuth2MobileId(org.thingsboard.server.common.data.id.OAuth2MobileId) OAuth2Mobile(org.thingsboard.server.common.data.oauth2.OAuth2Mobile)

Example 2 with OAuth2Mobile

use of org.thingsboard.server.common.data.oauth2.OAuth2Mobile 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;
}
Also used : Arrays(java.util.Arrays) BaseData(org.thingsboard.server.common.data.BaseData) OAuth2Params(org.thingsboard.server.common.data.oauth2.OAuth2Params) SchemeType(org.thingsboard.server.common.data.oauth2.SchemeType) Autowired(org.springframework.beans.factory.annotation.Autowired) OAuth2Mobile(org.thingsboard.server.common.data.oauth2.OAuth2Mobile) TenantId(org.thingsboard.server.common.data.id.TenantId) ArrayList(java.util.ArrayList) OAuth2BasicMapperConfig(org.thingsboard.server.common.data.oauth2.OAuth2BasicMapperConfig) Validator.validateId(org.thingsboard.server.dao.service.Validator.validateId) Validator.validateString(org.thingsboard.server.dao.service.Validator.validateString) CollectionUtils(org.apache.commons.collections.CollectionUtils) Service(org.springframework.stereotype.Service) PlatformType(org.thingsboard.server.common.data.oauth2.PlatformType) OAuth2ParamsInfo(org.thingsboard.server.common.data.oauth2.OAuth2ParamsInfo) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) TenantNameStrategyType(org.thingsboard.server.common.data.oauth2.TenantNameStrategyType) Transactional(javax.transaction.Transactional) OAuth2ClientInfo(org.thingsboard.server.common.data.oauth2.OAuth2ClientInfo) OAuth2CustomMapperConfig(org.thingsboard.server.common.data.oauth2.OAuth2CustomMapperConfig) MapperType(org.thingsboard.server.common.data.oauth2.MapperType) OAuth2DomainInfo(org.thingsboard.server.common.data.oauth2.OAuth2DomainInfo) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) OAuth2Info(org.thingsboard.server.common.data.oauth2.OAuth2Info) Consumer(java.util.function.Consumer) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) Slf4j(lombok.extern.slf4j.Slf4j) AbstractEntityService(org.thingsboard.server.dao.entity.AbstractEntityService) List(java.util.List) OAuth2MobileInfo(org.thingsboard.server.common.data.oauth2.OAuth2MobileInfo) OAuth2MapperConfig(org.thingsboard.server.common.data.oauth2.OAuth2MapperConfig) OAuth2Registration(org.thingsboard.server.common.data.oauth2.OAuth2Registration) Comparator(java.util.Comparator) OAuth2Domain(org.thingsboard.server.common.data.oauth2.OAuth2Domain) StringUtils(org.springframework.util.StringUtils) OAuth2RegistrationInfo(org.thingsboard.server.common.data.oauth2.OAuth2RegistrationInfo) OAuth2Info(org.thingsboard.server.common.data.oauth2.OAuth2Info) OAuth2ParamsInfo(org.thingsboard.server.common.data.oauth2.OAuth2ParamsInfo) ArrayList(java.util.ArrayList) OAuth2Registration(org.thingsboard.server.common.data.oauth2.OAuth2Registration) OAuth2Mobile(org.thingsboard.server.common.data.oauth2.OAuth2Mobile) BaseData(org.thingsboard.server.common.data.BaseData) OAuth2Params(org.thingsboard.server.common.data.oauth2.OAuth2Params) OAuth2Domain(org.thingsboard.server.common.data.oauth2.OAuth2Domain)

Example 3 with OAuth2Mobile

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

OAuth2Mobile (org.thingsboard.server.common.data.oauth2.OAuth2Mobile)3 Transactional (javax.transaction.Transactional)2 OAuth2Domain (org.thingsboard.server.common.data.oauth2.OAuth2Domain)2 OAuth2Params (org.thingsboard.server.common.data.oauth2.OAuth2Params)2 OAuth2Registration (org.thingsboard.server.common.data.oauth2.OAuth2Registration)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 List (java.util.List)1 UUID (java.util.UUID)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 Slf4j (lombok.extern.slf4j.Slf4j)1 CollectionUtils (org.apache.commons.collections.CollectionUtils)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Service (org.springframework.stereotype.Service)1 StringUtils (org.springframework.util.StringUtils)1 BaseData (org.thingsboard.server.common.data.BaseData)1 OAuth2MobileId (org.thingsboard.server.common.data.id.OAuth2MobileId)1 OAuth2ParamsId (org.thingsboard.server.common.data.id.OAuth2ParamsId)1