Search in sources :

Example 1 with Provider

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

the class PassportProviderWebResourceTest method getProvider.

private Provider getProvider(String name) {
    Provider provider = new Provider();
    provider.setEmailLinkingSafe(true);
    provider.setEnabled(false);
    provider.setOptions(new HashMap<>());
    provider.setDisplayName(name);
    provider.setPassportStrategyId("passport-saml");
    provider.setType("saml");
    provider.setMapping("saml_ldap_profile");
    provider.setRequestForEmail(true);
    return provider;
}
Also used : Provider(org.gluu.model.passport.Provider)

Example 2 with Provider

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

the class PassportProvidersAction method save.

public String save() {
    try {
        if (this.provider.getLogoImg().isEmpty()) {
            this.provider.setLogoImg(null);
        }
        if (this.provider.getPassportAuthnParams().isEmpty()) {
            this.provider.setPassportAuthnParams(null);
        }
        if (providerIdContainsBadCharacters()) {
            facesMessages.add(FacesMessage.SEVERITY_ERROR, "This provider id contains unauthorized characters.");
            return OxTrustConstants.RESULT_FAILURE;
        }
        if (!update) {
            if (providerIdIsInUse()) {
                facesMessages.add(FacesMessage.SEVERITY_ERROR, "This provider id is already in use. Please provide a new one.");
                return OxTrustConstants.RESULT_FAILURE;
            }
            setCallbackUrl();
            this.id = this.provider.getId();
            this.provider.setOptions(options.stream().filter(e -> e.getKey() != null).collect(Collectors.toMap(OptionEntry::getKey, OptionEntry::getValue)));
            loadProviders();
            this.providers.add(provider);
        } else {
            this.provider.setOptions(options.stream().filter(e -> e.getKey() != null).collect(Collectors.toMap(OptionEntry::getKey, OptionEntry::getValue)));
            loadProviders();
            for (Provider pro : this.providers) {
                if (pro.getId().equalsIgnoreCase(this.provider.getId())) {
                    this.providers.remove(pro);
                    this.providers.add(provider);
                    break;
                }
            }
        }
        performSave();
        if (!update) {
            facesMessages.add(FacesMessage.SEVERITY_INFO, "Provider '#{passportProvidersAction.provider.displayName}' added successfully");
            conversationService.endConversation();
            return OxTrustConstants.RESULT_SUCCESS;
        } else {
            facesMessages.add(FacesMessage.SEVERITY_INFO, "Provider '#{passportProvidersAction.provider.displayName}' updated successfully");
            conversationService.endConversation();
            return OxTrustConstants.RESULT_CONFIRM;
        }
    } 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 3 with Provider

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

the class PassportProvidersAction method add.

public String add() {
    try {
        loadProviders();
        this.update = false;
        this.provider = new Provider();
        this.provider.setOptions(new HashMap<>());
        this.options = this.provider.getOptions().entrySet().stream().map(e -> new OptionEntry(e.getKey(), e.getValue())).collect(Collectors.toList());
        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 4 with Provider

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

the class PassportProviderWebResource method updatePassportProvider.

@PUT
@Operation(summary = "Update passport provider", description = "Update passport provider")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = Provider.class)), description = "Success"), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response updatePassportProvider(Provider provider) {
    String id = provider.getId();
    id = id.equalsIgnoreCase("") ? null : id;
    log(logger, "Update passport provider " + 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 existingProvider = getExistingProvider(providers, id);
        if (existingProvider != null) {
            providers.remove(existingProvider);
            providers.add(provider);
            this.passportConfiguration.setProviders(providers);
            this.ldapOxPassportConfiguration.setPassportConfiguration(this.passportConfiguration);
            this.passportService.updateLdapOxPassportConfiguration(this.ldapOxPassportConfiguration);
            return Response.ok(provider).build();
        } else {
            return Response.status(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 5 with Provider

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

the class PassportProviderWebResource method getProviderById.

@GET
@Path(ApiConstants.ID_PARAM_PATH)
@Operation(summary = "Get passport provider by id", description = "Get passport provider by id")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = Provider.class)), description = "Success"), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { READ_ACCESS })
public Response getProviderById(@PathParam(ApiConstants.ID) @NotNull String id) {
    log(logger, "Get group having group" + id);
    id = id.equalsIgnoreCase("") ? null : id;
    try {
        Objects.requireNonNull(id, "inum should not be null");
        this.ldapOxPassportConfiguration = passportService.loadConfigurationFromLdap();
        this.passportConfiguration = this.ldapOxPassportConfiguration.getPassportConfiguration();
        List<Provider> providers = new ArrayList<>();
        providers.addAll(this.passportConfiguration.getProviders());
        Provider existingProvider = getExistingProvider(providers, id);
        if (existingProvider != null) {
            return Response.ok(existingProvider).build();
        } else {
            return Response.status(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)

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