Search in sources :

Example 6 with Provider

use of org.gluu.model.passport.Provider in project oxTrust by GluuFederation.

the class PassportProvidersAction method update.

public String update() {
    try {
        this.update = true;
        loadProviders();
        for (Provider pro : providers) {
            if (pro.getId().equalsIgnoreCase(id)) {
                this.provider = pro;
                this.optionsKeys = new ArrayList<>(this.provider.getOptions().keySet());
                break;
            }
        }
        this.options = this.provider.getOptions().entrySet().stream().map(e -> new OptionEntry(e.getKey(), e.getValue())).collect(Collectors.toList());
        this.options.sort(Comparator.comparing(OptionEntry::getKey));
        return OxTrustConstants.RESULT_SUCCESS;
    } catch (Exception e) {
        log.debug("", e);
        conversationService.endConversation();
        return OxTrustConstants.RESULT_FAILURE;
    }
}
Also used : OptionEntry(org.gluu.oxtrust.model.OptionEntry) PassportProvider(org.gluu.oxtrust.model.PassportProvider) Provider(org.gluu.model.passport.Provider)

Example 7 with Provider

use of org.gluu.model.passport.Provider in project oxTrust by GluuFederation.

the class PassportProvidersAction method providerIdIsInUse.

private boolean providerIdIsInUse() {
    loadProviders();
    boolean result = false;
    for (Provider provider : this.providers) {
        if (provider.getId().equalsIgnoreCase(this.provider.getId())) {
            result = true;
            break;
        }
    }
    return result;
}
Also used : PassportProvider(org.gluu.oxtrust.model.PassportProvider) Provider(org.gluu.model.passport.Provider)

Example 8 with Provider

use of org.gluu.model.passport.Provider in project oxTrust by GluuFederation.

the class PassportProviderWebResource method deleteProvider.

@DELETE
@Path(ApiConstants.ID_PARAM_PATH)
@Operation(summary = "Delete passport provider", description = "Delete a passport provider")
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Success"), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response deleteProvider(@PathParam(ApiConstants.ID) @NotNull String id) {
    log(logger, "Delete passport provider having id " + id);
    try {
        Objects.requireNonNull(id, "id should not be null");
        this.ldapOxPassportConfiguration = passportService.loadConfigurationFromLdap();
        this.passportConfiguration = this.ldapOxPassportConfiguration.getPassportConfiguration();
        List<Provider> providers = new ArrayList<>();
        providers.addAll(this.passportConfiguration.getProviders());
        Provider found = null;
        for (Provider provider : providers) {
            if (id.equalsIgnoreCase(provider.getId())) {
                found = provider;
                break;
            }
        }
        if (found != null) {
            providers.remove(found);
            this.passportConfiguration.setProviders(providers);
            this.ldapOxPassportConfiguration.setPassportConfiguration(this.passportConfiguration);
            this.passportService.updateLdapOxPassportConfiguration(this.ldapOxPassportConfiguration);
            return Response.ok().build();
        } else {
            return Response.ok(Response.Status.NOT_FOUND).build();
        }
    } catch (Exception e) {
        log(logger, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : ArrayList(java.util.ArrayList) Provider(org.gluu.model.passport.Provider) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 9 with Provider

use of org.gluu.model.passport.Provider in project oxTrust by GluuFederation.

the class PassportProviderWebResourceTest method updateProviderTest.

@Test
public void updateProviderTest() {
    String name = "ApiLinkedInUpdated";
    Provider provider = getProvider(name);
    HttpPost request = new HttpPost(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.PASSPORT + ApiConstants.PROVIDERS);
    try {
        HttpEntity entity = new ByteArrayEntity(mapper.writeValueAsString(provider).toString().getBytes("UTF-8"), ContentType.APPLICATION_FORM_URLENCODED);
        request.setEntity(entity);
        request.setHeader(CONTENT_TYPE, MediaType.APPLICATION_JSON);
        HttpResponse response = handle(request);
        Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
        HttpEntity result = response.getEntity();
        Provider myGroup = mapper.readValue(EntityUtils.toString(result), Provider.class);
        Assert.assertEquals(myGroup.getDisplayName(), name);
        myGroup.setDisplayName(myGroup.getDisplayName() + " Updated");
        HttpPut second = new HttpPut(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.PASSPORT + ApiConstants.PROVIDERS);
        entity = new ByteArrayEntity(mapper.writeValueAsString(myGroup).toString().getBytes("UTF-8"), ContentType.APPLICATION_FORM_URLENCODED);
        second.setEntity(entity);
        second.setHeader(CONTENT_TYPE, MediaType.APPLICATION_JSON);
        response = handle(second);
        Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    } catch (ParseException | IOException e) {
        e.printStackTrace();
        Assert.assertTrue(false);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpEntity(org.apache.http.HttpEntity) ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) HttpResponse(org.apache.http.HttpResponse) ParseException(org.apache.http.ParseException) IOException(java.io.IOException) HttpPut(org.apache.http.client.methods.HttpPut) Provider(org.gluu.model.passport.Provider) Test(org.junit.Test)

Example 10 with Provider

use of org.gluu.model.passport.Provider in project oxTrust by GluuFederation.

the class PassportProviderWebResourceTest method listProviderTest.

@Test
public void listProviderTest() {
    HttpUriRequest request = new HttpGet(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.PASSPORT + ApiConstants.PROVIDERS);
    HttpResponse response = handle(request);
    Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    HttpEntity entity = response.getEntity();
    try {
        String content = EntityUtils.toString(entity);
        Provider[] goups = mapper.readValue(content, Provider[].class);
        Assert.assertTrue(goups.length >= 0);
    } catch (ParseException | IOException e) {
        e.printStackTrace();
        Assert.assertTrue(false);
    }
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpEntity(org.apache.http.HttpEntity) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) ParseException(org.apache.http.ParseException) IOException(java.io.IOException) Provider(org.gluu.model.passport.Provider) Test(org.junit.Test)

Aggregations

Provider (org.gluu.model.passport.Provider)11 PassportProvider (org.gluu.oxtrust.model.PassportProvider)4 Operation (io.swagger.v3.oas.annotations.Operation)3 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HttpEntity (org.apache.http.HttpEntity)3 HttpResponse (org.apache.http.HttpResponse)3 ParseException (org.apache.http.ParseException)3 OptionEntry (org.gluu.oxtrust.model.OptionEntry)3 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)3 Test (org.junit.Test)3 HttpPost (org.apache.http.client.methods.HttpPost)2 ByteArrayEntity (org.apache.http.entity.ByteArrayEntity)2 HttpGet (org.apache.http.client.methods.HttpGet)1 HttpPut (org.apache.http.client.methods.HttpPut)1 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)1