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