Author: jbernhardt Date: Wed Jan 30 09:55:40 2013 New Revision: 1440323 URL: http://svn.apache.org/viewvc?rev=1440323&view=rev Log: [SYNCOPE-231][SYNCOPE-289] * Fixing UserService * Removing RestTemplate dependencies from IT tests * Code cleanup
Modified: syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/RoleServiceProxy.java syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/UserRequestServiceProxy.java syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/UserServiceProxy.java syncope/trunk/console/src/main/java/org/apache/syncope/console/rest/UserRequestRestClient.java syncope/trunk/core/src/main/java/org/apache/syncope/core/services/LoggerServiceImpl.java syncope/trunk/core/src/main/java/org/apache/syncope/core/services/NotificationServiceImpl.java syncope/trunk/core/src/main/java/org/apache/syncope/core/services/PolicyServiceImpl.java syncope/trunk/core/src/main/java/org/apache/syncope/core/services/ReportServiceImpl.java syncope/trunk/core/src/main/java/org/apache/syncope/core/services/ResourceServiceImpl.java syncope/trunk/core/src/main/java/org/apache/syncope/core/services/RoleServiceImpl.java syncope/trunk/core/src/main/java/org/apache/syncope/core/services/SchemaServiceImpl.java syncope/trunk/core/src/main/java/org/apache/syncope/core/services/UserRequestServiceImpl.java syncope/trunk/core/src/main/java/org/apache/syncope/core/services/UserServiceImpl.java syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java Modified: syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/RoleServiceProxy.java URL: http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/RoleServiceProxy.java?rev=1440323&r1=1440322&r2=1440323&view=diff ============================================================================== --- syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/RoleServiceProxy.java (original) +++ syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/RoleServiceProxy.java Wed Jan 30 09:55:40 2013 @@ -54,7 +54,10 @@ public class RoleServiceProxy extends Sp RoleTO role = getRestTemplate().postForObject(baseUrl + "role/create", roleTO, RoleTO.class); URI location = URI.create(baseUrl + "role/read/" + role.getId() + ".json"); - return Response.created(location).header(SyncopeConstants.REST_HEADER_ID, role.getId()).entity(role).build(); + return Response.created(location) + .header(SyncopeConstants.REST_HEADER_ID, role.getId()) + .entity(role) + .build(); } @Override Modified: syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/UserRequestServiceProxy.java URL: http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/UserRequestServiceProxy.java?rev=1440323&r1=1440322&r2=1440323&view=diff ============================================================================== --- syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/UserRequestServiceProxy.java (original) +++ syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/UserRequestServiceProxy.java Wed Jan 30 09:55:40 2013 @@ -22,6 +22,8 @@ import java.net.URI; import java.util.Arrays; import java.util.List; import javax.ws.rs.core.Response; + +import org.apache.syncope.common.SyncopeConstants; import org.apache.syncope.common.services.UserRequestService; import org.apache.syncope.common.to.UserRequestTO; import org.springframework.web.client.RestTemplate; @@ -39,7 +41,7 @@ public class UserRequestServiceProxy ext @Override public boolean isCreateAllowed() { - return getRestTemplate().getForObject(baseUrl + "user/request/create/allowed", Boolean.class); + return getRestTemplate().getForObject(baseUrl + "user/request/create/allowed.json", Boolean.class); } @Override @@ -62,24 +64,24 @@ public class UserRequestServiceProxy ext UserRequestTO.class); } - URI location = URI.create(baseUrl + "user/request/read/" + created.getId()); - return Response.created(location).entity(created.getId()).build(); + URI location = URI.create(baseUrl + "user/request/read/" + created.getId() + ".json"); + return Response.created(location).header(SyncopeConstants.REST_HEADER_ID, created.getId()).build(); } @Override public List<UserRequestTO> list() { - return Arrays.asList(getRestTemplate().getForObject(baseUrl + "user/request/list", UserRequestTO[].class)); + return Arrays.asList(getRestTemplate().getForObject(baseUrl + "user/request/list.json", UserRequestTO[].class)); } @Override public UserRequestTO read(final Long requestId) { return getRestTemplate().getForObject( - baseUrl + "user/request/read/{requestId}", UserRequestTO.class, requestId); + baseUrl + "user/request/read/{requestId}.json", UserRequestTO.class, requestId); } @Override public void delete(final Long requestId) { getRestTemplate().getForObject( - baseUrl + "user/request/deleteRequest/{requestId}", UserRequestTO.class, requestId); + baseUrl + "user/request/deleteRequest/{requestId}.json", UserRequestTO.class, requestId); } } Modified: syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/UserServiceProxy.java URL: http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/UserServiceProxy.java?rev=1440323&r1=1440322&r2=1440323&view=diff ============================================================================== --- syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/UserServiceProxy.java (original) +++ syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/UserServiceProxy.java Wed Jan 30 09:55:40 2013 @@ -24,6 +24,7 @@ import java.util.List; import javax.ws.rs.core.Response; +import org.apache.syncope.common.SyncopeConstants; import org.apache.syncope.common.mod.UserMod; import org.apache.syncope.common.search.NodeCond; import org.apache.syncope.common.services.UserService; @@ -75,8 +76,11 @@ public class UserServiceProxy extends Sp @Override public Response create(final UserTO userTO) { UserTO created = getRestTemplate().postForObject(baseUrl + "user/create", userTO, UserTO.class); - URI location = URI.create(baseUrl + "user/" + created.getId()); - return Response.created(location).entity(created).build(); + URI location = URI.create(baseUrl + "user/read/" + created.getId() + ".json"); + return Response.created(location) + .header(SyncopeConstants.REST_HEADER_ID, created.getId()) + .entity(created) + .build(); } @Override Modified: syncope/trunk/console/src/main/java/org/apache/syncope/console/rest/UserRequestRestClient.java URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/rest/UserRequestRestClient.java?rev=1440323&r1=1440322&r2=1440323&view=diff ============================================================================== --- syncope/trunk/console/src/main/java/org/apache/syncope/console/rest/UserRequestRestClient.java (original) +++ syncope/trunk/console/src/main/java/org/apache/syncope/console/rest/UserRequestRestClient.java Wed Jan 30 09:55:40 2013 @@ -22,6 +22,7 @@ import java.util.List; import javax.ws.rs.core.Response; +import org.apache.syncope.common.SyncopeConstants; import org.apache.syncope.common.mod.UserMod; import org.apache.syncope.common.services.UserRequestService; import org.apache.syncope.common.to.UserRequestTO; @@ -42,27 +43,24 @@ public class UserRequestRestClient exten getService(UserRequestService.class).delete(requestId); } - public UserRequestTO requestCreate(final UserTO userTO) { + public void requestCreate(final UserTO userTO) { UserRequestTO userRequestTO = new UserRequestTO(); userRequestTO.setType(UserRequestType.CREATE); userRequestTO.setUserTO(userTO); - Response response = getService(UserRequestService.class).create(userRequestTO); - return getService(UserRequestService.class).read((Long) response.getEntity()); + getService(UserRequestService.class).create(userRequestTO); } - public UserRequestTO requestUpdate(final UserMod userMod) { + public void requestUpdate(final UserMod userMod) { UserRequestTO userRequestTO = new UserRequestTO(); userRequestTO.setType(UserRequestType.UPDATE); userRequestTO.setUserMod(userMod); - Response response = getService(UserRequestService.class).create(userRequestTO); - return getService(UserRequestService.class).read((Long) response.getEntity()); + getService(UserRequestService.class).create(userRequestTO); } - public UserRequestTO requestDelete(final Long userId) { + public void requestDelete(final Long userId) { UserRequestTO userRequestTO = new UserRequestTO(); userRequestTO.setType(UserRequestType.DELETE); userRequestTO.setUserId(userId); - Response response = getService(UserRequestService.class).create(userRequestTO); - return getService(UserRequestService.class).read((Long) response.getEntity()); + getService(UserRequestService.class).create(userRequestTO); } } Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/services/LoggerServiceImpl.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/services/LoggerServiceImpl.java?rev=1440323&r1=1440322&r2=1440323&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/services/LoggerServiceImpl.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/services/LoggerServiceImpl.java Wed Jan 30 09:55:40 2013 @@ -40,6 +40,29 @@ public class LoggerServiceImpl implement private LoggerController loggerController; @Override + public void delete(final LoggerType type, final String name) { + switch (type) { + case NORMAL: + loggerController.deleteLog(name); + break; + + case AUDIT: + try { + loggerController.disableAudit(AuditLoggerName.fromLoggerName(name)); + } catch (IllegalArgumentException e) { + throw new BadRequestException(e); + } catch (ParseException e) { + throw new BadRequestException(e); + } + break; + + default: + throw new BadRequestException(); + } + + } + + @Override public List<LoggerTO> list(final LoggerType type) { switch (type) { case NORMAL: @@ -87,27 +110,4 @@ public class LoggerServiceImpl implement } } - @Override - public void delete(final LoggerType type, final String name) { - switch (type) { - case NORMAL: - loggerController.deleteLog(name); - break; - - case AUDIT: - try { - loggerController.disableAudit(AuditLoggerName.fromLoggerName(name)); - } catch (IllegalArgumentException e) { - throw new BadRequestException(e); - } catch (ParseException e) { - throw new BadRequestException(e); - } - break; - - default: - throw new BadRequestException(); - } - - } - } Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/services/NotificationServiceImpl.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/services/NotificationServiceImpl.java?rev=1440323&r1=1440322&r2=1440323&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/services/NotificationServiceImpl.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/services/NotificationServiceImpl.java Wed Jan 30 09:55:40 2013 @@ -24,6 +24,7 @@ import java.util.List; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; +import org.apache.syncope.common.SyncopeConstants; import org.apache.syncope.common.services.NotificationService; import org.apache.syncope.common.to.NotificationTO; import org.apache.syncope.core.rest.controller.NotificationController; @@ -42,7 +43,9 @@ public class NotificationServiceImpl imp public Response create(final NotificationTO notificationTO) { NotificationTO createdNotificationTO = notificationController.createInternal(notificationTO); URI location = uriInfo.getAbsolutePathBuilder().path("" + createdNotificationTO.getId()).build(); - return Response.created(location).build(); + return Response.created(location) + .header(SyncopeConstants.REST_HEADER_ID, createdNotificationTO.getId()) + .build(); } @Override Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/services/PolicyServiceImpl.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/services/PolicyServiceImpl.java?rev=1440323&r1=1440322&r2=1440323&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/services/PolicyServiceImpl.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/services/PolicyServiceImpl.java Wed Jan 30 09:55:40 2013 @@ -64,7 +64,9 @@ public class PolicyServiceImpl implement throw new BadRequestException(); } URI location = uriInfo.getAbsolutePathBuilder().path(policy.getId() + "").build(); - return Response.created(location).header(SyncopeConstants.REST_HEADER_ID, policy.getId()).build(); + return Response.created(location) + .header(SyncopeConstants.REST_HEADER_ID, policy.getId()) + .build(); } @Override Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/services/ReportServiceImpl.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/services/ReportServiceImpl.java?rev=1440323&r1=1440322&r2=1440323&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/services/ReportServiceImpl.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/services/ReportServiceImpl.java Wed Jan 30 09:55:40 2013 @@ -28,6 +28,7 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.StreamingOutput; import javax.ws.rs.core.UriInfo; +import org.apache.syncope.common.SyncopeConstants; import org.apache.syncope.common.services.ReportService; import org.apache.syncope.common.to.ReportExecTO; import org.apache.syncope.common.to.ReportTO; @@ -53,7 +54,9 @@ public class ReportServiceImpl implement public Response create(final ReportTO reportTO) { ReportTO createdReportTO = reportController.createInternal(reportTO); URI location = uriInfo.getAbsolutePathBuilder().path("" + createdReportTO.getId()).build(); - return Response.created(location).build(); + return Response.created(location) + .header(SyncopeConstants.REST_HEADER_ID, createdReportTO.getId()) + .build(); } @Override Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/services/ResourceServiceImpl.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/services/ResourceServiceImpl.java?rev=1440323&r1=1440322&r2=1440323&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/services/ResourceServiceImpl.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/services/ResourceServiceImpl.java Wed Jan 30 09:55:40 2013 @@ -48,7 +48,9 @@ public class ResourceServiceImpl impleme public Response create(final ResourceTO resourceTO) { ResourceTO resource = resourceController.create(new DummyHTTPServletResponse(), resourceTO); URI location = uriInfo.getAbsolutePathBuilder().path(resource.getName()).build(); - return Response.created(location).header(SyncopeConstants.REST_HEADER_ID, resource.getName()).build(); + return Response.created(location) + .header(SyncopeConstants.REST_HEADER_ID, resource.getName()) + .build(); } @Override Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/services/RoleServiceImpl.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/services/RoleServiceImpl.java?rev=1440323&r1=1440322&r2=1440323&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/services/RoleServiceImpl.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/services/RoleServiceImpl.java Wed Jan 30 09:55:40 2013 @@ -56,7 +56,9 @@ public class RoleServiceImpl implements public Response create(final RoleTO roleTO) { RoleTO created = roleController.create(new DummyHTTPServletResponse(), roleTO); URI location = uriInfo.getAbsolutePathBuilder().path(created.getId() + "").build(); - return Response.created(location).header(SyncopeConstants.REST_HEADER_ID, created.getId()).entity(created) + return Response.created(location) + .header(SyncopeConstants.REST_HEADER_ID, created.getId()) + .entity(created) .build(); } Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/services/SchemaServiceImpl.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/services/SchemaServiceImpl.java?rev=1440323&r1=1440322&r2=1440323&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/services/SchemaServiceImpl.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/services/SchemaServiceImpl.java Wed Jan 30 09:55:40 2013 @@ -76,7 +76,9 @@ public class SchemaServiceImpl implement throw new BadRequestException(); } URI location = uriInfo.getAbsolutePathBuilder().path(response.getName()).build(); - return Response.created(location).header(SyncopeConstants.REST_HEADER_ID, response.getName()).build(); + return Response.created(location) + .header(SyncopeConstants.REST_HEADER_ID, response.getName()) + .build(); } @Override Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/services/UserRequestServiceImpl.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/services/UserRequestServiceImpl.java?rev=1440323&r1=1440322&r2=1440323&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/services/UserRequestServiceImpl.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/services/UserRequestServiceImpl.java Wed Jan 30 09:55:40 2013 @@ -24,6 +24,7 @@ import java.util.List; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; +import org.apache.syncope.common.SyncopeConstants; import org.apache.syncope.common.services.UserRequestService; import org.apache.syncope.common.to.UserRequestTO; import org.apache.syncope.common.types.UserRequestType; @@ -61,7 +62,9 @@ public class UserRequestServiceImpl impl userRequestController.delete(userRequestTO.getUserId()); } URI location = uriInfo.getAbsolutePathBuilder().path("" + outUserRequestTO.getId()).build(); - return Response.created(location).entity(outUserRequestTO.getId()).build(); + return Response.created(location) + .header(SyncopeConstants.REST_HEADER_ID, outUserRequestTO.getId()) + .build(); } @Override Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/services/UserServiceImpl.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/services/UserServiceImpl.java?rev=1440323&r1=1440322&r2=1440323&view=diff ============================================================================== --- syncope/trunk/core/src/main/java/org/apache/syncope/core/services/UserServiceImpl.java (original) +++ syncope/trunk/core/src/main/java/org/apache/syncope/core/services/UserServiceImpl.java Wed Jan 30 09:55:40 2013 @@ -79,7 +79,9 @@ public class UserServiceImpl implements public Response create(final UserTO userTO) { UserTO created = userController.createInternal(userTO); URI location = uriInfo.getAbsolutePathBuilder().path(created.getId() + "").build(); - return Response.created(location).header(SyncopeConstants.REST_HEADER_ID, created.getId()).entity(created) + return Response.created(location) + .header(SyncopeConstants.REST_HEADER_ID, created.getId()) + .entity(created) .build(); } Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java?rev=1440323&r1=1440322&r2=1440323&view=diff ============================================================================== --- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java (original) +++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AbstractTest.java Wed Jan 30 09:55:40 2013 @@ -47,6 +47,7 @@ import org.apache.syncope.client.service import org.apache.syncope.client.services.proxy.ResourceServiceProxy; import org.apache.syncope.client.services.proxy.RoleServiceProxy; import org.apache.syncope.client.services.proxy.SchemaServiceProxy; +import org.apache.syncope.client.services.proxy.SpringServiceProxy; import org.apache.syncope.client.services.proxy.TaskServiceProxy; import org.apache.syncope.client.services.proxy.UserRequestServiceProxy; import org.apache.syncope.client.services.proxy.UserServiceProxy; @@ -147,21 +148,21 @@ public abstract class AbstractTest { protected UserRequestService userRequestService; protected PolicyService policyService; - + @Autowired protected RestClientExceptionMapper clientExceptionMapper; @Before public void setup() throws Exception { - if (!enabledCXF) { - resetRestTemplate(); - } else { + if (enabledCXF) { setupCXFServices(); + } else { + resetRestTemplate(); } } // BEGIN Spring MVC Initialization - protected void setupRestTemplate(final String uid, final String pwd) { + private void setupRestTemplate(final String uid, final String pwd) { PreemptiveAuthHttpRequestFactory requestFactory = ((PreemptiveAuthHttpRequestFactory) restTemplate .getRequestFactory()); @@ -169,7 +170,7 @@ public abstract class AbstractTest { requestFactory.getAuthScope(), new UsernamePasswordCredentials(uid, pwd)); } - protected RestTemplate anonymousRestTemplate() { + private RestTemplate getAnonymousRestTemplate() { RestTemplate template = new RestTemplate(httpClientFactory); List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>(); converters.add(mappingJacksonHttpMessageConverter); @@ -254,6 +255,26 @@ public abstract class AbstractTest { // END CXF Initialization + @SuppressWarnings("unchecked") + public <T> T setupCredentials(final T proxy, final String username, final String password) { + if (proxy instanceof SpringServiceProxy) { + SpringServiceProxy service = (SpringServiceProxy) proxy; + if (username == null && password == null) { + service.setRestTemplate(getAnonymousRestTemplate()); + } else { + setupRestTemplate(username, password); + } + return proxy; + } else { + restClientFactory.setUsername(username); + restClientFactory.setPassword(password); + restClientFactory.setServiceClass(proxy.getClass()); + T serviceProxy = (T) restClientFactory.create(proxy.getClass()); + setupContentType(WebClient.client(serviceProxy)); + return serviceProxy; + } + } + public <T> T getObject(final Response response, final Class<T> type, final Object serviceProxy) { assertNotNull(response); assertNotNull(response.getLocation()); @@ -301,13 +322,13 @@ public abstract class AbstractTest { attr.addValueToBeAdded(valueToBeAdded); return attr; } - - protected UserTO createUser(UserTO userTO) { + + protected UserTO createUser(final UserTO userTO) { Response response = userService.create(userTO); return response.readEntity(UserTO.class); } - protected void assertCreated(Response response) { + protected void assertCreated(final Response response) { if (response.getStatus() != HttpStatus.SC_CREATED) { StringBuilder builder = new StringBuilder(); MultivaluedMap<String, Object> headers = response.getHeaders(); @@ -316,7 +337,8 @@ public abstract class AbstractTest { builder.append(key + ":" + headers.getFirst(key) + ","); } builder.append(")"); - throw new RuntimeException("Error on create. Status is : " + response.getStatus() + " with headers " + builder.toString()); + throw new RuntimeException("Error on create. Status is : " + response.getStatus() + " with headers " + + builder.toString()); } } } Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java?rev=1440323&r1=1440322&r2=1440323&view=diff ============================================================================== --- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java (original) +++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java Wed Jan 30 09:55:40 2013 @@ -33,6 +33,7 @@ import javax.ws.rs.core.Response; import org.apache.syncope.common.search.AttributeCond; import org.apache.syncope.common.search.NodeCond; import org.apache.syncope.common.services.SchemaService; +import org.apache.syncope.common.services.UserService; import org.apache.syncope.common.to.AttributeTO; import org.apache.syncope.common.to.EntitlementTO; import org.apache.syncope.common.to.MembershipTO; @@ -52,7 +53,7 @@ import org.springframework.web.client.Ht @FixMethodOrder(MethodSorters.JVM) public class AuthenticationTestITCase extends AbstractTest { - + @Test public void testAdminEntitlements() { // 1. as anonymous, read all available entitlements @@ -109,15 +110,15 @@ public class AuthenticationTestITCase ex assertNotNull(schemaTO); // 4. read the schema created above (as user) - success - super.setupRestTemplate(userTO.getUsername(), "password123"); + SchemaService schemaService2 = setupCredentials(schemaService, userTO.getUsername(), "password123"); - schemaTO = schemaService.read(AttributableType.USER, SchemaService.SchemaType.NORMAL, "authTestSchema"); + schemaTO = schemaService2.read(AttributableType.USER, SchemaService.SchemaType.NORMAL, "authTestSchema"); assertNotNull(schemaTO); // 5. update the schema create above (as user) - failure HttpClientErrorException exception = null; try { - schemaService.update(AttributableType.ROLE, SchemaService.SchemaType.NORMAL, schemaTO.getName(), schemaTO); + schemaService2.update(AttributableType.ROLE, SchemaService.SchemaType.NORMAL, schemaTO.getName(), schemaTO); } catch (HttpClientErrorException e) { exception = e; } @@ -149,20 +150,19 @@ public class AuthenticationTestITCase ex userTO = createUser(userTO); assertNotNull(userTO); - super.setupRestTemplate(userTO.getUsername(), "password123"); + UserService userService2 = setupCredentials(userService, userTO.getUsername(), "password123"); - UserTO readUserTO = userService.read(1L); + UserTO readUserTO = userService2.read(1L); assertNotNull(readUserTO); - super.setupRestTemplate("user2", "password"); + UserService userService3 = setupCredentials(userService, "user2", ADMIN_PWD); SyncopeClientException exception = null; try { - userService.read(1L); + userService3.read(1L); fail(); } catch (SyncopeClientCompositeErrorException e) { - exception = e - .getException(SyncopeClientExceptionType.UnauthorizedRole); + exception = e.getException(SyncopeClientExceptionType.UnauthorizedRole); } assertNotNull(exception); @@ -185,14 +185,13 @@ public class AuthenticationTestITCase ex userTO = createUser(userTO); assertNotNull(userTO); - super.setupRestTemplate(userTO.getUsername(), "password123"); + UserService userService2 = setupCredentials(userService, userTO.getUsername(), "password123"); - AttributeCond isNullCond = new AttributeCond( - AttributeCond.Type.ISNOTNULL); + AttributeCond isNullCond = new AttributeCond(AttributeCond.Type.ISNOTNULL); isNullCond.setSchema("loginDate"); NodeCond searchCondition = NodeCond.getLeafCond(isNullCond); - List<UserTO> matchedUsers = userService.search(searchCondition); + List<UserTO> matchedUsers = userService2.search(searchCondition); assertNotNull(matchedUsers); assertFalse(matchedUsers.isEmpty()); Set<Long> userIds = new HashSet<Long>(matchedUsers.size()); @@ -201,9 +200,9 @@ public class AuthenticationTestITCase ex } assertTrue(userIds.contains(1L)); - super.setupRestTemplate("user2", "password"); + UserService userService3 = setupCredentials(userService, "user2", "password"); - matchedUsers = userService.search(searchCondition); + matchedUsers = userService3.search(searchCondition); assertNotNull(matchedUsers); @@ -233,9 +232,9 @@ public class AuthenticationTestITCase ex userTO = createUser(userTO); assertNotNull(userTO); - super.setupRestTemplate(userTO.getUsername(), "password123"); + UserService userService2 = setupCredentials(userService, userTO.getUsername(), "password123"); - UserTO readUserTO = userService.read(userTO.getId()); + UserTO readUserTO = userService2.read(userTO.getId()); assertNotNull(readUserTO); assertNotNull(readUserTO.getFailedLogins()); @@ -243,12 +242,12 @@ public class AuthenticationTestITCase ex // authentications failed ... - super.setupRestTemplate(userTO.getUsername(), "wrongpwd1"); + UserService userService3 = setupCredentials(userService, userTO.getUsername(), "wrongpwd1"); Throwable t = null; try { - userService.read(userTO.getId()); + userService3.read(userTO.getId()); assertNotNull(readUserTO); } catch (Exception e) { t = e; @@ -258,7 +257,7 @@ public class AuthenticationTestITCase ex t = null; try { - userService.read(userTO.getId()); + userService3.read(userTO.getId()); assertNotNull(readUserTO); } catch (Exception e) { t = e; @@ -272,9 +271,9 @@ public class AuthenticationTestITCase ex assertNotNull(readUserTO.getFailedLogins()); assertEquals(Integer.valueOf(2), readUserTO.getFailedLogins()); - super.setupRestTemplate(userTO.getUsername(), "password123"); + UserService userService4 = setupCredentials(userService, userTO.getUsername(), "password123"); - readUserTO = userService.read(userTO.getId()); + readUserTO = userService4.read(userTO.getId()); assertNotNull(readUserTO); assertNotNull(readUserTO.getFailedLogins()); assertEquals(Integer.valueOf(0), readUserTO.getFailedLogins()); @@ -295,9 +294,9 @@ public class AuthenticationTestITCase ex userTO = createUser(userTO); assertNotNull(userTO); - super.setupRestTemplate(userTO.getUsername(), "password123"); + UserService userService2 = setupCredentials(userService, userTO.getUsername(), "password123"); - userTO = userService.read(userTO.getId()); + userTO = userService2.read(userTO.getId()); assertNotNull(userTO); assertNotNull(userTO.getFailedLogins()); @@ -305,12 +304,12 @@ public class AuthenticationTestITCase ex // authentications failed ... - super.setupRestTemplate(userTO.getUsername(), "wrongpwd1"); + UserService userService3 = setupCredentials(userService, userTO.getUsername(), "wrongpwd1"); Throwable t = null; try { - userService.read(userTO.getId()); + userService3.read(userTO.getId()); fail(); } catch (Exception e) { t = e; @@ -320,7 +319,7 @@ public class AuthenticationTestITCase ex t = null; try { - userService.read(userTO.getId()); + userService3.read(userTO.getId()); } catch (Exception e) { t = e; } @@ -329,7 +328,7 @@ public class AuthenticationTestITCase ex t = null; try { - userService.read(userTO.getId()); + userService3.read(userTO.getId()); } catch (Exception e) { t = e; } @@ -347,10 +346,11 @@ public class AuthenticationTestITCase ex assertEquals(Integer.valueOf(3), userTO.getFailedLogins()); // last authentication before suspension - super.setupRestTemplate(userTO.getUsername(), "wrongpwd1"); + // TODO remove after CXF migration is complete + userService3 = setupCredentials(userService, userTO.getUsername(), "wrongpwd1"); try { - userService.read(userTO.getId()); + userService3.read(userTO.getId()); } catch (Exception e) { t = e; } @@ -369,11 +369,11 @@ public class AuthenticationTestITCase ex assertEquals("suspended", userTO.getStatus()); // check for authentication - - super.setupRestTemplate(userTO.getUsername(), "password123"); + // TODO remove after CXF migration is complete + userService2 = setupCredentials(userService, userTO.getUsername(), "password123"); try { - userService.read(userTO.getId()); + userService2.read(userTO.getId()); assertNotNull(userTO); } catch (Exception e) { t = e; @@ -390,9 +390,10 @@ public class AuthenticationTestITCase ex assertNotNull(userTO); assertEquals("active", userTO.getStatus()); - super.setupRestTemplate(userTO.getUsername(), "password123"); + // TODO remove after CXF migration is complete + userService2 = setupCredentials(userService, userTO.getUsername(), "password123"); - userTO = userService.read(userTO.getId()); + userTO = userService2.read(userTO.getId()); assertNotNull(userTO); assertEquals(Integer.valueOf(0), userTO.getFailedLogins()); @@ -430,7 +431,7 @@ public class AuthenticationTestITCase ex role1Admin = createUser(role1Admin); assertNotNull(role1Admin); - super.setupRestTemplate(role1Admin.getUsername(), "password"); + UserService userService2 = setupCredentials(userService, role1Admin.getUsername(), "password"); // User with role 1, created by user with child role created above UserTO role1User = UserTestITCase.getUniqueSampleTO("syncope48u...@apache.org"); @@ -438,10 +439,9 @@ public class AuthenticationTestITCase ex membershipTO.setRoleId(1L); role1User.addMembership(membershipTO); - role1User = createUser(role1User); + response = userService2.create(role1User); + assertNotNull(response); + role1User = response.readEntity(UserTO.class); assertNotNull(role1User); - - // reset admin credentials for restTemplate - super.resetRestTemplate(); } } Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java?rev=1440323&r1=1440322&r2=1440323&view=diff ============================================================================== --- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java (original) +++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java Wed Jan 30 09:55:40 2013 @@ -31,6 +31,7 @@ import java.util.List; import javax.ws.rs.core.Response; import org.apache.syncope.common.mod.RoleMod; +import org.apache.syncope.common.services.RoleService; import org.apache.syncope.common.to.ConnObjectTO; import org.apache.syncope.common.to.RoleTO; import org.apache.syncope.common.to.UserTO; @@ -196,24 +197,21 @@ public class RoleTestITCase extends Abst assertTrue(userTO.getMembershipMap().containsKey(1L)); assertFalse(userTO.getMembershipMap().containsKey(3L)); - super.setupRestTemplate("user1", "password"); + RoleService roleService2 = setupCredentials(roleService, "user1", ADMIN_PWD); SyncopeClientException exception = null; try { - roleService.selfRead(3L); + roleService2.selfRead(3L); fail(); } catch (SyncopeClientCompositeErrorException e) { exception = e.getException(SyncopeClientExceptionType.UnauthorizedRole); } assertNotNull(exception); - RoleTO roleTO = roleService.selfRead(1L); + RoleTO roleTO = roleService2.selfRead(1L); assertNotNull(roleTO); assertNotNull(roleTO.getAttributes()); assertFalse(roleTO.getAttributes().isEmpty()); - - // restore admin authentication - super.resetRestTemplate(); } @Test @@ -305,10 +303,10 @@ public class RoleTestITCase extends Abst roleMod.setName("Managing Director"); // 3. try to update as user3, not owner of role 7 - fail - setupRestTemplate("user2", "password"); + RoleService roleService2 = setupCredentials(roleService, "user2", ADMIN_PWD); try { - roleService.update(roleMod.getId(), roleMod); + roleService2.update(roleMod.getId(), roleMod); fail(); } catch (HttpStatusCodeException e) { assertEquals(HttpStatus.FORBIDDEN, e.getStatusCode()); @@ -316,13 +314,10 @@ public class RoleTestITCase extends Abst // 4. update as user5, owner of role 7 because owner of role 6 with // inheritance - success - super.setupRestTemplate("user5", ADMIN_PWD); + RoleService roleService3 = setupCredentials(roleService, "user5", ADMIN_PWD); - roleTO = roleService.update(roleMod.getId(), roleMod); + roleTO = roleService3.update(roleMod.getId(), roleMod); assertEquals("Managing Director", roleTO.getName()); - - // restore admin authentication - super.resetRestTemplate(); } /** Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java?rev=1440323&r1=1440322&r2=1440323&view=diff ============================================================================== --- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java (original) +++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserRequestTestITCase.java Wed Jan 30 09:55:40 2013 @@ -31,12 +31,12 @@ import javax.ws.rs.core.Response; import org.apache.syncope.common.mod.UserMod; import org.apache.syncope.common.search.AttributeCond; import org.apache.syncope.common.search.NodeCond; +import org.apache.syncope.common.services.UserRequestService; import org.apache.syncope.common.to.ConfigurationTO; import org.apache.syncope.common.to.UserRequestTO; import org.apache.syncope.common.to.UserTO; import org.apache.syncope.common.types.SyncopeClientExceptionType; import org.apache.syncope.common.validation.SyncopeClientCompositeErrorException; -import org.apache.syncope.common.validation.SyncopeClientException; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; @@ -62,14 +62,12 @@ public class UserRequestTestITCase exten UserTO userTO = UserTestITCase.getUniqueSampleTO("selfcre...@syncope.apache.org"); // 2. get unauthorized when trying to request user create - SyncopeClientException exception = null; try { createUserRequest(new UserRequestTO(userTO)); fail(); } catch (SyncopeClientCompositeErrorException e) { - exception = e.getException(SyncopeClientExceptionType.UnauthorizedRole); + assertNotNull(e.getException(SyncopeClientExceptionType.UnauthorizedRole)); } - assertNotNull(exception); // 3. set create request allowed configurationTO.setValue("true"); @@ -81,12 +79,12 @@ public class UserRequestTestITCase exten assertNotNull(configurationTO); // 4. as anonymous, request user create works - UserRequestTO request = anonymousRestTemplate().postForObject(BASE_URL + "user/request/create", - userTO, UserRequestTO.class); - assertNotNull(request); + UserRequestService userRequestService2 = setupCredentials(userRequestService, null, null); + response = userRequestService2.create(new UserRequestTO(userTO)); + UserRequestTO request = getObject(response, UserRequestTO.class, userRequestService2); // 5. switch back to admin - super.resetRestTemplate(); + super.resetRestTemplate(); // TODO remove after CXF migration is complete // 6. try to find user AttributeCond attrCond = new AttributeCond(AttributeCond.Type.EQ); @@ -115,26 +113,27 @@ public class UserRequestTestITCase exten userMod.setPassword(initialPassword); // 2. try to request user update as admin: failure - SyncopeClientException exception = null; try { createUserRequest(new UserRequestTO(userMod)); fail(); } catch (SyncopeClientCompositeErrorException e) { - exception = e.getException(SyncopeClientExceptionType.UnauthorizedRole); + assertNotNull(e.getException(SyncopeClientExceptionType.UnauthorizedRole)); } - assertNotNull(exception); // 3. auth as user just created - super.setupRestTemplate(userTO.getUsername(), initialPassword); + UserRequestService userRequestService2 = setupCredentials(userRequestService, userTO.getUsername(), + initialPassword); // 4. update with same password: not matching password policy - exception = null; try { - createUserRequest(new UserRequestTO(userMod)); + Response response = userRequestService2.create(new UserRequestTO(userMod)); + if (response.getStatus() != org.apache.http.HttpStatus.SC_CREATED) { + throw (RuntimeException) clientExceptionMapper.fromResponse(response); + } + fail(); } catch (SyncopeClientCompositeErrorException scce) { - exception = scce.getException(SyncopeClientExceptionType.InvalidSyncopeUser); + assertNotNull(scce.getException(SyncopeClientExceptionType.InvalidSyncopeUser)); } - assertNotNull(exception); // 5. now request user update works userMod.setPassword("new" + initialPassword); @@ -167,20 +166,21 @@ public class UserRequestTestITCase exten assertNotNull(userTO); // 2. try to request user delete as admin: failure - SyncopeClientException exception = null; try { createUserRequest(new UserRequestTO(userTO.getId())); fail(); } catch (SyncopeClientCompositeErrorException e) { - exception = e.getException(SyncopeClientExceptionType.UnauthorizedRole); + assertNotNull(e.getException(SyncopeClientExceptionType.UnauthorizedRole)); } - assertNotNull(exception); // 3. auth as user just created - super.setupRestTemplate(userTO.getUsername(), initialPassword); + UserRequestService userRequestService2 = setupCredentials(userRequestService, userTO.getUsername(), + initialPassword); // 4. now request user delete works - createUserRequest(new UserRequestTO(userTO.getId())); + Response response = userRequestService2.create(new UserRequestTO(userTO.getId())); + assertNotNull(response); + assertEquals(org.apache.http.HttpStatus.SC_CREATED, response.getStatus()); // 5. switch back to admin super.resetRestTemplate(); @@ -201,11 +201,11 @@ public class UserRequestTestITCase exten } } - private Long createUserRequest(UserRequestTO userRequestTO) throws RuntimeException { + private UserRequestTO createUserRequest(final UserRequestTO userRequestTO) { Response response = userRequestService.create(userRequestTO); if (response.getStatus() != org.apache.http.HttpStatus.SC_CREATED) { - throw (RuntimeException)clientExceptionMapper.fromResponse(response); + throw (RuntimeException) clientExceptionMapper.fromResponse(response); } - return (Long) response.readEntity(Long.class); + return getObject(response, UserRequestTO.class, userRequestService); } } Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java?rev=1440323&r1=1440322&r2=1440323&view=diff ============================================================================== --- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java (original) +++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/UserTestITCase.java Wed Jan 30 09:55:40 2013 @@ -38,6 +38,7 @@ import javax.ws.rs.core.Response; import org.apache.syncope.common.mod.AttributeMod; import org.apache.syncope.common.mod.MembershipMod; import org.apache.syncope.common.mod.UserMod; +import org.apache.syncope.common.services.UserService; import org.apache.syncope.common.to.AttributeTO; import org.apache.syncope.common.to.ConfigurationTO; import org.apache.syncope.common.to.ConnObjectTO; @@ -106,16 +107,16 @@ public class UserTestITCase extends Abst @Test public void selfRead() { - super.setupRestTemplate("user1", ADMIN_PWD); + UserService userService2 = setupCredentials(userService, "user1", ADMIN_PWD); try { - userService.read(1L); + userService2.read(1L); fail(); } catch (HttpClientErrorException e) { assertEquals(HttpStatus.FORBIDDEN, e.getStatusCode()); } - UserTO userTO = userService.readSelf(); + UserTO userTO = userService2.readSelf(); assertEquals("user1", userTO.getUsername()); } @@ -585,20 +586,19 @@ public class UserTestITCase extends Abst assertNull(form.getOwner()); // 3. claim task from user1, not in role 7 (designated for approval in workflow definition): fail - super.setupRestTemplate("user1", ADMIN_PWD); + UserService userService2 = setupCredentials(userService, "user1", ADMIN_PWD); - SyncopeClientException sce = null; try { - userService.claimForm(form.getTaskId()); + userService2.claimForm(form.getTaskId()); + fail(); } catch (SyncopeClientCompositeErrorException scce) { - sce = scce.getException(SyncopeClientExceptionType.Workflow); + assertNotNull(scce.getException(SyncopeClientExceptionType.Workflow)); } - assertNotNull(sce); // 4. claim task from user4, in role 7 - super.setupRestTemplate("user4", ADMIN_PWD); + UserService userService3 = setupCredentials(userService, "user4", ADMIN_PWD); - form = userService.claimForm(form.getTaskId()); + form = userService3.claimForm(form.getTaskId()); assertNotNull(form); assertNotNull(form.getTaskId()); assertNotNull(form.getOwner()); @@ -608,7 +608,7 @@ public class UserTestITCase extends Abst props.get("approve").setValue(Boolean.FALSE.toString()); props.get("rejectReason").setValue("I don't like him."); form.setProperties(props.values()); - userTO = userService.submitForm(form); + userTO = userService3.submitForm(form); assertNotNull(userTO); assertEquals("rejected", userTO.getStatus()); @@ -1931,7 +1931,7 @@ public class UserTestITCase extends Abst assertNotNull(userTO.getPropagationStatusTOs()); assertEquals(1, userTO.getPropagationStatusTOs().size()); assertEquals("resource-testdb", userTO.getPropagationStatusTOs().iterator().next().getResource()); - + // 3b. verify that password hasn't changed on Syncope assertEquals(pwdOnSyncope, userTO.getPassword());