Search in sources :

Example 1 with GluuAttribute

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

the class ScopeServiceTest method getClaims_GluuAttributeClaimNameBlank_EmptyResult.

@Test
public void getClaims_GluuAttributeClaimNameBlank_EmptyResult() throws Exception {
    User user = new User();
    Scope scope = new Scope();
    scope.setOxAuthClaims(Lists.newArrayList("claim1", "claim2"));
    when(attributeService.getAttributeByDn(anyString())).thenReturn(new GluuAttribute());
    Map<String, Object> result = scopeService.getClaims(user, scope);
    assertNotNull(result);
    assertEquals(result.size(), 0);
    verify(log, times(2)).error(startsWith("Failed to get claim because claim name is not set for attribute"), (Object) isNull());
    verifyNoMoreInteractions(log);
    verifyNoMoreInteractions(attributeService);
}
Also used : User(org.gluu.oxauth.model.common.User) Scope(org.oxauth.persistence.model.Scope) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) GluuAttribute(org.gluu.model.GluuAttribute) Test(org.testng.annotations.Test)

Example 2 with GluuAttribute

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

the class ClientInfoRestWebServiceImpl method getJSonResponse.

/**
 * Builds a JSon String with the response parameters.
 */
public String getJSonResponse(Client client, Set<String> scopes) {
    JSONObject jsonObj = new JSONObject();
    try {
        for (String scopeName : scopes) {
            Scope scope = scopeService.getScopeById(scopeName);
            if (scope.getOxAuthClaims() != null) {
                for (String claimDn : scope.getOxAuthClaims()) {
                    GluuAttribute attribute = attributeService.getAttributeByDn(claimDn);
                    String attributeName = attribute.getName();
                    Object attributeValue = clientService.getAttribute(client, attribute.getName());
                    jsonObj.put(attributeName, attributeValue);
                }
            }
        }
    } catch (JSONException e) {
        log.error(e.getMessage(), e);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return jsonObj.toString();
}
Also used : JSONObject(org.json.JSONObject) Scope(org.oxauth.persistence.model.Scope) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) GluuAttribute(org.gluu.model.GluuAttribute)

Example 3 with GluuAttribute

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

the class AttributeValidator method validate.

@Override
public void validate(FacesContext context, UIComponent comp, Object value) {
    GluuAttribute attribute = (GluuAttribute) comp.getAttributes().get("attribute");
    if (attribute == null) {
        ((UIInput) comp).setValid(true);
        return;
    }
    AttributeValidation attributeValidation = attribute.getAttributeValidation();
    Integer minvalue = attributeValidation != null ? attributeValidation.getMinLength() : null;
    Integer maxValue = attributeValidation != null ? attributeValidation.getMaxLength() : null;
    String regexpValue = attributeValidation != null ? attributeValidation.getRegexp() : null;
    String attributeValue = (String) value;
    // Minimum length validation
    if (minvalue != null) {
        int min = attributeValidation.getMinLength();
        if ((attributeValue != null) && (attributeValue.length() < min)) {
            ((UIInput) comp).setValid(false);
            FacesMessage message = new FacesMessage(attribute.getDisplayName() + " should be at least " + min + " symbols. ");
            message.setSeverity(FacesMessage.SEVERITY_ERROR);
            context.addMessage(comp.getClientId(context), message);
        }
    }
    // default maxlength
    int max = 400;
    if (maxValue != null) {
        max = attributeValidation.getMaxLength();
    }
    // Maximum Length validation
    if ((attributeValue != null) && (attributeValue.length() > max)) {
        ((UIInput) comp).setValid(false);
        FacesMessage message = new FacesMessage(attribute.getDisplayName() + " should not exceed " + max + " symbols. ");
        message.setSeverity(FacesMessage.SEVERITY_ERROR);
        context.addMessage(comp.getClientId(context), message);
    }
    if ((attribute.getName().equalsIgnoreCase("mail") && ((regexpValue == null) || (StringHelper.isEmpty(regexpValue))))) {
        regexpValue = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@" + "[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$";
    }
    if ((regexpValue != null) && StringHelper.isNotEmpty(regexpValue)) {
        java.util.regex.Pattern pattern = java.util.regex.Pattern.compile(regexpValue);
        if ((attributeValue != null) && !(attributeValue.trim().equals(""))) {
            java.util.regex.Matcher matcher = pattern.matcher(attributeValue);
            boolean flag = matcher.matches();
            if (!flag) {
                ((UIInput) comp).setValid(false);
                FacesMessage message = new FacesMessage(attribute.getDisplayName() + " Format is invalid. ");
                message.setSeverity(FacesMessage.SEVERITY_ERROR);
                context.addMessage(comp.getClientId(context), message);
            }
        }
    }
}
Also used : AttributeValidation(org.gluu.model.attribute.AttributeValidation) UIInput(javax.faces.component.UIInput) FacesMessage(javax.faces.application.FacesMessage) GluuAttribute(org.gluu.model.GluuAttribute)

Example 4 with GluuAttribute

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

the class AttributeService method getAttributesByAttribute.

public List<GluuAttribute> getAttributesByAttribute(String attributeName, String attributeValue, String baseDn) {
    String[] targetArray = new String[] { attributeValue };
    Filter filter = Filter.createSubstringFilter(attributeName, null, targetArray, null);
    List<GluuAttribute> result = persistenceEntryManager.findEntries(baseDn, GluuAttribute.class, filter);
    return result;
}
Also used : Filter(org.gluu.search.filter.Filter) GluuAttribute(org.gluu.model.GluuAttribute)

Example 5 with GluuAttribute

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

the class CustomAttributeAction method addMultiValuesInAttributes.

public void addMultiValuesInAttributes(String inum, boolean mandatory) {
    if (StringHelper.isEmpty(inum)) {
        return;
    }
    GluuAttribute tmpAttribute = this.attributeInums.get(inum);
    if (tmpAttribute == null) {
        return;
    }
    String id = this.attributeIds.get(tmpAttribute);
    this.availableAttributeIds.remove(id);
    String[] values = null;
    int index = 0;
    for (GluuCustomAttribute customAttribute : this.customAttributes) {
        if (tmpAttribute.equals(customAttribute.getMetadata())) {
            values = customAttribute.getValues();
            break;
        }
        index++;
    }
    String[] newValues = new String[values.length + 1];
    System.arraycopy(values, 0, newValues, 0, values.length);
    removeCustomAttribute(inum);
    GluuCustomAttribute tmpGluuPersonAttribute = new GluuCustomAttribute(tmpAttribute.getName(), newValues, true, mandatory);
    tmpGluuPersonAttribute.setMetadata(tmpAttribute);
    this.customAttributes.add(index, tmpGluuPersonAttribute);
}
Also used : GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) GluuAttribute(org.gluu.model.GluuAttribute)

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