Search in sources :

Example 56 with GluuAttribute

use of org.gluu.model.GluuAttribute in project oxTrust by GluuFederation.

the class AttributeWebResource method deleteAttribute.

@DELETE
@Path(ApiConstants.INUM_PARAM_PATH)
@Operation(summary = "Delete gluu attribute", description = "Deletes a gluu attribute")
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = Constants.RESULT_SUCCESS), @ApiResponse(responseCode = "404", description = "Not found"), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response deleteAttribute(@PathParam(ApiConstants.INUM) @NotNull String inum) {
    log(logger, "Processing deleteAttribute()");
    try {
        Preconditions.checkNotNull(inum);
        GluuAttribute gluuAttribute = attributeService.getAttributeByInum(inum);
        if (gluuAttribute != null) {
            attributeService.removeAttribute(gluuAttribute);
            return Response.ok().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 : GluuAttribute(org.gluu.model.GluuAttribute) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 57 with GluuAttribute

use of org.gluu.model.GluuAttribute in project oxTrust by GluuFederation.

the class AttributeWebResource method updateAttribute.

@PUT
@Operation(summary = "Update new attribute", description = "Updates a gluu attribute")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = GluuAttribute.class)), description = Constants.RESULT_SUCCESS), @ApiResponse(responseCode = "404", description = "Not found"), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response updateAttribute(GluuAttribute gluuAttribute) {
    log(logger, "Processing updateAttribute()");
    try {
        Preconditions.checkNotNull(gluuAttribute, "Attempt to update null attribute");
        String inum = gluuAttribute.getInum();
        GluuAttribute existingAttribute = attributeService.getAttributeByInum(inum);
        if (existingAttribute != null) {
            gluuAttribute.setInum(existingAttribute.getInum());
            attributeService.updateAttribute(gluuAttribute);
            return Response.ok(attributeService.getAttributeByInum(existingAttribute.getInum())).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 : GluuAttribute(org.gluu.model.GluuAttribute) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 58 with GluuAttribute

use of org.gluu.model.GluuAttribute in project oxTrust by GluuFederation.

the class AttributeInventoryAction method submit.

public void submit() {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    List<String> checkedItems = new ArrayList<String>();
    for (GluuAttribute item : activeAttributeList) {
        if (checked.get(item.getDn())) {
            checkedItems.add(item.getDn());
        }
    }
    HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
    response.setContentType("text/plain");
    response.addHeader("Content-disposition", "attachment; filename=\"attributes.ldif\"");
    try (ServletOutputStream os = response.getOutputStream()) {
        ldifService.exportLDIFFile(checkedItems, os);
        os.flush();
        facesContext.responseComplete();
    } catch (Exception e) {
        log.error("\nFailure : " + e.toString() + "\n");
    }
    checked.clear();
}
Also used : FacesContext(javax.faces.context.FacesContext) ServletOutputStream(javax.servlet.ServletOutputStream) ArrayList(java.util.ArrayList) HttpServletResponse(javax.servlet.http.HttpServletResponse) GluuAttribute(org.gluu.model.GluuAttribute)

Example 59 with GluuAttribute

use of org.gluu.model.GluuAttribute in project oxTrust by GluuFederation.

the class CustomAttributeAction method selectCustomAttributes.

private void selectCustomAttributes(List<GluuCustomAttribute> customAttributes) {
    for (GluuCustomAttribute customAttribute : this.customAttributes) {
        GluuAttribute tmpAttribute = attributeInums.get(customAttribute.getMetadata().getInum());
        if ((tmpAttribute == null) || containsCustomAttribute(tmpAttribute)) {
            continue;
        }
        String id = this.attributeIds.get(tmpAttribute);
        this.availableAttributeIds.remove(id);
    }
}
Also used : GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) GluuAttribute(org.gluu.model.GluuAttribute)

Example 60 with GluuAttribute

use of org.gluu.model.GluuAttribute in project oxTrust by GluuFederation.

the class CustomAttributeAction method validateAttributeValues.

public void validateAttributeValues(ComponentSystemEvent event) {
    final FacesContext facesContext = FacesContext.getCurrentInstance();
    final List<Object> values = new ArrayList<Object>();
    event.getComponent().visitTree(VisitContext.createVisitContext(facesContext), new VisitCallback() {

        @Override
        public VisitResult visit(VisitContext context, UIComponent target) {
            if (target instanceof UIInput) {
                GluuAttribute attribute = (GluuAttribute) target.getAttributes().get("attribute");
                if (attribute != null) {
                    values.add(((UIInput) target).getValue());
                }
            }
            return VisitResult.ACCEPT;
        }
    });
    values.removeAll(Arrays.asList(null, ""));
    Set<Object> uniqValues = new HashSet<Object>(values);
    if (values.size() != uniqValues.size()) {
        event.getComponent().visitTree(VisitContext.createVisitContext(facesContext), new VisitCallback() {

            @Override
            public VisitResult visit(VisitContext context, UIComponent target) {
                if (target instanceof UIInput) {
                    GluuAttribute attribute = (GluuAttribute) target.getAttributes().get("attribute");
                    if (attribute != null) {
                        ((UIInput) target).setValid(false);
                        String message = "Please fill out an unique value for all of '" + attribute.getDisplayName() + "' fields";
                        facesMessages.add(target.getClientId(facesContext), FacesMessage.SEVERITY_ERROR, message);
                    }
                }
                return VisitResult.ACCEPT;
            }
        });
        facesContext.validationFailed();
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) VisitCallback(javax.faces.component.visit.VisitCallback) VisitContext(javax.faces.component.visit.VisitContext) ArrayList(java.util.ArrayList) UIComponent(javax.faces.component.UIComponent) UIInput(javax.faces.component.UIInput) GluuAttribute(org.gluu.model.GluuAttribute) VisitResult(javax.faces.component.visit.VisitResult) HashSet(java.util.HashSet)

Aggregations

GluuAttribute (org.gluu.model.GluuAttribute)68 ArrayList (java.util.ArrayList)21 GluuCustomAttribute (org.gluu.oxtrust.model.GluuCustomAttribute)10 IOException (java.io.IOException)8 Scope (org.oxauth.persistence.model.Scope)8 HttpEntity (org.apache.http.HttpEntity)7 HttpResponse (org.apache.http.HttpResponse)7 ParseException (org.apache.http.ParseException)7 Test (org.junit.Test)7 HttpGet (org.apache.http.client.methods.HttpGet)6 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)6 Filter (org.gluu.search.filter.Filter)5 JSONObject (org.json.JSONObject)4 Operation (io.swagger.v3.oas.annotations.Operation)3 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 FacesMessage (javax.faces.application.FacesMessage)3 UIInput (javax.faces.component.UIInput)3 AttributeValidation (org.gluu.model.attribute.AttributeValidation)3