Search in sources :

Example 1 with ConnectionInfos

use of org.olat.modules.teams.model.ConnectionInfos in project OpenOLAT by OpenOLAT.

the class TeamsConfigurationController method validateConnection.

private boolean validateConnection() {
    boolean allOk = true;
    TeamsErrors errors = new TeamsErrors();
    ConnectionInfos infos = teamsService.checkConnection(clientIdEl.getValue(), secretEl.getValue(), tenantEl.getValue(), producerIdEl.getValue(), errors);
    producerIdEl.clearError();
    if (infos != null) {
        if (StringHelper.containsNonWhitespace(producerIdEl.getValue()) && !StringHelper.containsNonWhitespace(infos.getProducerDisplayName())) {
            producerIdEl.setErrorKey("error.producerNotFound", null);
            allOk &= false;
        }
    }
    if (errors.hasErrors()) {
        clientIdEl.setErrorKey("error.connection", null);
    }
    return allOk;
}
Also used : TeamsErrors(org.olat.modules.teams.model.TeamsErrors) ConnectionInfos(org.olat.modules.teams.model.ConnectionInfos)

Example 2 with ConnectionInfos

use of org.olat.modules.teams.model.ConnectionInfos in project OpenOLAT by OpenOLAT.

the class TeamsConfigurationController method loadModel.

private void loadModel() {
    TeamsErrors errors = new TeamsErrors();
    ConnectionInfos infos = teamsService.checkConnection(errors);
    updateModel(infos);
}
Also used : TeamsErrors(org.olat.modules.teams.model.TeamsErrors) ConnectionInfos(org.olat.modules.teams.model.ConnectionInfos)

Example 3 with ConnectionInfos

use of org.olat.modules.teams.model.ConnectionInfos in project OpenOLAT by OpenOLAT.

the class TeamsConfigurationController method doCheckConnection.

private void doCheckConnection() {
    String producerId = producerIdEl.getValue();
    TeamsErrors errors = new TeamsErrors();
    ConnectionInfos infos = teamsService.checkConnection(clientIdEl.getValue(), secretEl.getValue(), tenantEl.getValue(), producerId, errors);
    updateModel(infos);
    if (infos == null) {
        if (errors.getErrors().isEmpty()) {
            showError("error.connection");
        } else {
            String formattedErrors = TeamsUIHelper.formatErrors(getTranslator(), errors);
            getWindowControl().setError(formattedErrors);
        }
    } else {
        if (StringHelper.containsNonWhitespace(producerId) && !StringHelper.containsNonWhitespace(infos.getProducerDisplayName())) {
            errors.append(new TeamsError(TeamsErrorCodes.producerNotFound));
        }
        if (errors.getErrors().isEmpty()) {
            showInfo("info.connection.ok");
        } else {
            String formattedErrors = TeamsUIHelper.formatErrors(getTranslator(), errors);
            getWindowControl().setError(formattedErrors);
        }
    }
}
Also used : TeamsError(org.olat.modules.teams.model.TeamsError) TeamsErrors(org.olat.modules.teams.model.TeamsErrors) ConnectionInfos(org.olat.modules.teams.model.ConnectionInfos)

Example 4 with ConnectionInfos

use of org.olat.modules.teams.model.ConnectionInfos in project OpenOLAT by OpenOLAT.

the class MicrosoftGraphDAO method check.

public ConnectionInfos check(String clientId, String clientSecret, String tenantGuid, String producerId, TeamsErrors errors) {
    try {
        MicrosoftGraphAccessTokenManager accessTokenManager = new MicrosoftGraphAccessTokenManager(clientId, clientSecret, tenantGuid);
        AuthenticationTokenProvider authProvider = new AuthenticationTokenProvider(accessTokenManager);
        GraphServiceClient<Request> client = client(authProvider);
        Organization org = getOrganisation(tenantGuid, client);
        String organisation = org == null ? null : org.displayName;
        String producerDisplayName = null;
        if (StringHelper.containsNonWhitespace(producerId)) {
            User producer = searchUserById(producerId, client, errors);
            producerDisplayName = producer == null ? null : producer.displayName;
        }
        return new ConnectionInfos(organisation, producerDisplayName);
    } catch (ClientException e) {
        errors.append(extractMsalFrom(e));
        log.error("", e);
        return null;
    } catch (NullPointerException | IllegalArgumentException e) {
        errors.append(new TeamsError(TeamsErrorCodes.httpClientError));
        log.error("", e);
        return null;
    } catch (Exception e) {
        errors.append(new TeamsError(e.getMessage()));
        log.error("", e);
        return null;
    }
}
Also used : Organization(com.microsoft.graph.models.Organization) User(com.microsoft.graph.models.User) TeamsError(org.olat.modules.teams.model.TeamsError) Request(okhttp3.Request) ClientException(com.microsoft.graph.core.ClientException) MsalException(com.microsoft.aad.msal4j.MsalException) ClientException(com.microsoft.graph.core.ClientException) ConnectionInfos(org.olat.modules.teams.model.ConnectionInfos)

Example 5 with ConnectionInfos

use of org.olat.modules.teams.model.ConnectionInfos in project OpenOLAT by OpenOLAT.

the class MicrosoftGraphDAO method check.

public final ConnectionInfos check(TeamsErrors errors) {
    try {
        GraphServiceClient<Request> client = client();
        String tenantId = teamsModule.getTenantGuid();
        Organization org = getOrganisation(tenantId, client);
        String organisation = org == null ? null : org.displayName;
        String producerDisplayName = null;
        if (StringHelper.containsNonWhitespace(teamsModule.getProducerId())) {
            User producer = searchUserById(teamsModule.getProducerId(), client, errors);
            producerDisplayName = producer == null ? null : producer.displayName;
        }
        return new ConnectionInfos(organisation, producerDisplayName);
    } catch (ClientException | NullPointerException | IllegalArgumentException e) {
        errors.append(new TeamsError(TeamsErrorCodes.httpClientError));
        log.error("", e);
        return null;
    } catch (Exception e) {
        errors.append(new TeamsError(e.getMessage(), ""));
        log.error("", e);
        return null;
    }
}
Also used : Organization(com.microsoft.graph.models.Organization) User(com.microsoft.graph.models.User) TeamsError(org.olat.modules.teams.model.TeamsError) Request(okhttp3.Request) ClientException(com.microsoft.graph.core.ClientException) ConnectionInfos(org.olat.modules.teams.model.ConnectionInfos) ClientException(com.microsoft.graph.core.ClientException) MsalException(com.microsoft.aad.msal4j.MsalException)

Aggregations

ConnectionInfos (org.olat.modules.teams.model.ConnectionInfos)6 TeamsErrors (org.olat.modules.teams.model.TeamsErrors)4 TeamsError (org.olat.modules.teams.model.TeamsError)3 MsalException (com.microsoft.aad.msal4j.MsalException)2 ClientException (com.microsoft.graph.core.ClientException)2 Organization (com.microsoft.graph.models.Organization)2 User (com.microsoft.graph.models.User)2 Request (okhttp3.Request)2 Test (org.junit.Test)1