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;
}
}
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;
}
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();
}
}
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);
}
}
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);
}
}
Aggregations