use of org.apache.syncope.common.lib.to.ConnInstanceTO in project syncope by apache.
the class LoggerITCase method customAuditAppender.
@Test
public void customAuditAppender() throws IOException, InterruptedException {
try (InputStream propStream = getClass().getResourceAsStream("/core-test.properties")) {
Properties props = new Properties();
props.load(propStream);
String auditFilePath = props.getProperty("test.log.dir") + File.separator + "audit_for_Master_file.log";
String auditNoRewriteFilePath = props.getProperty("test.log.dir") + File.separator + "audit_for_Master_norewrite_file.log";
// 1. Enable audit for resource update -> catched by FileRewriteAuditAppender
AuditLoggerName auditLoggerResUpd = new AuditLoggerName(EventCategoryType.LOGIC, ResourceLogic.class.getSimpleName(), null, "update", AuditElements.Result.SUCCESS);
LoggerTO loggerTOUpd = new LoggerTO();
loggerTOUpd.setKey(auditLoggerResUpd.toLoggerName());
loggerTOUpd.setLevel(LoggerLevel.DEBUG);
loggerService.update(LoggerType.AUDIT, loggerTOUpd);
// 2. Enable audit for connector update -> NOT catched by FileRewriteAuditAppender
AuditLoggerName auditLoggerConnUpd = new AuditLoggerName(EventCategoryType.LOGIC, ConnectorLogic.class.getSimpleName(), null, "update", AuditElements.Result.SUCCESS);
LoggerTO loggerTOConnUpd = new LoggerTO();
loggerTOConnUpd.setKey(auditLoggerConnUpd.toLoggerName());
loggerTOConnUpd.setLevel(LoggerLevel.DEBUG);
loggerService.update(LoggerType.AUDIT, loggerTOConnUpd);
// 3. check that resource update is transformed and logged onto an audit file.
ResourceTO resource = resourceService.read(RESOURCE_NAME_CSV);
assertNotNull(resource);
resource.setPropagationPriority(100);
resourceService.update(resource);
ConnInstanceTO connector = connectorService.readByResource(RESOURCE_NAME_CSV, null);
assertNotNull(connector);
connector.setPoolConf(new ConnPoolConfTO());
connectorService.update(connector);
File auditTempFile = new File(auditFilePath);
// check audit_for_Master_file.log, it should contain only a static message
String auditLog = FileUtils.readFileToString(auditTempFile, Charset.defaultCharset());
assertTrue(StringUtils.contains(auditLog, "DEBUG Master.syncope.audit.[LOGIC]:[ResourceLogic]:[]:[update]:[SUCCESS]" + " - This is a static test message"));
File auditNoRewriteTempFile = new File(auditNoRewriteFilePath);
// check audit_for_Master_file.log, it should contain only a static message
String auditLogNoRewrite = FileUtils.readFileToString(auditNoRewriteTempFile, Charset.defaultCharset());
assertFalse(StringUtils.contains(auditLogNoRewrite, "DEBUG Master.syncope.audit.[LOGIC]:[ResourceLogic]:[]:[update]:[SUCCESS]" + " - This is a static test message"));
// clean audit_for_Master_file.log
FileUtils.writeStringToFile(auditTempFile, StringUtils.EMPTY, Charset.defaultCharset());
loggerService.delete(LoggerType.AUDIT, "syncope.audit.[LOGIC]:[ResourceLogic]:[]:[update]:[SUCCESS]");
resource = resourceService.read(RESOURCE_NAME_CSV);
assertNotNull(resource);
resource.setPropagationPriority(200);
resourceService.update(resource);
// check that nothing has been written to audit_for_Master_file.log
assertTrue(StringUtils.isEmpty(FileUtils.readFileToString(auditTempFile, Charset.defaultCharset())));
} catch (IOException e) {
fail("Unable to read/write log files" + e.getMessage());
}
}
use of org.apache.syncope.common.lib.to.ConnInstanceTO in project syncope by apache.
the class ConnectorITCase method checkSelectedLanguage.
@Test
public void checkSelectedLanguage() {
// 1. Check Italian
List<ConnInstanceTO> connectorInstanceTOs = connectorService.list("it");
for (ConnInstanceTO instance : connectorInstanceTOs) {
if ("net.tirasa.connid.bundles.db.table".equals(instance.getBundleName())) {
assertEquals("Utente", instance.getConf("user").get().getSchema().getDisplayName());
}
}
// 2. Check English (default)
connectorInstanceTOs = connectorService.list(null);
for (ConnInstanceTO instance : connectorInstanceTOs) {
if ("net.tirasa.connid.bundles.db.table".equals(instance.getBundleName())) {
assertEquals("User", instance.getConf("user").get().getSchema().getDisplayName());
}
}
}
use of org.apache.syncope.common.lib.to.ConnInstanceTO in project syncope by apache.
the class ConnectorITCase method issueSYNCOPE112.
@Test
public void issueSYNCOPE112() {
// ----------------------------------------
// Create a new connector
// ----------------------------------------
ConnInstanceTO connectorTO = new ConnInstanceTO();
connectorTO.setAdminRealm(SyncopeConstants.ROOT_REALM);
connectorTO.setLocation(connectorService.read("88a7a819-dab5-46b4-9b90-0b9769eabdb8", Locale.ENGLISH.getLanguage()).getLocation());
// set connector version
connectorTO.setVersion(connIdSoapVersion);
// set connector name
connectorTO.setConnectorName("net.tirasa.connid.bundles.soap.WebServiceConnector");
// set bundle name
connectorTO.setBundleName("net.tirasa.connid.bundles.soap");
// set display name
connectorTO.setDisplayName("WSSoap");
// set the connector configuration using PropertyTO
Set<ConnConfProperty> conf = new HashSet<>();
ConnConfPropSchema userSchema = new ConnConfPropSchema();
userSchema.setName("endpoint");
userSchema.setType(String.class.getName());
userSchema.setRequired(true);
ConnConfProperty endpoint = new ConnConfProperty();
endpoint.setSchema(userSchema);
endpoint.getValues().add("http://localhost:9080/does_not_work");
endpoint.setOverridable(true);
ConnConfPropSchema keyColumnSchema = new ConnConfPropSchema();
keyColumnSchema.setName("servicename");
keyColumnSchema.setType(String.class.getName());
keyColumnSchema.setRequired(true);
ConnConfProperty servicename = new ConnConfProperty();
servicename.setSchema(keyColumnSchema);
servicename.getValues().add("net.tirasa.connid.bundles.soap.provisioning.interfaces.Provisioning");
servicename.setOverridable(false);
conf.add(endpoint);
conf.add(servicename);
// set connector configuration
connectorTO.getConf().addAll(conf);
try {
try {
connectorService.check(connectorTO);
fail("This should not happen");
} catch (Exception e) {
assertNotNull(e);
}
Response response = connectorService.create(connectorTO);
if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
throw (RuntimeException) clientFactory.getExceptionMapper().fromResponse(response);
}
connectorTO = getObject(response.getLocation(), ConnectorService.class, ConnInstanceTO.class);
assertNotNull(connectorTO);
// ----------------------------------------
// ----------------------------------------
// create a resourceTO
// ----------------------------------------
String resourceName = "checkForPropOverriding";
ResourceTO resourceTO = new ResourceTO();
resourceTO.setKey(resourceName);
resourceTO.setConnector(connectorTO.getKey());
conf = new HashSet<>();
endpoint.getValues().clear();
endpoint.getValues().add("http://localhost:9080/syncope-fit-build-tools/cxf/soap/provisioning");
conf.add(endpoint);
resourceTO.getConfOverride().addAll(conf);
ProvisionTO provisionTO = new ProvisionTO();
provisionTO.setAnyType(AnyTypeKind.USER.name());
provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
resourceTO.getProvisions().add(provisionTO);
MappingTO mapping = new MappingTO();
provisionTO.setMapping(mapping);
ItemTO mapItem = new ItemTO();
mapItem.setExtAttrName("uid");
mapItem.setIntAttrName("userId");
mapItem.setConnObjectKey(true);
mapping.setConnObjectKeyItem(mapItem);
// ----------------------------------------
try {
resourceService.check(resourceTO);
} catch (Exception e) {
fail(ExceptionUtils.getStackTrace(e));
}
// ----------------------------------------
} finally {
// Remove connector from db to make test re-runnable
connectorService.delete(connectorTO.getKey());
}
}
use of org.apache.syncope.common.lib.to.ConnInstanceTO in project syncope by apache.
the class ConnectorITCase method validate.
@Test
public void validate() {
ConnInstanceTO connectorTO = new ConnInstanceTO();
connectorTO.setAdminRealm(SyncopeConstants.ROOT_REALM);
connectorTO.setLocation(connectorServerLocation);
connectorTO.setVersion(connIdDbVersion);
connectorTO.setConnectorName("net.tirasa.connid.bundles.db.table.DatabaseTableConnector");
connectorTO.setBundleName("net.tirasa.connid.bundles.db.table");
connectorTO.setDisplayName("H2Test");
// set the connector configuration using PropertyTO
Set<ConnConfProperty> conf = new HashSet<>();
ConnConfPropSchema jdbcDriverSchema = new ConnConfPropSchema();
jdbcDriverSchema.setName("jdbcDriver");
jdbcDriverSchema.setType(String.class.getName());
jdbcDriverSchema.setRequired(true);
ConnConfProperty jdbcDriver = new ConnConfProperty();
jdbcDriver.setSchema(jdbcDriverSchema);
jdbcDriver.getValues().add("org.h2.Driver");
conf.add(jdbcDriver);
ConnConfPropSchema jdbcUrlTemplateSchema = new ConnConfPropSchema();
jdbcUrlTemplateSchema.setName("jdbcUrlTemplate");
jdbcUrlTemplateSchema.setType(String.class.getName());
jdbcUrlTemplateSchema.setRequired(true);
ConnConfProperty jdbcUrlTemplate = new ConnConfProperty();
jdbcUrlTemplate.setSchema(jdbcUrlTemplateSchema);
jdbcUrlTemplate.getValues().add(testJDBCURL);
conf.add(jdbcUrlTemplate);
ConnConfPropSchema userSchema = new ConnConfPropSchema();
userSchema.setName("user");
userSchema.setType(String.class.getName());
userSchema.setRequired(false);
ConnConfProperty user = new ConnConfProperty();
user.setSchema(userSchema);
user.getValues().add("sa");
conf.add(user);
ConnConfPropSchema passwordSchema = new ConnConfPropSchema();
passwordSchema.setName("password");
passwordSchema.setType(GuardedString.class.getName());
passwordSchema.setRequired(true);
ConnConfProperty password = new ConnConfProperty();
password.setSchema(passwordSchema);
password.getValues().add("sa");
conf.add(password);
ConnConfPropSchema tableSchema = new ConnConfPropSchema();
tableSchema.setName("table");
tableSchema.setType(String.class.getName());
tableSchema.setRequired(true);
ConnConfProperty table = new ConnConfProperty();
table.setSchema(tableSchema);
table.getValues().add("test");
conf.add(table);
ConnConfPropSchema keyColumnSchema = new ConnConfPropSchema();
keyColumnSchema.setName("keyColumn");
keyColumnSchema.setType(String.class.getName());
keyColumnSchema.setRequired(true);
ConnConfProperty keyColumn = new ConnConfProperty();
keyColumn.setSchema(keyColumnSchema);
keyColumn.getValues().add("id");
conf.add(keyColumn);
ConnConfPropSchema passwordColumnSchema = new ConnConfPropSchema();
passwordColumnSchema.setName("passwordColumn");
passwordColumnSchema.setType(String.class.getName());
passwordColumnSchema.setRequired(true);
ConnConfProperty passwordColumn = new ConnConfProperty();
passwordColumn.setSchema(passwordColumnSchema);
passwordColumn.getValues().add("password");
conf.add(passwordColumn);
// set connector configuration
connectorTO.getConf().addAll(conf);
try {
connectorService.check(connectorTO);
} catch (Exception e) {
fail(ExceptionUtils.getStackTrace(e));
}
conf.remove(password);
password.getValues().clear();
password.getValues().add("password");
conf.add(password);
try {
connectorService.check(connectorTO);
fail("This should not happen");
} catch (Exception e) {
assertNotNull(e);
}
}
use of org.apache.syncope.common.lib.to.ConnInstanceTO in project syncope by apache.
the class ConnectorITCase method checkHiddenProperty.
@Test
public void checkHiddenProperty() {
ConnInstanceTO connInstanceTO = connectorService.read("88a7a819-dab5-46b4-9b90-0b9769eabdb8", Locale.ENGLISH.getLanguage());
boolean check = false;
for (ConnConfProperty prop : connInstanceTO.getConf()) {
if ("receiveTimeout".equals(prop.getSchema().getName())) {
check = true;
}
}
assertTrue(check);
}
Aggregations