Search in sources :

Example 1 with PlatformType

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

the class OAuth2Controller method getOAuth2Clients.

@ApiOperation(value = "Get OAuth2 clients (getOAuth2Clients)", notes = "Get the list of OAuth2 clients " + "to log in with, available for such domain scheme (HTTP or HTTPS) (if x-forwarded-proto request header is present - " + "the scheme is known from it) and domain name and port (port may be known from x-forwarded-port header)")
@RequestMapping(value = "/noauth/oauth2Clients", method = RequestMethod.POST)
@ResponseBody
public List<OAuth2ClientInfo> getOAuth2Clients(HttpServletRequest request, @ApiParam(value = "Mobile application package name, to find OAuth2 clients " + "where there is configured mobile application with such package name") @RequestParam(required = false) String pkgName, @ApiParam(value = "Platform type to search OAuth2 clients for which " + "the usage with this platform type is allowed in the settings. " + "If platform type is not one of allowable values - it will just be ignored", allowableValues = "WEB, ANDROID, IOS") @RequestParam(required = false) String platform) throws ThingsboardException {
    try {
        if (log.isDebugEnabled()) {
            log.debug("Executing getOAuth2Clients: [{}][{}][{}]", request.getScheme(), request.getServerName(), request.getServerPort());
            Enumeration<String> headerNames = request.getHeaderNames();
            while (headerNames.hasMoreElements()) {
                String header = headerNames.nextElement();
                log.debug("Header: {} {}", header, request.getHeader(header));
            }
        }
        PlatformType platformType = null;
        if (StringUtils.isNotEmpty(platform)) {
            try {
                platformType = PlatformType.valueOf(platform);
            } catch (Exception e) {
            }
        }
        return oAuth2Service.getOAuth2Clients(MiscUtils.getScheme(request), MiscUtils.getDomainNameAndPort(request), pkgName, platformType);
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : PlatformType(org.thingsboard.server.common.data.oauth2.PlatformType) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with PlatformType

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

the class OAuth2ServiceImpl method getOAuth2Clients.

@Override
public List<OAuth2ClientInfo> getOAuth2Clients(String domainSchemeStr, String domainName, String pkgName, PlatformType platformType) {
    log.trace("Executing getOAuth2Clients [{}://{}] pkgName=[{}] platformType=[{}]", domainSchemeStr, domainName, pkgName, platformType);
    if (domainSchemeStr == null) {
        throw new IncorrectParameterException(INCORRECT_DOMAIN_SCHEME);
    }
    SchemeType domainScheme;
    try {
        domainScheme = SchemeType.valueOf(domainSchemeStr.toUpperCase());
    } catch (IllegalArgumentException e) {
        throw new IncorrectParameterException(INCORRECT_DOMAIN_SCHEME);
    }
    validateString(domainName, INCORRECT_DOMAIN_NAME + domainName);
    return oauth2RegistrationDao.findEnabledByDomainSchemesDomainNameAndPkgNameAndPlatformType(Arrays.asList(domainScheme, SchemeType.MIXED), domainName, pkgName, platformType).stream().map(OAuth2Utils::toClientInfo).collect(Collectors.toList());
}
Also used : SchemeType(org.thingsboard.server.common.data.oauth2.SchemeType) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)1 PlatformType (org.thingsboard.server.common.data.oauth2.PlatformType)1 SchemeType (org.thingsboard.server.common.data.oauth2.SchemeType)1 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)1