use of org.apache.syncope.common.lib.to.ConnInstanceTO in project syncope by apache.
the class VirSchemaDetails method getExtAttrNames.
private List<String> getExtAttrNames() {
ConnInstanceTO connInstanceTO = new ConnInstanceTO();
connInstanceTO.setKey(selectedResource.getConnector());
connInstanceTO.getConf().addAll(selectedResource.getConfOverride());
Optional<ConnIdObjectClassTO> connIdObjectClass = connRestClient.buildObjectClassInfo(connInstanceTO, false).stream().filter(object -> object.getType().equals(anyTypes.get(anyType.getModelObject()))).findAny();
return connIdObjectClass.isPresent() ? connIdObjectClass.get().getAttributes() : Collections.<String>emptyList();
}
use of org.apache.syncope.common.lib.to.ConnInstanceTO in project syncope by apache.
the class ConnInstanceHistoryConfTest method createDelete.
@Test
public void createDelete() {
ConnInstance ldapConnector = connInstanceDAO.find("74141a3b-0762-4720-a4aa-fc3e374ef3ef");
assertNotNull(ldapConnector);
ConnInstanceHistoryConf ldapHistory = entityFactory.newEntity(ConnInstanceHistoryConf.class);
ldapHistory.setCreation(new Date());
ldapHistory.setCreator("me");
ldapHistory.setEntity(ldapConnector);
ldapHistory.setConf(new ConnInstanceTO());
ldapHistory = connInstanceHistoryConfDAO.save(ldapHistory);
assertNotNull(ldapHistory.getKey());
connInstanceHistoryConfDAO.flush();
List<ConnInstanceHistoryConf> history = connInstanceHistoryConfDAO.findByEntity(ldapConnector);
assertEquals(1, history.size());
assertEquals(ldapHistory, history.get(0));
connInstanceHistoryConfDAO.delete(ldapHistory.getKey());
connInstanceHistoryConfDAO.flush();
assertNull(connInstanceHistoryConfDAO.find(ldapHistory.getKey()));
assertTrue(connInstanceHistoryConfDAO.findByEntity(ldapConnector).isEmpty());
}
use of org.apache.syncope.common.lib.to.ConnInstanceTO in project syncope by apache.
the class MultitenancyITCase method createResourceAndPull.
@Test
public void createResourceAndPull() {
// read connector
ConnInstanceTO conn = adminClient.getService(ConnectorService.class).read("b7ea96c3-c633-488b-98a0-b52ac35850f7", Locale.ENGLISH.getLanguage());
assertNotNull(conn);
assertEquals("LDAP", conn.getDisplayName());
// prepare resource
ResourceTO resource = new ResourceTO();
resource.setKey("new-ldap-resource");
resource.setConnector(conn.getKey());
try {
ProvisionTO provisionTO = new ProvisionTO();
provisionTO.setAnyType(AnyTypeKind.USER.name());
provisionTO.setObjectClass(ObjectClass.ACCOUNT_NAME);
resource.getProvisions().add(provisionTO);
MappingTO mapping = new MappingTO();
mapping.setConnObjectLink("'uid=' + username + ',ou=people,o=isp'");
provisionTO.setMapping(mapping);
ItemTO item = new ItemTO();
item.setIntAttrName("username");
item.setExtAttrName("cn");
item.setPurpose(MappingPurpose.BOTH);
mapping.setConnObjectKeyItem(item);
item = new ItemTO();
item.setPassword(true);
item.setIntAttrName("password");
item.setExtAttrName("userPassword");
item.setPurpose(MappingPurpose.BOTH);
item.setMandatoryCondition("true");
mapping.add(item);
item = new ItemTO();
item.setIntAttrName("key");
item.setPurpose(MappingPurpose.BOTH);
item.setExtAttrName("sn");
item.setMandatoryCondition("true");
mapping.add(item);
item = new ItemTO();
item.setIntAttrName("email");
item.setPurpose(MappingPurpose.BOTH);
item.setExtAttrName("mail");
mapping.add(item);
// create resource
Response response = adminClient.getService(ResourceService.class).create(resource);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
resource = adminClient.getService(ResourceService.class).read(resource.getKey());
assertNotNull(resource);
// create pull task
PullTaskTO task = new PullTaskTO();
task.setName("LDAP Pull Task");
task.setActive(true);
task.setDestinationRealm(SyncopeConstants.ROOT_REALM);
task.setResource(resource.getKey());
task.setPullMode(PullMode.FULL_RECONCILIATION);
task.setPerformCreate(true);
response = adminClient.getService(TaskService.class).create(TaskType.PULL, task);
assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
task = adminClient.getService(TaskService.class).read(TaskType.PULL, StringUtils.substringAfterLast(response.getLocation().toASCIIString(), "/"), true);
assertNotNull(resource);
// pull
ExecTO execution = AbstractTaskITCase.execProvisioningTask(adminClient.getService(TaskService.class), TaskType.PULL, task.getKey(), 50, false);
// verify execution status
String status = execution.getStatus();
assertNotNull(status);
assertEquals(PropagationTaskExecStatus.SUCCESS, PropagationTaskExecStatus.valueOf(status));
// verify that pulled user is found
PagedResult<UserTO> matchingUsers = adminClient.getService(UserService.class).search(new AnyQuery.Builder().realm(SyncopeConstants.ROOT_REALM).fiql(SyncopeClient.getUserSearchConditionBuilder().is("username").equalTo("pullFromLDAP").query()).build());
assertNotNull(matchingUsers);
assertEquals(1, matchingUsers.getResult().size());
} finally {
adminClient.getService(ResourceService.class).delete(resource.getKey());
}
}
use of org.apache.syncope.common.lib.to.ConnInstanceTO in project syncope by apache.
the class RESTITCase method unauthorizedOrForbidden.
@Test
public void unauthorizedOrForbidden() {
// service as admin: it works
List<ConnInstanceTO> connectors = connectorService.list(null);
assertNotNull(connectors);
assertFalse(connectors.isEmpty());
// service with bad password: 401 unauthorized
try {
clientFactory.create("bellini", "passwor");
fail("This should not happen");
} catch (AccessControlException e) {
assertNotNull(e);
}
// service with invalid JWT string: 401 unauthorized
try {
clientFactory.create(RandomStringUtils.random(20, true, true)).self();
fail("This should not happen");
} catch (AccessControlException e) {
assertNotNull(e);
}
// service with good password, but no entitlements owned: 403 forbidden
SyncopeClient goodClient = clientFactory.create("bellini", "password");
try {
goodClient.getService(ConnectorService.class).list(null);
fail("This should not happen");
} catch (ForbiddenException e) {
assertNotNull(e);
}
}
use of org.apache.syncope.common.lib.to.ConnInstanceTO in project syncope by apache.
the class ConnInstanceDataBinderImpl method update.
@Override
public ConnInstance update(final ConnInstanceTO connInstanceTO) {
ConnInstance connInstance = connInstanceDAO.authFind(connInstanceTO.getKey());
if (connInstance == null) {
throw new NotFoundException("Connector '" + connInstanceTO.getKey() + "'");
}
ConnInstanceTO current = getConnInstanceTO(connInstance);
if (!current.equals(connInstanceTO)) {
// 1. save the current configuration, before update
ConnInstanceHistoryConf connInstanceHistoryConf = entityFactory.newEntity(ConnInstanceHistoryConf.class);
connInstanceHistoryConf.setCreator(AuthContextUtils.getUsername());
connInstanceHistoryConf.setCreation(new Date());
connInstanceHistoryConf.setEntity(connInstance);
connInstanceHistoryConf.setConf(current);
connInstanceHistoryConfDAO.save(connInstanceHistoryConf);
// 2. ensure the maximum history size is not exceeded
List<ConnInstanceHistoryConf> history = connInstanceHistoryConfDAO.findByEntity(connInstance);
long maxHistorySize = confDAO.find("connector.conf.history.size", 10L);
if (maxHistorySize < history.size()) {
// always remove the last item since history was obtained by a query with ORDER BY creation DESC
for (int i = 0; i < history.size() - maxHistorySize; i++) {
connInstanceHistoryConfDAO.delete(history.get(history.size() - 1).getKey());
}
}
}
// 3. actual update
connInstance.getCapabilities().clear();
connInstance.getCapabilities().addAll(connInstanceTO.getCapabilities());
if (connInstanceTO.getAdminRealm() != null) {
Realm realm = realmDAO.findByFullPath(connInstanceTO.getAdminRealm());
if (realm == null) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRealm);
sce.getElements().add("Invalid or null realm specified: " + connInstanceTO.getAdminRealm());
throw sce;
}
connInstance.setAdminRealm(realm);
}
if (connInstanceTO.getLocation() != null) {
connInstance.setLocation(connInstanceTO.getLocation());
}
if (connInstanceTO.getBundleName() != null) {
connInstance.setBundleName(connInstanceTO.getBundleName());
}
if (connInstanceTO.getVersion() != null) {
connInstance.setVersion(connInstanceTO.getVersion());
}
if (connInstanceTO.getConnectorName() != null) {
connInstance.setConnectorName(connInstanceTO.getConnectorName());
}
if (connInstanceTO.getConf() != null && !connInstanceTO.getConf().isEmpty()) {
connInstance.setConf(connInstanceTO.getConf());
}
if (connInstanceTO.getDisplayName() != null) {
connInstance.setDisplayName(connInstanceTO.getDisplayName());
}
if (connInstanceTO.getConnRequestTimeout() != null) {
connInstance.setConnRequestTimeout(connInstanceTO.getConnRequestTimeout());
}
if (connInstanceTO.getPoolConf() == null) {
connInstance.setPoolConf(null);
} else {
connInstance.setPoolConf(ConnPoolConfUtils.getConnPoolConf(connInstanceTO.getPoolConf(), entityFactory.newConnPoolConf()));
}
try {
connInstance = connInstanceDAO.save(connInstance);
} catch (Exception e) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidConnInstance);
sce.getElements().add(e.getMessage());
throw sce;
}
return connInstance;
}
Aggregations