You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2016/01/26 13:04:43 UTC
[12/21] syncope git commit: [SYNCOPE-152] Moving console IT under
fit/core-reference in order to speed-up the total build time
http://git-wip-us.apache.org/repos/asf/syncope/blob/17d5d892/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AbstractITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AbstractITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AbstractITCase.java
deleted file mode 100644
index 9aaf034..0000000
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AbstractITCase.java
+++ /dev/null
@@ -1,454 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.fit.core.reference;
-
-import static org.junit.Assert.assertNotNull;
-
-import java.io.InputStream;
-import java.net.URI;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Properties;
-import java.util.UUID;
-import javax.naming.Context;
-import javax.naming.NamingException;
-import javax.naming.directory.InitialDirContext;
-import javax.sql.DataSource;
-import javax.ws.rs.core.GenericType;
-import javax.ws.rs.core.Response;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.cxf.jaxrs.client.WebClient;
-import org.apache.syncope.client.lib.SyncopeClient;
-import org.apache.syncope.client.lib.SyncopeClientFactoryBean;
-import org.apache.syncope.common.lib.patch.AnyObjectPatch;
-import org.apache.syncope.common.lib.patch.AttrPatch;
-import org.apache.syncope.common.lib.patch.GroupPatch;
-import org.apache.syncope.common.lib.patch.UserPatch;
-import org.apache.syncope.common.lib.policy.AbstractPolicyTO;
-import org.apache.syncope.common.lib.to.AbstractSchemaTO;
-import org.apache.syncope.common.lib.to.AnyObjectTO;
-import org.apache.syncope.common.lib.to.AttrTO;
-import org.apache.syncope.common.lib.to.ResourceTO;
-import org.apache.syncope.common.lib.to.GroupTO;
-import org.apache.syncope.common.lib.to.ProvisioningResult;
-import org.apache.syncope.common.lib.to.RoleTO;
-import org.apache.syncope.common.lib.to.UserTO;
-import org.apache.syncope.common.lib.types.ConnConfProperty;
-import org.apache.syncope.common.lib.types.PatchOperation;
-import org.apache.syncope.common.lib.types.SchemaType;
-import org.apache.syncope.common.rest.api.RESTHeaders;
-import org.apache.syncope.common.rest.api.service.AnyObjectService;
-import org.apache.syncope.common.rest.api.service.AnyTypeClassService;
-import org.apache.syncope.common.rest.api.service.AnyTypeService;
-import org.apache.syncope.common.rest.api.service.CamelRouteService;
-import org.apache.syncope.common.rest.api.service.ConfigurationService;
-import org.apache.syncope.common.rest.api.service.ConnectorService;
-import org.apache.syncope.common.rest.api.service.DomainService;
-import org.apache.syncope.common.rest.api.service.LoggerService;
-import org.apache.syncope.common.rest.api.service.NotificationService;
-import org.apache.syncope.common.rest.api.service.PolicyService;
-import org.apache.syncope.common.rest.api.service.ReportService;
-import org.apache.syncope.common.rest.api.service.ResourceService;
-import org.apache.syncope.common.rest.api.service.GroupService;
-import org.apache.syncope.common.rest.api.service.RealmService;
-import org.apache.syncope.common.rest.api.service.RelationshipTypeService;
-import org.apache.syncope.common.rest.api.service.RoleService;
-import org.apache.syncope.common.rest.api.service.SchemaService;
-import org.apache.syncope.common.rest.api.service.SecurityQuestionService;
-import org.apache.syncope.common.rest.api.service.SyncopeService;
-import org.apache.syncope.common.rest.api.service.TaskService;
-import org.apache.syncope.common.rest.api.service.UserSelfService;
-import org.apache.syncope.common.rest.api.service.UserService;
-import org.apache.syncope.common.rest.api.service.UserWorkflowService;
-import org.apache.syncope.common.rest.api.service.WorkflowService;
-import org.identityconnectors.common.security.Encryptor;
-import org.junit.BeforeClass;
-import org.junit.runner.RunWith;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(locations = { "classpath:testJDBCContext.xml" })
-public abstract class AbstractITCase {
-
- protected static final Logger LOG = LoggerFactory.getLogger(AbstractITCase.class);
-
- protected static final String ADMIN_UNAME = "admin";
-
- protected static final String ADMIN_PWD = "password";
-
- protected static final String ADDRESS = "http://localhost:9080/syncope/rest";
-
- protected static final String ENV_KEY_CONTENT_TYPE = "jaxrsContentType";
-
- protected static final String RESOURCE_NAME_WS1 = "ws-target-resource-1";
-
- protected static final String RESOURCE_NAME_WS2 = "ws-target-resource-2";
-
- protected static final String RESOURCE_NAME_LDAP = "resource-ldap";
-
- protected static final String RESOURCE_NAME_TESTDB = "resource-testdb";
-
- protected static final String RESOURCE_NAME_TESTDB2 = "resource-testdb2";
-
- protected static final String RESOURCE_NAME_CSV = "resource-csv";
-
- protected static final String RESOURCE_NAME_DBSYNC = "resource-db-sync";
-
- protected static final String RESOURCE_NAME_DBVIRATTR = "resource-db-virattr";
-
- protected static final String RESOURCE_NAME_NOPROPAGATION = "ws-target-resource-nopropagation";
-
- protected static final String RESOURCE_NAME_NOPROPAGATION2 = "ws-target-resource-nopropagation2";
-
- protected static final String RESOURCE_NAME_NOPROPAGATION3 = "ws-target-resource-nopropagation3";
-
- protected static final String RESOURCE_NAME_NOPROPAGATION4 = "ws-target-resource-nopropagation4";
-
- protected static final String RESOURCE_NAME_RESETSYNCTOKEN = "ws-target-resource-update-resetsynctoken";
-
- protected static final String RESOURCE_NAME_TIMEOUT = "ws-target-resource-timeout";
-
- protected static final String RESOURCE_NAME_MAPPINGS1 = "ws-target-resource-list-mappings-1";
-
- protected static final String RESOURCE_NAME_MAPPINGS2 = "ws-target-resource-list-mappings-2";
-
- protected static final String RESOURCE_NAME_CREATE = "ws-target-resource-create";
-
- protected static final String RESOURCE_NAME_CREATE_SINGLE = "ws-target-resource-create-single";
-
- protected static final String RESOURCE_NAME_CREATE_WRONG = "ws-target-resource-create-wrong";
-
- protected static final String RESOURCE_NAME_DELETE = "ws-target-resource-delete";
-
- protected static final String RESOURCE_NAME_UPDATE = "ws-target-resource-update";
-
- protected static final String RESOURCE_NAME_CREATE_NONE = "ws-target-resource-create-none";
-
- protected static final String RESOURCE_NAME_DBSCRIPTED = "resource-db-scripted";
-
- protected static String ANONYMOUS_UNAME;
-
- protected static String ANONYMOUS_KEY;
-
- protected static SyncopeClientFactoryBean clientFactory;
-
- protected static SyncopeClient adminClient;
-
- protected static SyncopeService syncopeService;
-
- protected static DomainService domainService;
-
- protected static AnyTypeClassService anyTypeClassService;
-
- protected static AnyTypeService anyTypeService;
-
- protected static RelationshipTypeService relationshipTypeService;
-
- protected static RealmService realmService;
-
- protected static AnyObjectService anyObjectService;
-
- protected static RoleService roleService;
-
- protected static UserService userService;
-
- protected static UserSelfService userSelfService;
-
- protected static UserWorkflowService userWorkflowService;
-
- protected static GroupService groupService;
-
- protected static ResourceService resourceService;
-
- protected static ConfigurationService configurationService;
-
- protected static ConnectorService connectorService;
-
- protected static LoggerService loggerService;
-
- protected static ReportService reportService;
-
- protected static TaskService taskService;
-
- protected static WorkflowService workflowService;
-
- protected static NotificationService notificationService;
-
- protected static SchemaService schemaService;
-
- protected static PolicyService policyService;
-
- protected static SecurityQuestionService securityQuestionService;
-
- protected static CamelRouteService camelRouteService;
-
- @Autowired
- protected DataSource testDataSource;
-
- @BeforeClass
- public static void securitySetup() {
- InputStream propStream = null;
- try {
- propStream = Encryptor.class.getResourceAsStream("/security.properties");
- Properties props = new Properties();
- props.load(propStream);
-
- ANONYMOUS_UNAME = props.getProperty("anonymousUser");
- ANONYMOUS_KEY = props.getProperty("anonymousKey");
- } catch (Exception e) {
- LOG.error("Could not read secretKey", e);
- } finally {
- IOUtils.closeQuietly(propStream);
- }
-
- assertNotNull(ANONYMOUS_UNAME);
- assertNotNull(ANONYMOUS_KEY);
- }
-
- @BeforeClass
- public static void restSetup() {
- clientFactory = new SyncopeClientFactoryBean().setAddress(ADDRESS);
-
- String envContentType = System.getProperty(ENV_KEY_CONTENT_TYPE);
- if (StringUtils.isNotBlank(envContentType)) {
- clientFactory.setContentType(envContentType);
- }
- LOG.info("Performing IT with content type {}", clientFactory.getContentType().getMediaType());
-
- adminClient = clientFactory.create(ADMIN_UNAME, ADMIN_PWD);
-
- syncopeService = adminClient.getService(SyncopeService.class);
- domainService = adminClient.getService(DomainService.class);
- anyTypeClassService = adminClient.getService(AnyTypeClassService.class);
- anyTypeService = adminClient.getService(AnyTypeService.class);
- relationshipTypeService = adminClient.getService(RelationshipTypeService.class);
- realmService = adminClient.getService(RealmService.class);
- anyObjectService = adminClient.getService(AnyObjectService.class);
- roleService = adminClient.getService(RoleService.class);
- userService = adminClient.getService(UserService.class);
- userSelfService = adminClient.getService(UserSelfService.class);
- userWorkflowService = adminClient.getService(UserWorkflowService.class);
- groupService = adminClient.getService(GroupService.class);
- resourceService = adminClient.getService(ResourceService.class);
- configurationService = adminClient.getService(ConfigurationService.class);
- connectorService = adminClient.getService(ConnectorService.class);
- loggerService = adminClient.getService(LoggerService.class);
- reportService = adminClient.getService(ReportService.class);
- taskService = adminClient.getService(TaskService.class);
- policyService = adminClient.getService(PolicyService.class);
- workflowService = adminClient.getService(WorkflowService.class);
- notificationService = adminClient.getService(NotificationService.class);
- schemaService = adminClient.getService(SchemaService.class);
- securityQuestionService = adminClient.getService(SecurityQuestionService.class);
- camelRouteService = adminClient.getService(CamelRouteService.class);
- }
-
- protected static String getUUIDString() {
- return UUID.randomUUID().toString().substring(0, 8);
- }
-
- protected static AttrTO attrTO(final String schema, final String value) {
- return new AttrTO.Builder().schema(schema).value(value).build();
- }
-
- protected static AttrPatch attrAddReplacePatch(final String schema, final String value) {
- return new AttrPatch.Builder().operation(PatchOperation.ADD_REPLACE).attrTO(attrTO(schema, value)).build();
- }
-
- public <T> T getObject(final URI location, final Class<?> serviceClass, final Class<T> resultClass) {
- WebClient webClient = WebClient.fromClient(WebClient.client(adminClient.getService(serviceClass)));
- webClient.accept(clientFactory.getContentType().getMediaType()).to(location.toASCIIString(), false);
-
- return webClient.get(resultClass);
- }
-
- @SuppressWarnings("unchecked")
- protected <T extends AbstractSchemaTO> T createSchema(final SchemaType type, final T schemaTO) {
- Response response = schemaService.create(type, schemaTO);
- if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
- Exception ex = clientFactory.getExceptionMapper().fromResponse(response);
- if (ex != null) {
- throw (RuntimeException) ex;
- }
- }
-
- return (T) getObject(response.getLocation(), SchemaService.class, schemaTO.getClass());
- }
-
- protected RoleTO createRole(final RoleTO roleTO) {
- Response response = roleService.create(roleTO);
- if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
- Exception ex = clientFactory.getExceptionMapper().fromResponse(response);
- if (ex != null) {
- throw (RuntimeException) ex;
- }
- }
- return getObject(response.getLocation(), RoleService.class, RoleTO.class);
- }
-
- protected UserTO readUser(final String username) {
- return userService.read(Long.valueOf(userService.getUserKey(username).getHeaderString(RESTHeaders.USER_KEY)));
- }
-
- protected ProvisioningResult<UserTO> createUser(final UserTO userTO) {
- return createUser(userTO, true);
- }
-
- protected ProvisioningResult<UserTO> createUser(final UserTO userTO, final boolean storePassword) {
- Response response = userService.create(userTO, storePassword);
- if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
- Exception ex = clientFactory.getExceptionMapper().fromResponse(response);
- if (ex != null) {
- throw (RuntimeException) ex;
- }
- }
- return response.readEntity(new GenericType<ProvisioningResult<UserTO>>() {
- });
- }
-
- protected ProvisioningResult<UserTO> updateUser(final UserPatch userPatch) {
- return userService.update(userPatch).
- readEntity(new GenericType<ProvisioningResult<UserTO>>() {
- });
- }
-
- protected ProvisioningResult<UserTO> deleteUser(final Long key) {
- return userService.delete(key).
- readEntity(new GenericType<ProvisioningResult<UserTO>>() {
- });
- }
-
- protected ProvisioningResult<AnyObjectTO> createAnyObject(final AnyObjectTO anyObjectTO) {
- Response response = anyObjectService.create(anyObjectTO);
- if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
- Exception ex = clientFactory.getExceptionMapper().fromResponse(response);
- if (ex != null) {
- throw (RuntimeException) ex;
- }
- }
- return response.readEntity(new GenericType<ProvisioningResult<AnyObjectTO>>() {
- });
- }
-
- protected ProvisioningResult<AnyObjectTO> updateAnyObject(final AnyObjectPatch anyObjectPatch) {
- return anyObjectService.update(anyObjectPatch).
- readEntity(new GenericType<ProvisioningResult<AnyObjectTO>>() {
- });
- }
-
- protected ProvisioningResult<AnyObjectTO> deleteAnyObject(final Long key) {
- return anyObjectService.delete(key).
- readEntity(new GenericType<ProvisioningResult<AnyObjectTO>>() {
- });
- }
-
- protected ProvisioningResult<GroupTO> createGroup(final GroupTO groupTO) {
- Response response = groupService.create(groupTO);
- if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
- Exception ex = clientFactory.getExceptionMapper().fromResponse(response);
- if (ex != null) {
- throw (RuntimeException) ex;
- }
- }
- return response.readEntity(new GenericType<ProvisioningResult<GroupTO>>() {
- });
- }
-
- protected ProvisioningResult<GroupTO> updateGroup(final GroupPatch groupPatch) {
- return groupService.update(groupPatch).
- readEntity(new GenericType<ProvisioningResult<GroupTO>>() {
- });
- }
-
- protected ProvisioningResult<GroupTO> deleteGroup(final Long key) {
- return groupService.delete(key).
- readEntity(new GenericType<ProvisioningResult<GroupTO>>() {
- });
- }
-
- @SuppressWarnings("unchecked")
- protected <T extends AbstractPolicyTO> T createPolicy(final T policy) {
- Response response = policyService.create(policy);
- if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
- Exception ex = clientFactory.getExceptionMapper().fromResponse(response);
- if (ex != null) {
- throw (RuntimeException) ex;
- }
- }
- return (T) getObject(response.getLocation(), PolicyService.class, policy.getClass());
- }
-
- protected ResourceTO createResource(final ResourceTO resourceTO) {
- Response response = resourceService.create(resourceTO);
- if (response.getStatusInfo().getStatusCode() != Response.Status.CREATED.getStatusCode()) {
- Exception ex = clientFactory.getExceptionMapper().fromResponse(response);
- if (ex != null) {
- throw (RuntimeException) ex;
- }
- }
- return getObject(response.getLocation(), ResourceService.class, ResourceTO.class);
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes", "UseOfObsoleteCollectionType" })
- protected InitialDirContext getLdapResourceDirContext(final String bindDn, final String bindPwd)
- throws NamingException {
- ResourceTO ldapRes = resourceService.read(RESOURCE_NAME_LDAP);
- final Map<String, ConnConfProperty> ldapConnConf =
- connectorService.read(ldapRes.getConnector(), Locale.ENGLISH.getLanguage()).getConfMap();
-
- Properties env = new Properties();
- env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
- env.put(Context.PROVIDER_URL, "ldap://" + ldapConnConf.get("host").getValues().get(0)
- + ":" + ldapConnConf.get("port").getValues().get(0) + "/");
- env.put(Context.SECURITY_AUTHENTICATION, "simple");
- env.put(Context.SECURITY_PRINCIPAL,
- bindDn == null ? ldapConnConf.get("principal").getValues().get(0) : bindDn);
- env.put(Context.SECURITY_CREDENTIALS,
- bindPwd == null ? ldapConnConf.get("credentials").getValues().get(0) : bindPwd);
-
- return new InitialDirContext(env);
- }
-
- protected Object getLdapRemoteObject(final String bindDn, final String bindPwd, final String objectDn) {
- InitialDirContext ctx = null;
- try {
- ctx = getLdapResourceDirContext(bindDn, bindPwd);
- return ctx.lookup(objectDn);
- } catch (Exception e) {
- return null;
- } finally {
- if (ctx != null) {
- try {
- ctx.close();
- } catch (NamingException e) {
- // ignore
- }
- }
- }
- }
-
- protected Object getLdapRemoteObject(final String objectDn) {
- return getLdapRemoteObject(null, null, objectDn);
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/17d5d892/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AbstractTaskITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AbstractTaskITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AbstractTaskITCase.java
deleted file mode 100644
index 8a20ea9..0000000
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AbstractTaskITCase.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.fit.core.reference;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import org.apache.commons.collections4.IterableUtils;
-import org.apache.commons.collections4.Predicate;
-import org.apache.syncope.common.lib.to.AbstractTaskTO;
-import org.apache.syncope.common.lib.to.NotificationTaskTO;
-import org.apache.syncope.common.lib.to.PagedResult;
-import org.apache.syncope.common.lib.to.TaskExecTO;
-import org.apache.syncope.common.lib.to.UserTO;
-import org.apache.syncope.common.lib.types.TaskType;
-import org.apache.syncope.common.rest.api.beans.ExecuteQuery;
-import org.apache.syncope.common.rest.api.beans.TaskQuery;
-import org.apache.syncope.common.rest.api.service.TaskService;
-import org.apache.syncope.core.logic.notification.NotificationJob;
-
-public abstract class AbstractTaskITCase extends AbstractITCase {
-
- protected static final Long SYNC_TASK_ID = 4L;
-
- protected static final Long SCHED_TASK_ID = 5L;
-
- protected static class ThreadExec implements Callable<TaskExecTO> {
-
- private final TaskService taskService;
-
- private final Long taskKey;
-
- private final int maxWaitSeconds;
-
- private final boolean dryRun;
-
- public ThreadExec(
- final TaskService taskService, final Long taskKey, final int maxWaitSeconds, final boolean dryRun) {
-
- this.taskService = taskService;
- this.taskKey = taskKey;
- this.maxWaitSeconds = maxWaitSeconds;
- this.dryRun = dryRun;
- }
-
- @Override
- public TaskExecTO call() throws Exception {
- return execProvisioningTask(taskService, taskKey, maxWaitSeconds, dryRun);
- }
- }
-
- /**
- * Remove initial and synchronized users to make test re-runnable.
- */
- protected void removeTestUsers() {
- for (int i = 0; i < 10; i++) {
- String cUserName = "test" + i;
- try {
- UserTO cUserTO = readUser(cUserName);
- userService.delete(cUserTO.getKey());
- } catch (Exception e) {
- // Ignore
- }
- }
- }
-
- protected static TaskExecTO execTask(final TaskService taskService, final Long taskKey, final String initialStatus,
- final int maxWaitSeconds, final boolean dryRun) {
-
- AbstractTaskTO taskTO = taskService.read(taskKey, true);
- assertNotNull(taskTO);
- assertNotNull(taskTO.getExecutions());
-
- int preSyncSize = taskTO.getExecutions().size();
- TaskExecTO execution = taskService.execute(
- new ExecuteQuery.Builder().key(taskTO.getKey()).dryRun(dryRun).build());
- assertEquals(initialStatus, execution.getStatus());
-
- int i = 0;
- int maxit = maxWaitSeconds;
-
- // wait for completion (executions incremented)
- do {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- }
-
- taskTO = taskService.read(taskTO.getKey(), true);
-
- assertNotNull(taskTO);
- assertNotNull(taskTO.getExecutions());
-
- i++;
- } while (preSyncSize == taskTO.getExecutions().size() && i < maxit);
- if (i == maxit) {
- fail("Timeout when executing task " + taskKey);
- }
- return taskTO.getExecutions().get(taskTO.getExecutions().size() - 1);
- }
-
- public static TaskExecTO execProvisioningTask(
- final TaskService taskService, final Long taskKey, final int maxWaitSeconds, final boolean dryRun) {
-
- return execTask(taskService, taskKey, "JOB_FIRED", maxWaitSeconds, dryRun);
- }
-
- protected static TaskExecTO execNotificationTask(
- final TaskService taskService, final Long taskKey, final int maxWaitSeconds) {
-
- return execTask(taskService, taskKey, NotificationJob.Status.SENT.name(), maxWaitSeconds, false);
- }
-
- protected Map<Long, TaskExecTO> execProvisioningTasks(final TaskService taskService,
- final Set<Long> taskKeys, final int maxWaitSeconds, final boolean dryRun) throws Exception {
-
- ExecutorService service = Executors.newFixedThreadPool(taskKeys.size());
- List<Future<TaskExecTO>> futures = new ArrayList<>();
-
- for (Long key : taskKeys) {
- futures.add(service.submit(new ThreadExec(taskService, key, maxWaitSeconds, dryRun)));
- // avoid flooding the test server
- try {
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- }
- }
-
- Map<Long, TaskExecTO> res = new HashMap<>();
-
- for (Future<TaskExecTO> future : futures) {
- TaskExecTO taskExecTO = future.get(100, TimeUnit.SECONDS);
- res.put(taskExecTO.getTask(), taskExecTO);
- }
-
- service.shutdownNow();
-
- return res;
- }
-
- protected NotificationTaskTO findNotificationTaskBySender(final String sender) {
- PagedResult<NotificationTaskTO> tasks =
- taskService.list(new TaskQuery.Builder().type(TaskType.NOTIFICATION).build());
- assertNotNull(tasks);
- assertFalse(tasks.getResult().isEmpty());
-
- return IterableUtils.find(tasks.getResult(), new Predicate<NotificationTaskTO>() {
-
- @Override
- public boolean evaluate(final NotificationTaskTO task) {
- return sender.equals(task.getSender());
- }
- });
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/17d5d892/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/ActivitiDetector.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/ActivitiDetector.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/ActivitiDetector.java
deleted file mode 100644
index 6182e2a..0000000
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/ActivitiDetector.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.fit.core.reference;
-
-import org.apache.syncope.common.rest.api.service.SyncopeService;
-
-public class ActivitiDetector {
-
- public static boolean isActivitiEnabledForUsers(final SyncopeService syncopeService) {
- return syncopeService.info().getUserWorkflowAdapter().indexOf("Activiti") != -1;
- }
-
- public static boolean isActivitiEnabledForGroups(final SyncopeService syncopeService) {
- return syncopeService.info().getGroupWorkflowAdapter().indexOf("Activiti") != -1;
- }
-
- public static boolean isActivitiEnabledForAnyObjects(final SyncopeService syncopeService) {
- return syncopeService.info().getAnyObjectWorkflowAdapter().indexOf("Activiti") != -1;
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/17d5d892/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AnyObjectITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AnyObjectITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AnyObjectITCase.java
deleted file mode 100644
index 6cbcf39..0000000
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AnyObjectITCase.java
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.fit.core.reference;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.Set;
-import javax.ws.rs.core.Response;
-import org.apache.syncope.common.lib.SyncopeClientException;
-import org.apache.syncope.common.lib.SyncopeConstants;
-import org.apache.syncope.common.lib.patch.AnyObjectPatch;
-import org.apache.syncope.common.lib.to.ConnObjectTO;
-import org.apache.syncope.common.lib.to.AnyObjectTO;
-import org.apache.syncope.common.lib.to.AttrTO;
-import org.apache.syncope.common.lib.to.MembershipTO;
-import org.apache.syncope.common.lib.to.PagedResult;
-import org.apache.syncope.common.lib.to.RelationshipTO;
-import org.apache.syncope.common.lib.types.AnyTypeKind;
-import org.apache.syncope.common.lib.types.ClientExceptionType;
-import org.apache.syncope.common.lib.types.SchemaType;
-import org.apache.syncope.common.rest.api.beans.AnyListQuery;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-
-@FixMethodOrder(MethodSorters.JVM)
-public class AnyObjectITCase extends AbstractITCase {
-
- public static AnyObjectTO getSampleTO(final String location) {
- AnyObjectTO anyObjectTO = new AnyObjectTO();
- anyObjectTO.setRealm(SyncopeConstants.ROOT_REALM);
- anyObjectTO.setType("PRINTER");
- anyObjectTO.getPlainAttrs().add(attrTO("location", location + getUUIDString()));
-
- anyObjectTO.getResources().add(RESOURCE_NAME_DBSCRIPTED);
- return anyObjectTO;
- }
-
- @Test
- public void create() {
- AnyObjectTO anyObjectTO = getSampleTO("create");
-
- anyObjectTO = createAnyObject(anyObjectTO).getAny();
- assertNotNull(anyObjectTO);
-
- ConnObjectTO connObjectTO =
- resourceService.readConnObject(RESOURCE_NAME_DBSCRIPTED, anyObjectTO.getType(), anyObjectTO.getKey());
- assertNotNull(connObjectTO);
- assertNotNull(connObjectTO.getPlainAttrMap().get("location"));
- assertEquals(anyObjectTO.getPlainAttrMap().get("location"), connObjectTO.getPlainAttrMap().get("location"));
- }
-
- @Test
- public void createInvalidMembership() {
- // 1. create anyObject in realm /odd and attempt to assign group 15, from realm /even => exception
- AnyObjectTO anyObjectTO = getSampleTO("createInvalidMembership");
- anyObjectTO.setRealm("/odd");
- anyObjectTO.getMemberships().add(new MembershipTO.Builder().group(15L).build());
-
- try {
- createAnyObject(anyObjectTO);
- fail();
- } catch (SyncopeClientException e) {
- assertEquals(ClientExceptionType.InvalidMembership, e.getType());
- }
-
- // 2. change anyObject's realm to /even/two, now it works
- anyObjectTO.setRealm("/even/two");
-
- anyObjectTO = createAnyObject(anyObjectTO).getAny();
- assertTrue(anyObjectTO.getMembershipMap().containsKey(15L));
- }
-
- @Test
- public void delete() {
- try {
- anyObjectService.delete(0L);
- } catch (SyncopeClientException e) {
- assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus());
- }
-
- AnyObjectTO anyObjectTO = getSampleTO("deletable");
- anyObjectTO.setRealm("/even");
-
- anyObjectTO = createAnyObject(anyObjectTO).getAny();
- assertNotNull(anyObjectTO);
-
- AnyObjectTO deletedAnyObject = deleteAnyObject(anyObjectTO.getKey()).getAny();
- assertNotNull(deletedAnyObject);
-
- try {
- anyObjectService.read(deletedAnyObject.getKey());
- } catch (SyncopeClientException e) {
- assertEquals(Response.Status.NOT_FOUND, e.getType().getResponseStatus());
- }
- }
-
- @Test
- public void list() {
- PagedResult<AnyObjectTO> anyObjectTOs = anyObjectService.list(
- "PRINTER", new AnyListQuery.Builder().realm(SyncopeConstants.ROOT_REALM).build());
- assertNotNull(anyObjectTOs);
- assertTrue(anyObjectTOs.getResult().size() >= 2);
- for (AnyObjectTO anyObjectTO : anyObjectTOs.getResult()) {
- assertNotNull(anyObjectTO);
- }
- }
-
- @Test
- public void read() {
- AnyObjectTO anyObjectTO = anyObjectService.read(1L);
- assertNotNull(anyObjectTO);
- assertNotNull(anyObjectTO.getPlainAttrs());
- assertFalse(anyObjectTO.getPlainAttrs().isEmpty());
- }
-
- @Test
- public void update() {
- AnyObjectTO anyObjectTO = getSampleTO("update");
- anyObjectTO = createAnyObject(anyObjectTO).getAny();
-
- assertEquals(1, anyObjectTO.getPlainAttrs().size());
-
- AnyObjectPatch anyObjectPatch = new AnyObjectPatch();
- anyObjectPatch.setKey(anyObjectTO.getKey());
- String newLocation = "new" + getUUIDString();
- anyObjectPatch.getPlainAttrs().add(attrAddReplacePatch("location", newLocation));
-
- anyObjectTO = updateAnyObject(anyObjectPatch).getAny();
-
- assertEquals(newLocation, anyObjectTO.getPlainAttrMap().get("location").getValues().get(0));
- }
-
- @Test
- public void readAttrs() {
- AnyObjectTO anyObjectTO = getSampleTO("readAttrs");
- anyObjectTO = createAnyObject(anyObjectTO).getAny();
- assertNotNull(anyObjectTO);
-
- Set<AttrTO> attrs = anyObjectService.read(anyObjectTO.getKey(), SchemaType.PLAIN);
- assertEquals(anyObjectTO.getPlainAttrs(), attrs);
-
- AttrTO location = anyObjectService.read(anyObjectTO.getKey(), SchemaType.PLAIN, "location");
- assertEquals(anyObjectTO.getPlainAttrMap().get("location"), location);
- }
-
- @Test
- public void updateAttr() {
- AnyObjectTO anyObjectTO = getSampleTO("updateAttr");
- anyObjectTO = createAnyObject(anyObjectTO).getAny();
- assertNotNull(anyObjectTO);
-
- AttrTO updated = attrTO("location", "newlocation");
- anyObjectService.update(anyObjectTO.getKey(), SchemaType.PLAIN, updated);
-
- AttrTO location = anyObjectService.read(anyObjectTO.getKey(), SchemaType.PLAIN, "location");
- assertEquals(updated, location);
- }
-
- @Test
- public void deleteAttr() {
- AnyObjectTO anyObjectTO = getSampleTO("deleteAttr");
- anyObjectTO = createAnyObject(anyObjectTO).getAny();
- assertNotNull(anyObjectTO);
- assertNotNull(anyObjectTO.getPlainAttrMap().get("location"));
-
- anyObjectService.delete(anyObjectTO.getKey(), SchemaType.PLAIN, "location");
-
- try {
- anyObjectService.read(anyObjectTO.getKey(), SchemaType.PLAIN, "location");
- fail();
- } catch (SyncopeClientException e) {
- assertEquals(ClientExceptionType.NotFound, e.getType());
- }
- }
-
- @Test
- public void issueSYNCOPE756() {
- AnyObjectTO anyObjectTO = getSampleTO("issueSYNCOPE756");
- anyObjectTO.getRelationships().add(new RelationshipTO.Builder().right(AnyTypeKind.USER.name(), 1).build());
-
- try {
- createAnyObject(anyObjectTO).getAny();
- fail();
- } catch (SyncopeClientException e) {
- assertEquals(ClientExceptionType.InvalidAnyType, e.getType());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/17d5d892/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AnyTypeClassITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AnyTypeClassITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AnyTypeClassITCase.java
deleted file mode 100644
index 7bc9349..0000000
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AnyTypeClassITCase.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.fit.core.reference;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.List;
-import javax.ws.rs.core.Response;
-import org.apache.syncope.common.lib.SyncopeClientException;
-import org.apache.syncope.common.lib.to.AnyTypeClassTO;
-import org.apache.syncope.common.lib.to.DerSchemaTO;
-import org.apache.syncope.common.lib.to.PlainSchemaTO;
-import org.apache.syncope.common.lib.types.AttrSchemaType;
-import org.apache.syncope.common.lib.types.ClientExceptionType;
-import org.apache.syncope.common.lib.types.SchemaType;
-import org.apache.syncope.common.rest.api.service.AnyTypeClassService;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-
-@FixMethodOrder(MethodSorters.JVM)
-public class AnyTypeClassITCase extends AbstractITCase {
-
- @Test
- public void read() {
- AnyTypeClassTO minimalGroup = anyTypeClassService.read("minimal group");
- assertNotNull(minimalGroup);
-
- assertFalse(minimalGroup.getPlainSchemas().isEmpty());
- assertFalse(minimalGroup.getDerSchemas().isEmpty());
- assertFalse(minimalGroup.getVirSchemas().isEmpty());
- }
-
- @Test
- public void list() {
- List<AnyTypeClassTO> list = anyTypeClassService.list();
- assertFalse(list.isEmpty());
- }
-
- @Test
- public void crud() {
- // 1. create sample schemas
- PlainSchemaTO plainSchema = new PlainSchemaTO();
- plainSchema.setKey("new_plain_schema" + getUUIDString());
- plainSchema.setType(AttrSchemaType.String);
- plainSchema = createSchema(SchemaType.PLAIN, plainSchema);
-
- DerSchemaTO derSchema = new DerSchemaTO();
- derSchema.setKey("new_der_schema" + getUUIDString());
- derSchema.setExpression(plainSchema.getKey() + " + '_' + derived_dx");
- derSchema = createSchema(SchemaType.DERIVED, derSchema);
-
- // 2. actual CRUD
- AnyTypeClassTO newClass = new AnyTypeClassTO();
- newClass.setKey("new class" + getUUIDString());
- newClass.getPlainSchemas().add(plainSchema.getKey());
-
- Response response = anyTypeClassService.create(newClass);
- assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
-
- newClass = getObject(response.getLocation(), AnyTypeClassService.class, AnyTypeClassTO.class);
- assertNotNull(newClass);
- assertFalse(newClass.getPlainSchemas().isEmpty());
- assertTrue(newClass.getDerSchemas().isEmpty());
- assertTrue(newClass.getVirSchemas().isEmpty());
-
- newClass.getDerSchemas().add(derSchema.getKey());
- anyTypeClassService.update(newClass);
-
- newClass = anyTypeClassService.read(newClass.getKey());
- assertNotNull(newClass);
- assertFalse(newClass.getPlainSchemas().isEmpty());
- assertFalse(newClass.getDerSchemas().isEmpty());
- assertTrue(newClass.getVirSchemas().isEmpty());
-
- assertEquals(newClass.getKey(), schemaService.read(SchemaType.PLAIN, plainSchema.getKey()).getAnyTypeClass());
- assertEquals(newClass.getKey(), schemaService.read(SchemaType.DERIVED, derSchema.getKey()).getAnyTypeClass());
-
- anyTypeClassService.delete(newClass.getKey());
-
- try {
- anyTypeClassService.read(newClass.getKey());
- fail();
- } catch (SyncopeClientException e) {
- assertEquals(ClientExceptionType.NotFound, e.getType());
- }
-
- assertNull(schemaService.read(SchemaType.PLAIN, plainSchema.getKey()).getAnyTypeClass());
- assertNull(schemaService.read(SchemaType.DERIVED, derSchema.getKey()).getAnyTypeClass());
- }
-
- @Test
- public void deleteSchema() {
- PlainSchemaTO newSchema = new PlainSchemaTO();
- newSchema.setKey("newSchema" + getUUIDString());
- newSchema.setType(AttrSchemaType.Date);
- createSchema(SchemaType.PLAIN, newSchema);
-
- AnyTypeClassTO newClass = new AnyTypeClassTO();
- newClass.setKey("new class" + getUUIDString());
- newClass.getPlainSchemas().add(newSchema.getKey());
-
- Response response = anyTypeClassService.create(newClass);
- assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
-
- newClass = getObject(response.getLocation(), AnyTypeClassService.class, AnyTypeClassTO.class);
- assertNotNull(newClass);
- assertTrue(newClass.getPlainSchemas().contains(newSchema.getKey()));
-
- schemaService.delete(SchemaType.PLAIN, newSchema.getKey());
-
- newClass = anyTypeClassService.read(newClass.getKey());
- assertNotNull(newClass);
- assertFalse(newClass.getPlainSchemas().contains(newSchema.getKey()));
- }
-
- @Test
- public void issueSYNCOPE759() {
- AnyTypeClassTO minimalGroup = anyTypeClassService.read("minimal group");
- assertNotNull(minimalGroup);
-
- AnyTypeClassTO newAnyTypeClass = new AnyTypeClassTO();
- newAnyTypeClass.setKey(minimalGroup.getKey());
-
- try {
- anyTypeClassService.create(newAnyTypeClass);
- fail();
- } catch (SyncopeClientException e) {
- assertEquals(ClientExceptionType.EntityExists, e.getType());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/17d5d892/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AnyTypeITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AnyTypeITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AnyTypeITCase.java
deleted file mode 100644
index 704370e..0000000
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AnyTypeITCase.java
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.fit.core.reference;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.List;
-import javax.ws.rs.core.Response;
-import org.apache.syncope.common.lib.SyncopeClientException;
-import org.apache.syncope.common.lib.to.AnyTypeClassTO;
-import org.apache.syncope.common.lib.to.AnyTypeTO;
-import org.apache.syncope.common.lib.types.AnyTypeKind;
-import org.apache.syncope.common.lib.types.ClientExceptionType;
-import org.apache.syncope.common.rest.api.service.AnyTypeClassService;
-import org.apache.syncope.common.rest.api.service.AnyTypeService;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-
-@FixMethodOrder(MethodSorters.JVM)
-public class AnyTypeITCase extends AbstractITCase {
-
- @Test
- public void read() {
- AnyTypeTO userType = anyTypeService.read(AnyTypeKind.USER.name());
- assertNotNull(userType);
- assertEquals(AnyTypeKind.USER, userType.getKind());
- assertEquals(AnyTypeKind.USER.name(), userType.getKey());
- assertFalse(userType.getClasses().isEmpty());
-
- AnyTypeTO groupType = anyTypeService.read(AnyTypeKind.GROUP.name());
- assertNotNull(groupType);
- assertEquals(AnyTypeKind.GROUP, groupType.getKind());
- assertEquals(AnyTypeKind.GROUP.name(), groupType.getKey());
- assertFalse(groupType.getClasses().isEmpty());
-
- AnyTypeTO otherType = anyTypeService.read("PRINTER");
- assertNotNull(otherType);
- assertEquals(AnyTypeKind.ANY_OBJECT, otherType.getKind());
- assertEquals("PRINTER", otherType.getKey());
- }
-
- @Test
- public void list() {
- List<AnyTypeTO> list = anyTypeService.list();
- assertFalse(list.isEmpty());
- }
-
- @Test
- public void crud() {
- AnyTypeTO newType = new AnyTypeTO();
- newType.setKey("new type");
- newType.setKind(AnyTypeKind.ANY_OBJECT);
- newType.getClasses().add("generic membership");
- newType.getClasses().add("csv");
-
- Response response = anyTypeService.create(newType);
- assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
-
- newType = getObject(response.getLocation(), AnyTypeService.class, AnyTypeTO.class);
- assertNotNull(newType);
- assertEquals(2, newType.getClasses().size());
- assertTrue(newType.getClasses().contains("generic membership"));
- assertTrue(newType.getClasses().contains("csv"));
-
- newType.getClasses().remove("generic membership");
- anyTypeService.update(newType);
-
- newType = anyTypeService.read(newType.getKey());
- assertNotNull(newType);
- assertEquals(1, newType.getClasses().size());
- assertTrue(newType.getClasses().contains("csv"));
-
- anyTypeService.delete(newType.getKey());
-
- try {
- anyTypeService.read(newType.getKey());
- fail();
- } catch (SyncopeClientException e) {
- assertEquals(ClientExceptionType.NotFound, e.getType());
- }
- }
-
- @Test
- public void createInvalidKind() {
- AnyTypeTO newType = new AnyTypeTO();
- newType.setKey("new type");
- newType.setKind(AnyTypeKind.USER);
- try {
- anyTypeService.create(newType);
- fail();
- } catch (SyncopeClientException e) {
- assertEquals(ClientExceptionType.InvalidAnyType, e.getType());
- }
- }
-
- @Test
- public void createInvalidName() {
- AnyTypeTO newType = new AnyTypeTO();
- newType.setKey("group");
- newType.setKind(AnyTypeKind.ANY_OBJECT);
- try {
- anyTypeService.create(newType);
- fail();
- } catch (SyncopeClientException e) {
- assertEquals(ClientExceptionType.InvalidAnyType, e.getType());
- }
- }
-
- @Test
- public void deleteInvalid() {
- try {
- anyTypeService.delete(AnyTypeKind.USER.name());
- fail();
- } catch (SyncopeClientException e) {
- assertEquals(ClientExceptionType.InvalidAnyType, e.getType());
- }
- }
-
- @Test
- public void deleteTypeClass() {
- AnyTypeClassTO newClass = new AnyTypeClassTO();
- newClass.setKey("new class" + getUUIDString());
- newClass.getDerSchemas().add("cn");
-
- Response response = anyTypeClassService.create(newClass);
- assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatusInfo().getStatusCode());
-
- newClass = getObject(response.getLocation(), AnyTypeClassService.class, AnyTypeClassTO.class);
- assertNotNull(newClass);
-
- AnyTypeTO other = anyTypeService.read("PRINTER");
- assertNotNull(other);
-
- other.getClasses().add(newClass.getKey());
- anyTypeService.update(other);
-
- other = anyTypeService.read(other.getKey());
- assertNotNull(other);
- assertTrue(other.getClasses().contains(newClass.getKey()));
-
- anyTypeClassService.delete(newClass.getKey());
-
- other = anyTypeService.read(other.getKey());
- assertNotNull(other);
- assertFalse(other.getClasses().contains(newClass.getKey()));
- }
-
- @Test
- public void issueSYNCOPE754() {
- AnyTypeClassTO other = anyTypeClassService.read("other");
- assertNotNull(other);
-
- AnyTypeTO group = anyTypeService.read(AnyTypeKind.GROUP.name());
- try {
- assertFalse(group.getClasses().contains("other"));
- group.getClasses().add("other");
-
- anyTypeService.update(group);
-
- group = anyTypeService.read(AnyTypeKind.GROUP.name());
- assertTrue(group.getClasses().contains("other"));
-
- other = anyTypeClassService.read("other");
- assertEquals(2, other.getInUseByTypes().size());
- assertTrue(other.getInUseByTypes().contains(AnyTypeKind.USER.name()));
- assertTrue(other.getInUseByTypes().contains(AnyTypeKind.GROUP.name()));
- } finally {
- group.getClasses().remove("other");
- anyTypeService.update(group);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/syncope/blob/17d5d892/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AuthenticationITCase.java
----------------------------------------------------------------------
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AuthenticationITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AuthenticationITCase.java
deleted file mode 100644
index a7f74ee..0000000
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/reference/AuthenticationITCase.java
+++ /dev/null
@@ -1,564 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.syncope.fit.core.reference;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.security.AccessControlException;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import javax.ws.rs.core.GenericType;
-import javax.ws.rs.core.Response;
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.collections4.IterableUtils;
-import org.apache.commons.collections4.Predicate;
-import org.apache.commons.collections4.Transformer;
-import org.apache.commons.lang3.tuple.Pair;
-import org.apache.syncope.client.lib.SyncopeClient;
-import org.apache.syncope.common.lib.SyncopeClientException;
-import org.apache.syncope.common.lib.SyncopeConstants;
-import org.apache.syncope.common.lib.patch.DeassociationPatch;
-import org.apache.syncope.common.lib.patch.PasswordPatch;
-import org.apache.syncope.common.lib.patch.StatusPatch;
-import org.apache.syncope.common.lib.patch.StringPatchItem;
-import org.apache.syncope.common.lib.patch.StringReplacePatchItem;
-import org.apache.syncope.common.lib.patch.UserPatch;
-import org.apache.syncope.common.lib.to.AnyObjectTO;
-import org.apache.syncope.common.lib.to.AnyTypeClassTO;
-import org.apache.syncope.common.lib.to.AnyTypeTO;
-import org.apache.syncope.common.lib.to.BulkActionResult;
-import org.apache.syncope.common.lib.to.MembershipTO;
-import org.apache.syncope.common.lib.to.PagedResult;
-import org.apache.syncope.common.lib.to.PlainSchemaTO;
-import org.apache.syncope.common.lib.to.ProvisioningResult;
-import org.apache.syncope.common.lib.to.RoleTO;
-import org.apache.syncope.common.lib.to.UserTO;
-import org.apache.syncope.common.lib.to.WorkflowFormPropertyTO;
-import org.apache.syncope.common.lib.to.WorkflowFormTO;
-import org.apache.syncope.common.lib.types.AnyTypeKind;
-import org.apache.syncope.common.lib.types.AttrSchemaType;
-import org.apache.syncope.common.lib.types.CipherAlgorithm;
-import org.apache.syncope.common.lib.types.ClientExceptionType;
-import org.apache.syncope.common.lib.types.PatchOperation;
-import org.apache.syncope.common.lib.types.ResourceDeassociationAction;
-import org.apache.syncope.common.lib.types.SchemaType;
-import org.apache.syncope.common.lib.types.StandardEntitlement;
-import org.apache.syncope.common.lib.types.StatusPatchType;
-import org.apache.syncope.common.rest.api.RESTHeaders;
-import org.apache.syncope.common.rest.api.beans.AnySearchQuery;
-import org.apache.syncope.common.rest.api.service.AnyObjectService;
-import org.apache.syncope.common.rest.api.service.SchemaService;
-import org.apache.syncope.common.rest.api.service.UserService;
-import org.apache.syncope.core.misc.security.Encryptor;
-import org.junit.Assume;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-import org.springframework.jdbc.core.JdbcTemplate;
-
-@FixMethodOrder(MethodSorters.JVM)
-public class AuthenticationITCase extends AbstractITCase {
-
- private int getFailedLogins(final UserService userService, final long userId) {
- UserTO readUserTO = userService.read(userId);
- assertNotNull(readUserTO);
- assertNotNull(readUserTO.getFailedLogins());
- return readUserTO.getFailedLogins();
- }
-
- private void assertReadFails(final SyncopeClient client) {
- try {
- client.self();
- fail("access should not work");
- } catch (Exception e) {
- assertNotNull(e);
- }
- }
-
- @Test
- public void testReadEntitlements() {
- // 1. as not authenticated (not allowed)
- try {
- clientFactory.create().self();
- fail();
- } catch (AccessControlException e) {
- assertNotNull(e);
- }
-
- // 2. as anonymous
- Pair<Map<String, Set<String>>, UserTO> self = clientFactory.create(ANONYMOUS_UNAME, ANONYMOUS_KEY).self();
- assertEquals(1, self.getKey().size());
- assertTrue(self.getKey().keySet().contains(StandardEntitlement.ANONYMOUS));
- assertEquals(ANONYMOUS_UNAME, self.getValue().getUsername());
-
- // 3. as admin
- self = adminClient.self();
- assertEquals(syncopeService.info().getEntitlements().size(), self.getKey().size());
- assertFalse(self.getKey().keySet().contains(StandardEntitlement.ANONYMOUS));
- assertEquals(ADMIN_UNAME, self.getValue().getUsername());
-
- // 4. as user
- self = clientFactory.create("bellini", ADMIN_PWD).self();
- assertFalse(self.getKey().isEmpty());
- assertFalse(self.getKey().keySet().contains(StandardEntitlement.ANONYMOUS));
- assertEquals("bellini", self.getValue().getUsername());
- }
-
- @Test
- public void testUserSchemaAuthorization() {
- String schemaName = "authTestSchema" + getUUIDString();
-
- // 1. create a schema (as admin)
- PlainSchemaTO schemaTO = new PlainSchemaTO();
- schemaTO.setKey(schemaName);
- schemaTO.setMandatoryCondition("false");
- schemaTO.setType(AttrSchemaType.String);
-
- PlainSchemaTO newPlainSchemaTO = createSchema(SchemaType.PLAIN, schemaTO);
- assertEquals(schemaTO, newPlainSchemaTO);
-
- // 2. create an user with the role created above (as admin)
- UserTO userTO = UserITCase.getUniqueSampleTO("auth@test.org");
- userTO = createUser(userTO).getAny();
- assertNotNull(userTO);
-
- // 3. read the schema created above (as admin) - success
- schemaTO = schemaService.read(SchemaType.PLAIN, schemaName);
- assertNotNull(schemaTO);
-
- // 4. read the schema created above (as user) - success
- SchemaService schemaService2 = clientFactory.create(userTO.getUsername(), "password123").
- getService(SchemaService.class);
- schemaTO = schemaService2.read(SchemaType.PLAIN, schemaName);
- assertNotNull(schemaTO);
-
- // 5. update the schema create above (as user) - failure
- try {
- schemaService2.update(SchemaType.PLAIN, schemaTO);
- fail("Schemaupdate as user should not work");
- } catch (AccessControlException e) {
- // CXF Service will throw this exception
- assertNotNull(e);
- }
-
- assertEquals(0, getFailedLogins(userService, userTO.getKey()));
- }
-
- @Test
- public void testUserRead() {
- UserTO userTO = UserITCase.getUniqueSampleTO("testuserread@test.org");
- userTO.getRoles().add("User manager");
-
- userTO = createUser(userTO).getAny();
- assertNotNull(userTO);
-
- UserService userService2 = clientFactory.create(userTO.getUsername(), "password123").
- getService(UserService.class);
-
- UserTO readUserTO = userService2.read(1L);
- assertNotNull(readUserTO);
-
- UserService userService3 = clientFactory.create("puccini", ADMIN_PWD).getService(UserService.class);
-
- try {
- userService3.read(3L);
- fail();
- } catch (SyncopeClientException e) {
- assertNotNull(e);
- assertEquals(ClientExceptionType.DelegatedAdministration, e.getType());
- }
- }
-
- @Test
- public void testUserSearch() {
- UserTO userTO = UserITCase.getUniqueSampleTO("testusersearch@test.org");
- userTO.getRoles().add("User reviewer");
-
- userTO = createUser(userTO).getAny();
- assertNotNull(userTO);
-
- // 1. user assigned to role 1, with search entitlement on realms /odd and /even: won't find anything with
- // root realm
- UserService userService2 = clientFactory.create(userTO.getUsername(), "password123").
- getService(UserService.class);
-
- PagedResult<UserTO> matchedUsers = userService2.search(
- new AnySearchQuery.Builder().realm(SyncopeConstants.ROOT_REALM).
- fiql(SyncopeClient.getUserSearchConditionBuilder().isNotNull("key").query()).build());
- assertNotNull(matchedUsers);
- assertFalse(matchedUsers.getResult().isEmpty());
- Set<Long> matchedUserKeys = CollectionUtils.collect(matchedUsers.getResult(),
- new Transformer<UserTO, Long>() {
-
- @Override
- public Long transform(final UserTO input) {
- return input.getKey();
- }
- }, new HashSet<Long>());
- assertTrue(matchedUserKeys.contains(1L));
- assertFalse(matchedUserKeys.contains(2L));
- assertFalse(matchedUserKeys.contains(5L));
-
- // 2. user assigned to role 4, with search entitlement on realm /even/two
- UserService userService3 = clientFactory.create("puccini", ADMIN_PWD).getService(UserService.class);
-
- matchedUsers = userService3.search(
- new AnySearchQuery.Builder().realm("/even/two").
- fiql(SyncopeClient.getUserSearchConditionBuilder().isNotNull("loginDate").query()).build());
- assertNotNull(matchedUsers);
- assertTrue(IterableUtils.matchesAll(matchedUsers.getResult(), new Predicate<UserTO>() {
-
- @Override
- public boolean evaluate(final UserTO matched) {
- return "/even/two".equals(matched.getRealm());
- }
- }));
- }
-
- @Test
- public void delegatedUserCRUD() {
- String roleKey = null;
- Long delegatedAdminKey = null;
- try {
- // 1. create role for full user administration, under realm /even/two
- RoleTO role = new RoleTO();
- role.setKey("Delegated user admin");
- role.getEntitlements().add(StandardEntitlement.USER_CREATE);
- role.getEntitlements().add(StandardEntitlement.USER_UPDATE);
- role.getEntitlements().add(StandardEntitlement.USER_DELETE);
- role.getEntitlements().add(StandardEntitlement.USER_LIST);
- role.getEntitlements().add(StandardEntitlement.USER_READ);
- role.getRealms().add("/even/two");
-
- roleKey = roleService.create(role).getHeaderString(RESTHeaders.RESOURCE_KEY);
- assertNotNull(roleKey);
-
- // 2. as admin, create delegated admin user, and assign the role just created
- UserTO delegatedAdmin = UserITCase.getUniqueSampleTO("admin@syncope.apache.org");
- delegatedAdmin.getRoles().add(roleKey);
- delegatedAdmin = createUser(delegatedAdmin).getAny();
- delegatedAdminKey = delegatedAdmin.getKey();
-
- // 3. instantiate a delegate user service client, for further operatins
- UserService delegatedUserService =
- clientFactory.create(delegatedAdmin.getUsername(), "password123").getService(UserService.class);
-
- // 4. as delegated, create user under realm / -> fail
- UserTO user = UserITCase.getUniqueSampleTO("delegated@syncope.apache.org");
- try {
- delegatedUserService.create(user);
- fail();
- } catch (SyncopeClientException e) {
- assertEquals(ClientExceptionType.DelegatedAdministration, e.getType());
- }
-
- // 5. set realm to /even/two -> succeed
- user.setRealm("/even/two");
-
- Response response = delegatedUserService.create(user);
- assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
-
- user = response.readEntity(new GenericType<ProvisioningResult<UserTO>>() {
- }).getAny();
- assertEquals("surname", user.getPlainAttrMap().get("surname").getValues().get(0));
-
- // 5. as delegated, update user attempting to move under realm / -> fail
- UserPatch userPatch = new UserPatch();
- userPatch.setKey(user.getKey());
- userPatch.setRealm(new StringReplacePatchItem.Builder().value("/odd").build());
- userPatch.getPlainAttrs().add(attrAddReplacePatch("surname", "surname2"));
-
- try {
- delegatedUserService.update(userPatch);
- fail();
- } catch (SyncopeClientException e) {
- assertEquals(ClientExceptionType.DelegatedAdministration, e.getType());
- }
-
- // 6. revert realm change -> succeed
- userPatch.setRealm(null);
-
- response = delegatedUserService.update(userPatch);
- assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
-
- user = response.readEntity(new GenericType<ProvisioningResult<UserTO>>() {
- }).getAny();
- assertEquals("surname2", user.getPlainAttrMap().get("surname").getValues().get(0));
-
- // 7. as delegated, delete user
- delegatedUserService.delete(user.getKey());
-
- try {
- userService.read(user.getKey());
- fail();
- } catch (SyncopeClientException e) {
- assertEquals(ClientExceptionType.NotFound, e.getType());
- }
- } finally {
- if (roleKey != null) {
- roleService.delete(roleKey);
- }
- if (delegatedAdminKey != null) {
- userService.delete(delegatedAdminKey);
- }
- }
- }
-
- @Test
- public void checkFailedLogins() {
- UserTO userTO = UserITCase.getUniqueSampleTO("checkFailedLogin@syncope.apache.org");
- userTO.getRoles().add("User manager");
-
- userTO = createUser(userTO).getAny();
- assertNotNull(userTO);
- long userId = userTO.getKey();
-
- UserService userService2 = clientFactory.create(userTO.getUsername(), "password123").
- getService(UserService.class);
- assertEquals(0, getFailedLogins(userService2, userId));
-
- // authentications failed ...
- SyncopeClient badPwdClient = clientFactory.create(userTO.getUsername(), "wrongpwd1");
- assertReadFails(badPwdClient);
- assertReadFails(badPwdClient);
-
- assertEquals(2, getFailedLogins(userService, userId));
-
- UserService userService4 = clientFactory.create(userTO.getUsername(), "password123").
- getService(UserService.class);
- assertEquals(0, getFailedLogins(userService4, userId));
- }
-
- @Test
- public void checkUserSuspension() {
- UserTO userTO = UserITCase.getUniqueSampleTO("checkSuspension@syncope.apache.org");
- userTO.setRealm("/odd");
- userTO.getRoles().add("User manager");
-
- userTO = createUser(userTO).getAny();
- long userKey = userTO.getKey();
- assertNotNull(userTO);
-
- assertEquals(0, getFailedLogins(userService, userKey));
-
- // authentications failed ...
- SyncopeClient badPwdClient = clientFactory.create(userTO.getUsername(), "wrongpwd1");
- assertReadFails(badPwdClient);
- assertReadFails(badPwdClient);
- assertReadFails(badPwdClient);
-
- assertEquals(3, getFailedLogins(userService, userKey));
-
- // last authentication before suspension
- assertReadFails(badPwdClient);
-
- userTO = userService.read(userTO.getKey());
- assertNotNull(userTO);
- assertNotNull(userTO.getFailedLogins());
- assertEquals(3, userTO.getFailedLogins(), 0);
- assertEquals("suspended", userTO.getStatus());
-
- // Access with correct credentials should fail as user is suspended
- SyncopeClient goodPwdClient = clientFactory.create(userTO.getUsername(), "password123");
- assertReadFails(goodPwdClient);
-
- StatusPatch reactivate = new StatusPatch();
- reactivate.setKey(userTO.getKey());
- reactivate.setType(StatusPatchType.REACTIVATE);
- userTO = userService.status(reactivate).readEntity(new GenericType<ProvisioningResult<UserTO>>() {
- }).getAny();
- assertNotNull(userTO);
- assertEquals("active", userTO.getStatus());
-
- assertEquals(0, goodPwdClient.self().getValue().getFailedLogins(), 0);
- }
-
- @Test
- public void anyTypeEntitlement() {
- final String anyTypeKey = "FOLDER " + getUUIDString();
-
- // 1. no entitlement exists (yet) for the any type to be created
- assertFalse(IterableUtils.matchesAny(syncopeService.info().getEntitlements(), new Predicate<String>() {
-
- @Override
- public boolean evaluate(final String entitlement) {
- return entitlement.contains(anyTypeKey);
- }
- }));
-
- // 2. create plain schema, any type class and any type
- PlainSchemaTO path = new PlainSchemaTO();
- path.setKey("path" + getUUIDString());
- path.setType(AttrSchemaType.String);
- path = createSchema(SchemaType.PLAIN, path);
-
- AnyTypeClassTO anyTypeClass = new AnyTypeClassTO();
- anyTypeClass.setKey("folder" + getUUIDString());
- anyTypeClass.getPlainSchemas().add(path.getKey());
- anyTypeClassService.create(anyTypeClass);
-
- AnyTypeTO anyTypeTO = new AnyTypeTO();
- anyTypeTO.setKey(anyTypeKey);
- anyTypeTO.setKind(AnyTypeKind.ANY_OBJECT);
- anyTypeTO.getClasses().add(anyTypeClass.getKey());
- anyTypeService.create(anyTypeTO);
-
- // 2. now entitlement exists for the any type just created
- assertTrue(IterableUtils.matchesAny(syncopeService.info().getEntitlements(), new Predicate<String>() {
-
- @Override
- public boolean evaluate(final String entitlement) {
- return entitlement.contains(anyTypeKey);
- }
- }));
-
- // 3. attempt to create an instance of the type above: fail because no entitlement was assigned
- AnyObjectTO folder = new AnyObjectTO();
- folder.setRealm(SyncopeConstants.ROOT_REALM);
- folder.setType(anyTypeKey);
- folder.getPlainAttrs().add(attrTO(path.getKey(), "/home"));
-
- SyncopeClient belliniClient = clientFactory.create("bellini", ADMIN_PWD);
- try {
- belliniClient.getService(AnyObjectService.class).create(folder);
- fail();
- } catch (SyncopeClientException e) {
- assertEquals(ClientExceptionType.DelegatedAdministration, e.getType());
- }
-
- // 4. give create entitlement for the any type just created
- RoleTO role = new RoleTO();
- role.setKey("role" + getUUIDString());
- role.getRealms().add(SyncopeConstants.ROOT_REALM);
- role.getEntitlements().add(anyTypeKey + "_READ");
- role.getEntitlements().add(anyTypeKey + "_CREATE");
- role = createRole(role);
-
- UserTO bellini = readUser("bellini");
- UserPatch patch = new UserPatch();
- patch.setKey(bellini.getKey());
- patch.getRoles().add(new StringPatchItem.Builder().
- operation(PatchOperation.ADD_REPLACE).value(role.getKey()).build());
- bellini = updateUser(patch).getAny();
- assertTrue(bellini.getRoles().contains(role.getKey()));
-
- // 5. now the instance of the type above can be created successfully
- belliniClient.getService(AnyObjectService.class).create(folder);
- }
-
- @Test
- public void issueSYNCOPE434() {
- Assume.assumeTrue(ActivitiDetector.isActivitiEnabledForUsers(syncopeService));
-
- // 1. create user with group 9 (users with group 9 are defined in workflow as subject to approval)
- UserTO userTO = UserITCase.getUniqueSampleTO("createWithReject@syncope.apache.org");
- userTO.getMemberships().add(new MembershipTO.Builder().group(9L).build());
-
- userTO = createUser(userTO).getAny();
- assertNotNull(userTO);
- assertEquals("createApproval", userTO.getStatus());
-
- // 2. try to authenticate: fail
- try {
- clientFactory.create(userTO.getUsername(), "password123").self();
- fail();
- } catch (AccessControlException e) {
- assertNotNull(e);
- }
-
- // 3. approve user
- WorkflowFormTO form = userWorkflowService.getFormForUser(userTO.getKey());
- form = userWorkflowService.claimForm(form.getTaskId());
- Map<String, WorkflowFormPropertyTO> props = form.getPropertyMap();
- props.get("approve").setValue(Boolean.TRUE.toString());
- form.getProperties().clear();
- form.getProperties().addAll(props.values());
- userTO = userWorkflowService.submitForm(form);
- assertNotNull(userTO);
- assertEquals("active", userTO.getStatus());
-
- // 4. try to authenticate again: success
- Pair<Map<String, Set<String>>, UserTO> self =
- clientFactory.create(userTO.getUsername(), "password123").self();
- assertNotNull(self);
- assertNotNull(self.getKey());
- assertNotNull(self.getValue());
- }
-
- @Test
- public void issueSYNCOPE164() throws Exception {
- // 1. create user with db resource
- UserTO user = UserITCase.getUniqueSampleTO("syncope164@syncope.apache.org");
- user.setRealm("/even/two");
- user.setPassword("password123");
- user.getResources().add(RESOURCE_NAME_TESTDB);
- user = createUser(user).getAny();
- assertNotNull(user);
-
- // 2. unlink the resource from the created user
- DeassociationPatch deassociationPatch = new DeassociationPatch();
- deassociationPatch.setKey(user.getKey());
- deassociationPatch.setAction(ResourceDeassociationAction.UNLINK);
- deassociationPatch.getResources().add(RESOURCE_NAME_TESTDB);
- assertNotNull(userService.deassociate(deassociationPatch).readEntity(BulkActionResult.class));
-
- // 3. change password on Syncope
- UserPatch userPatch = new UserPatch();
- userPatch.setKey(user.getKey());
- userPatch.setPassword(new PasswordPatch.Builder().value("password234").build());
- user = updateUser(userPatch).getAny();
- assertNotNull(user);
-
- // 4. check that the db resource has still the initial password value
- final JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
- String value = jdbcTemplate.queryForObject(
- "SELECT PASSWORD FROM test WHERE ID=?", String.class, user.getUsername());
- assertEquals(Encryptor.getInstance().encode("password123", CipherAlgorithm.SHA1), value.toUpperCase());
-
- // 5. successfully authenticate with old (on db resource) and new (on internal storage) password values
- Pair<Map<String, Set<String>>, UserTO> self =
- clientFactory.create(user.getUsername(), "password123").self();
- assertNotNull(self);
- self = clientFactory.create(user.getUsername(), "password234").self();
- assertNotNull(self);
- }
-
- @Test
- public void issueSYNCOPE706() {
- String username = getUUIDString();
- try {
- userService.getUserKey(username);
- fail();
- } catch (SyncopeClientException e) {
- assertEquals(ClientExceptionType.NotFound, e.getType());
- }
-
- try {
- clientFactory.create(username, "anypassword").self();
- fail();
- } catch (AccessControlException e) {
- assertNotNull(e.getMessage());
- }
- }
-}