use of org.apache.harmony.security.x509.Extension in project oxTrust by GluuFederation.
the class UserExtensionsTest method testCreatePersonFromUserObject.
@Test(dependsOnMethods = "testCreatePersonFromJsonString")
@Parameters
public void testCreatePersonFromUserObject() throws Exception {
System.out.println(" testCreatePersonFromUserObject() ");
// Create custom attributes
// String, not
GluuAttribute scimCustomFirst = null;
// multi-valued
if (attributeService.getAttributeByName("scimCustomFirst") == null) {
scimCustomFirst = createCustomAttribute(attributeService, schemaService, appConfiguration, "scimCustomFirst", "Custom First", "First custom attribute", GluuAttributeDataType.STRING, OxMultivalued.FALSE);
}
// Date, multi-valued
GluuAttribute scimCustomSecond = null;
if (attributeService.getAttributeByName("scimCustomSecond") == null) {
scimCustomSecond = createCustomAttribute(attributeService, schemaService, appConfiguration, "scimCustomSecond", "Custom Second", "Second custom attribute", GluuAttributeDataType.DATE, OxMultivalued.TRUE);
}
// Numeric, not
GluuAttribute scimCustomThird = null;
// multi-valued
if (attributeService.getAttributeByName("scimCustomThird") == null) {
scimCustomThird = createCustomAttribute(attributeService, schemaService, appConfiguration, "scimCustomThird", "Custom Third", "Third custom attribute", GluuAttributeDataType.NUMERIC, OxMultivalued.FALSE);
}
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
User user = createUserObject();
// Create Person
GluuCustomPerson gluuPerson = copyUtils2.copy(user, null, false);
assertNotNull(gluuPerson, "gluuPerson is null!");
System.out.println(">>>>>>>>>> gluuPerson.getUid() = " + gluuPerson.getUid());
String inum = personService.generateInumForNewPerson();
String dn = personService.getDnForPerson(inum);
String iname = personService.generateInameForNewPerson(user.getUserName());
gluuPerson.setDn(dn);
gluuPerson.setInum(inum);
gluuPerson.setIname(iname);
gluuPerson.setCommonName(gluuPerson.getGivenName() + " " + gluuPerson.getSurname());
personService.addPerson(gluuPerson);
// Retrieve Person
GluuCustomPerson retrievedPerson = personService.getPersonByUid(gluuPerson.getUid());
assertNotNull(retrievedPerson, "Failed to find person.");
User newPerson = copyUtils2.copy(retrievedPerson, null);
Extension extension = newPerson.getExtension(Constants.USER_EXT_SCHEMA_ID);
assertNotNull(extension, "(Persistence) Custom extension not persisted.");
Extension.Field customFirstField = extension.getFields().get("scimCustomFirst");
assertNotNull(customFirstField, "(Persistence) \"scimCustomFirst\" field not persisted.");
assertEquals(customFirstField.getValue(), "customFirstValue");
System.out.println("##### (Persistence) customFirstField.getValue() = " + customFirstField.getValue());
Extension.Field customSecondField = extension.getFields().get("scimCustomSecond");
assertNotNull(customSecondField, "(Persistence) \"scimCustomSecond\" field not persisted.");
List<Date> dateList = Arrays.asList(mapper.readValue(customSecondField.getValue(), Date[].class));
assertEquals(dateList.size(), 2);
System.out.println("##### (Persistence) dateList.get(0) = " + dateList.get(0));
System.out.println("##### (Persistence) dateList.get(1) = " + dateList.get(1));
Extension.Field customThirdField = extension.getFields().get("scimCustomThird");
assertNotNull(customThirdField, "(Persistence) \"scimCustomThird\" field not persisted.");
assertEquals(new BigDecimal(customThirdField.getValue()), new BigDecimal(3000));
System.out.println("##### (Persistence) customThirdField.getValue() = " + customThirdField.getValue());
// Remove Person
memberService.removePerson(retrievedPerson);
// Remove custom attributes
// schemaService.removeAttributeTypeFromObjectClass(scimCustomFirst.getOrigin(),
// scimCustomFirst.getName());
// schemaService.removeStringAttribute(scimCustomFirst.getName());
// attributeService.removeAttribute(scimCustomFirst);
// schemaService.removeAttributeTypeFromObjectClass(scimCustomSecond.getOrigin(),
// scimCustomSecond.getName());
// schemaService.removeStringAttribute(scimCustomSecond.getName());
// attributeService.removeAttribute(scimCustomSecond);
// schemaService.removeAttributeTypeFromObjectClass(scimCustomThird.getOrigin(),
// scimCustomThird.getName());
// schemaService.removeStringAttribute(scimCustomThird.getName());
// attributeService.removeAttribute(scimCustomThird);
}
use of org.apache.harmony.security.x509.Extension in project oxTrust by GluuFederation.
the class UserDeserializer method deserialize.
@Override
public User deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
log.info(" deserialize() ");
try {
JsonNode rootNode = jsonParser.readValueAsTree();
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES);
User user = mapper.readValue(rootNode.toString(), User.class);
if (user.getSchemas() == null) {
throw new IllegalArgumentException("Required field \"schemas\" is null or missing.");
} else if (!user.getSchemas().contains(Constants.USER_CORE_SCHEMA_ID)) {
throw new IllegalArgumentException("User Core schema is required.");
} else if (user.getSchemas().contains(Constants.USER_EXT_SCHEMA_ID)) {
JsonNode userExtensionNode = rootNode.get(Constants.USER_EXT_SCHEMA_ID);
if (userExtensionNode != null) {
ExtensionDeserializer deserializer = new ExtensionDeserializer();
deserializer.setId(Constants.USER_EXT_SCHEMA_ID);
SimpleModule deserializerModule = new SimpleModule("ExtensionDeserializerModule", new Version(1, 0, 0, ""));
deserializerModule.addDeserializer(Extension.class, deserializer);
mapper.registerModule(deserializerModule);
Extension extension = mapper.readValue(userExtensionNode.toString(), Extension.class);
user.addExtension(extension);
} else {
throw new IllegalArgumentException("User Extension schema is indicated, but value body is absent.");
}
}
return user;
} catch (Exception e) {
e.printStackTrace();
throw new IOException(INTERNAL_SERVER_ERROR_MESSAGE);
}
}
use of org.apache.harmony.security.x509.Extension in project oxTrust by GluuFederation.
the class UserSerializer method serializeUserExtension.
protected void serializeUserExtension(Map.Entry<String, JsonNode> rootNodeEntry, ObjectMapper mapper, User user, JsonGenerator jsonGenerator) throws Exception {
Extension extension = user.getExtension(rootNodeEntry.getKey());
Map<String, Object> list = new HashMap<String, Object>();
boolean enclosingWritten = false;
for (Map.Entry<String, Extension.Field> extEntry : extension.getFields().entrySet()) {
if (attributes != null && attributes.size() > 0) {
for (String attribute : attributes) {
attribute = FilterUtil.stripScim2Schema(attribute);
if (extEntry.getKey().equalsIgnoreCase(attribute)) {
if (!enclosingWritten) {
jsonGenerator.writeFieldName(rootNodeEntry.getKey());
enclosingWritten = true;
}
break;
}
}
} else {
if (!enclosingWritten) {
jsonGenerator.writeFieldName(rootNodeEntry.getKey());
enclosingWritten = true;
}
}
if (enclosingWritten) {
GluuAttribute gluuAttribute = attributeService.getAttributeByName(extEntry.getKey());
GluuAttributeDataType attributeDataType = gluuAttribute.getDataType();
if ((gluuAttribute.getOxMultivaluedAttribute() != null) && gluuAttribute.getOxMultivaluedAttribute().equals(OxMultivalued.TRUE)) {
if (attributeDataType.equals(GluuAttributeDataType.STRING) || attributeDataType.equals(GluuAttributeDataType.PHOTO)) {
List<String> stringList = Arrays.asList(mapper.readValue(extEntry.getValue().getValue(), String[].class));
list.put(extEntry.getKey(), stringList);
} else if (attributeDataType.equals(GluuAttributeDataType.DATE)) {
List<Date> dateList = Arrays.asList(mapper.readValue(extEntry.getValue().getValue(), Date[].class));
List<String> stringList = new ArrayList<String>();
DateTimeFormatter dateTimeFormatter = ISODateTimeFormat.dateTime().withZoneUTC();
for (Date date : dateList) {
String dateString = dateTimeFormatter.print(date.getTime());
stringList.add(dateString);
}
list.put(extEntry.getKey(), stringList);
} else if (attributeDataType.equals(GluuAttributeDataType.NUMERIC)) {
List<BigDecimal> numberList = Arrays.asList(mapper.readValue(extEntry.getValue().getValue(), BigDecimal[].class));
list.put(extEntry.getKey(), numberList);
}
} else {
list.put(extEntry.getKey(), extEntry.getValue().getValue());
}
}
}
if (enclosingWritten) {
jsonGenerator.writeObject(list);
}
}
use of org.apache.harmony.security.x509.Extension in project robovm by robovm.
the class X509CRLEntryObject method getExtensionOIDs.
private Set getExtensionOIDs(boolean critical) {
Extensions extensions = c.getExtensions();
if (extensions != null) {
Set set = new HashSet();
Enumeration e = extensions.oids();
while (e.hasMoreElements()) {
ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) e.nextElement();
Extension ext = extensions.getExtension(oid);
if (critical == ext.isCritical()) {
set.add(oid.getId());
}
}
return set;
}
return null;
}
use of org.apache.harmony.security.x509.Extension in project robovm by robovm.
the class X509CRLObject method isRevoked.
/**
* Checks whether the given certificate is on this CRL.
*
* @param cert the certificate to check for.
* @return true if the given certificate is on this CRL,
* false otherwise.
*/
public boolean isRevoked(Certificate cert) {
if (!cert.getType().equals("X.509")) {
throw new RuntimeException("X.509 CRL used with non X.509 Cert");
}
TBSCertList.CRLEntry[] certs = c.getRevokedCertificates();
X500Name caName = c.getIssuer();
if (certs != null) {
BigInteger serial = ((X509Certificate) cert).getSerialNumber();
for (int i = 0; i < certs.length; i++) {
if (isIndirect && certs[i].hasExtensions()) {
Extension currentCaName = certs[i].getExtensions().getExtension(Extension.certificateIssuer);
if (currentCaName != null) {
caName = X500Name.getInstance(GeneralNames.getInstance(currentCaName.getParsedValue()).getNames()[0].getName());
}
}
if (certs[i].getUserCertificate().getValue().equals(serial)) {
X500Name issuer;
if (cert instanceof X509Certificate) {
issuer = X500Name.getInstance(((X509Certificate) cert).getIssuerX500Principal().getEncoded());
} else {
try {
issuer = org.bouncycastle.asn1.x509.Certificate.getInstance(cert.getEncoded()).getIssuer();
} catch (CertificateEncodingException e) {
throw new RuntimeException("Cannot process certificate");
}
}
if (!caName.equals(issuer)) {
return false;
}
return true;
}
}
}
return false;
}
Aggregations