syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbernha...@apache.org
Subject svn commit: r1423393 - in /syncope/branches/cxf: console/src/main/java/org/apache/syncope/console/commons/ console/src/main/java/org/apache/syncope/console/pages/ console/src/main/java/org/apache/syncope/console/pages/panels/ console/src/main/java/org/...
Date Tue, 18 Dec 2012 10:22:11 GMT
Author: jbernhardt
Date: Tue Dec 18 10:22:09 2012
New Revision: 1423393

URL: http://svn.apache.org/viewvc?rev=1423393&view=rev
Log:
[SYNCOPE-231] 
Updated Authentication Service
Update of REST Console client
Further improvements (bug fixes)

Removed:
    syncope/branches/cxf/core/src/test/java/org/apache/syncope/core/rest/CopyOfAuthenticationXmlTestITCase.java
Modified:
    syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/commons/UserDataProvider.java
    syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/pages/EditUserModalPage.java
    syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/pages/Login.java
    syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/pages/Todo.java
    syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/pages/UserRequestModalPage.java
    syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/pages/panels/ResultSetPanel.java
    syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/rest/EntitlementRestClient.java
    syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/rest/RoleRestClient.java
    syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/rest/UserRestClient.java
    syncope/branches/cxf/core/src/test/java/org/apache/syncope/core/rest/AbstractAuthenticationTestITCase.java
    syncope/branches/cxf/core/src/test/resources/restClientContext.xml

Modified: syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/commons/UserDataProvider.java
URL: http://svn.apache.org/viewvc/syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/commons/UserDataProvider.java?rev=1423393&r1=1423392&r2=1423393&view=diff
==============================================================================
--- syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/commons/UserDataProvider.java
(original)
+++ syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/commons/UserDataProvider.java
Tue Dec 18 10:22:09 2012
@@ -18,22 +18,32 @@
  */
 package org.apache.syncope.console.commons;
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
+
+import org.apache.syncope.console.rest.UserRestClient;
+import org.apache.syncope.exceptions.InvalidSearchConditionException;
+import org.apache.syncope.search.NodeCond;
+import org.apache.syncope.to.UserTO;
 import org.apache.wicket.extensions.markup.html.repeater.data.sort.SortOrder;
 import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
 import org.apache.wicket.model.CompoundPropertyModel;
 import org.apache.wicket.model.IModel;
-import org.apache.syncope.console.rest.UserRestClient;
-import org.apache.syncope.search.NodeCond;
-import org.apache.syncope.to.UserTO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class UserDataProvider extends SortableDataProvider<UserTO> {
 
     private static final long serialVersionUID = 6267494272884913376L;
 
-    private SortableUserProviderComparator comparator;
+    /**
+     * Logger.
+     */
+    protected static final Logger LOG = LoggerFactory.getLogger(UserDataProvider.class);
+
+    private final SortableUserProviderComparator comparator;
 
     private NodeCond filter = null;
 
@@ -41,7 +51,7 @@ public class UserDataProvider extends So
 
     private boolean filtered = false;
 
-    private UserRestClient restClient;
+    private final UserRestClient restClient;
 
     public UserDataProvider(final UserRestClient restClient, final int paginatorRows, final
boolean filtered) {
 
@@ -51,7 +61,7 @@ public class UserDataProvider extends So
         this.filtered = filtered;
         this.paginatorRows = paginatorRows;
 
-        //Default sorting
+        // Default sorting
         setSort("id", SortOrder.ASCENDING);
 
         comparator = new SortableUserProviderComparator(this);
@@ -63,12 +73,17 @@ public class UserDataProvider extends So
 
     @Override
     public Iterator<UserTO> iterator(final int first, final int count) {
-        final List<UserTO> users;
+        List<UserTO> users;
 
         if (filtered) {
-            users = filter == null
-                    ? Collections.EMPTY_LIST
-                    : restClient.search(filter, (first / paginatorRows) + 1, paginatorRows);
+            users = new ArrayList<UserTO>();
+            if (filter != null) {
+                try {
+                    users = restClient.search(filter, (first / paginatorRows) + 1, paginatorRows);
+                } catch (Exception e) {
+                    LOG.error("Could not search for user. \n {}", e.getMessage());
+                }
+            }
         } else {
             users = restClient.list((first / paginatorRows) + 1, paginatorRows);
         }
@@ -80,9 +95,14 @@ public class UserDataProvider extends So
     @Override
     public int size() {
         if (filtered) {
-            return filter == null
-                    ? 0
-                    : restClient.searchCount(filter);
+            try {
+                return filter == null
+                        ? 0
+                        : restClient.searchCount(filter);
+            } catch (InvalidSearchConditionException e) {
+                LOG.error("Could not search for user. \n {}", e.getMessage());
+                return 0;
+            }
         } else {
             return restClient.count();
         }

Modified: syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/pages/EditUserModalPage.java
URL: http://svn.apache.org/viewvc/syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/pages/EditUserModalPage.java?rev=1423393&r1=1423392&r2=1423393&view=diff
==============================================================================
--- syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/pages/EditUserModalPage.java
(original)
+++ syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/pages/EditUserModalPage.java
Tue Dec 18 10:22:09 2012
@@ -33,6 +33,8 @@ import org.apache.wicket.ajax.AjaxReques
 import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
 import org.apache.wicket.markup.html.form.Form;
 import org.apache.wicket.spring.injection.annot.SpringBean;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Modal window with User form.
@@ -42,6 +44,11 @@ public class EditUserModalPage extends U
     @SpringBean
     private UserRestClient userRestClient;
 
+    /**
+     * Logger.
+     */
+    protected static final Logger LOG = LoggerFactory.getLogger(EditUserModalPage.class);
+
     private UserTO initialUserTO = null;
 
     public EditUserModalPage(final PageReference callerPageRef, final ModalWindow window,
final UserTO userTO) {
@@ -72,13 +79,21 @@ public class EditUserModalPage extends U
         final UserTO updatedUserTO = (UserTO) form.getModelObject();
 
         if (updatedUserTO.getId() == 0) {
-            userTO = userRestClient.create(updatedUserTO);
+            try {
+                userTO = userRestClient.create(updatedUserTO);
+            } catch (Exception e) {
+                LOG.error("Could not update user. \n {}", e.getMessage());
+            }
         } else {
             final UserMod userMod = AttributableOperations.diff(updatedUserTO, initialUserTO);
 
             // update user just if it is changed
             if (!userMod.isEmpty()) {
-                userTO = userRestClient.update(userMod);
+                try {
+                    userTO = userRestClient.update(userMod);
+                } catch (Exception e) {
+                    LOG.error("Could not create User. \n {}", e.getMessage());
+                }
             }
         }
 

Modified: syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/pages/Login.java
URL: http://svn.apache.org/viewvc/syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/pages/Login.java?rev=1423393&r1=1423392&r2=1423393&view=diff
==============================================================================
--- syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/pages/Login.java
(original)
+++ syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/pages/Login.java
Tue Dec 18 10:22:09 2012
@@ -21,12 +21,21 @@ package org.apache.syncope.console.pages
 import java.util.Arrays;
 import java.util.List;
 import java.util.Locale;
+import java.util.Set;
+
+import org.apache.cxf.common.util.Base64Utility;
+import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
+import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.http.HttpResponse;
-import org.apache.http.auth.UsernamePasswordCredentials;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.http.util.EntityUtils;
 import org.apache.syncope.client.http.PreemptiveAuthHttpRequestFactory;
+import org.apache.syncope.console.SyncopeSession;
+import org.apache.syncope.console.wicket.markup.html.form.LinkPanel;
+import org.apache.syncope.services.AuthenticationService;
+import org.apache.syncope.to.EntitlementTO;
+import org.apache.syncope.to.UserTO;
 import org.apache.wicket.Page;
 import org.apache.wicket.ajax.AjaxRequestTarget;
 import org.apache.wicket.ajax.markup.html.AjaxLink;
@@ -50,11 +59,9 @@ import org.apache.wicket.request.mapper.
 import org.apache.wicket.spring.injection.annot.SpringBean;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.client.HttpClientErrorException;
 import org.springframework.web.client.RestTemplate;
-import org.apache.syncope.console.SyncopeSession;
-import org.apache.syncope.console.wicket.markup.html.form.LinkPanel;
-import org.apache.syncope.to.UserTO;
 
 /**
  * Syncope Login page.
@@ -66,6 +73,9 @@ public class Login extends WebPage {
      */
     private static final Logger LOG = LoggerFactory.getLogger(Login.class);
 
+    @Autowired
+    protected JAXRSClientFactoryBean restClientFactory;
+
     private static final long serialVersionUID = -3744389270366566218L;
 
     private final static int SELF_REG_WIN_HEIGHT = 550;
@@ -96,7 +106,8 @@ public class Login extends WebPage {
         passwordField.setMarkupId("password");
         form.add(passwordField);
 
-        languageSelect = new LocaleDropDown("language", Arrays.asList(new Locale[]{Locale.ENGLISH,
Locale.ITALIAN}));
+        languageSelect = new LocaleDropDown("language", Arrays.asList(new Locale[] { Locale.ENGLISH,
+                Locale.ITALIAN }));
 
         form.add(languageSelect);
 
@@ -107,7 +118,8 @@ public class Login extends WebPage {
             @Override
             public void onSubmit() {
                 try {
-                    String[] entitlements = authenticate(userIdField.getRawInput(), passwordField.getRawInput());
+                    String[] entitlements = authenticate(userIdField.getRawInput(),
+                            passwordField.getRawInput());
 
                     SyncopeSession.get().setUserId(userIdField.getRawInput());
                     SyncopeSession.get().setEntitlements(entitlements);
@@ -117,8 +129,8 @@ public class Login extends WebPage {
                 } catch (HttpClientErrorException e) {
                     error(getString("login-error"));
 
-                    PreemptiveAuthHttpRequestFactory requestFactory = ((PreemptiveAuthHttpRequestFactory)
SyncopeSession.
-                            get().getRestTemplate().getRequestFactory());
+                    PreemptiveAuthHttpRequestFactory requestFactory = ((PreemptiveAuthHttpRequestFactory)
SyncopeSession
+                            .get().getRestTemplate().getRequestFactory());
 
                     ((DefaultHttpClient) requestFactory.getHttpClient()).getCredentialsProvider().clear();
                 }
@@ -155,8 +167,8 @@ public class Login extends WebPage {
 
                         @Override
                         public Page createPage() {
-                            return new UserRequestModalPage(Login.this.getPageReference(),
editProfileModalWin,
-                                    new UserTO(), UserModalPage.Mode.SELF);
+                            return new UserRequestModalPage(Login.this.getPageReference(),
+                                    editProfileModalWin, new UserTO(), UserModalPage.Mode.SELF);
                         }
                     });
 
@@ -175,17 +187,27 @@ public class Login extends WebPage {
     }
 
     private String[] authenticate(final String userId, final String password) {
-        final RestTemplate restTemplate = SyncopeSession.get().getRestTemplate();
+        //final RestTemplate restTemplate = SyncopeSession.get().getRestTemplate();
 
         // 1. Set provided credentials to check
-        PreemptiveAuthHttpRequestFactory requestFactory =
-                ((PreemptiveAuthHttpRequestFactory) restTemplate.getRequestFactory());
-
-        ((DefaultHttpClient) requestFactory.getHttpClient()).getCredentialsProvider().setCredentials(
-                requestFactory.getAuthScope(), new UsernamePasswordCredentials(userId, password));
+        restClientFactory.setServiceClass(AuthenticationService.class);
+        AuthenticationService authService = restClientFactory.create(AuthenticationService.class);
+        WebClient.client(authService).type("application/json").accept("application/json");
+
+        String userCredentials = userId + ":" + password;
+        String authorizationHeader = "Basic " + Base64Utility.encode(userCredentials.getBytes());
+        WebClient.client(authService).header("Authorization", authorizationHeader);
 
         // 2. Search authorizations for user specified by credentials
-        return restTemplate.getForObject(baseURL + "auth/entitlements.json", String[].class);
+        Set<EntitlementTO> ents = authService.getMyEntitlements();
+        String[] result = new String[ents.size()];
+        int i = 0;
+        for (EntitlementTO e : ents) {
+            result[i] = e.getName();
+            i++;
+        }
+
+        return result;
     }
 
     private boolean isSelfRegistrationAllowed() {
@@ -205,8 +227,8 @@ public class Login extends WebPage {
     private String getCoreVersion() {
         final RestTemplate restTemplate = SyncopeSession.get().getRestTemplate();
 
-        PreemptiveAuthHttpRequestFactory requestFactory = ((PreemptiveAuthHttpRequestFactory)
restTemplate.
-                getRequestFactory());
+        PreemptiveAuthHttpRequestFactory requestFactory = ((PreemptiveAuthHttpRequestFactory)
restTemplate
+                .getRequestFactory());
 
         String version = "";
         try {

Modified: syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/pages/Todo.java
URL: http://svn.apache.org/viewvc/syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/pages/Todo.java?rev=1423393&r1=1423392&r2=1423393&view=diff
==============================================================================
--- syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/pages/Todo.java
(original)
+++ syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/pages/Todo.java
Tue Dec 18 10:22:09 2012
@@ -281,7 +281,7 @@ public class Todo extends BasePage {
                         try {
                             userRestClient.delete(model.getObject().getUserId());
                             userRequestRestClient.delete(model.getObject().getId());
-                        } catch (SyncopeClientCompositeErrorException e) {
+                        } catch (Exception e) {
                             LOG.error("While deleting an user", e);
                             error(e.getMessage());
                             return;
@@ -365,7 +365,7 @@ public class Todo extends BasePage {
 
         private static final long serialVersionUID = -2311716167583335852L;
 
-        private SortableDataProviderComparator<WorkflowFormTO> comparator;
+        private final SortableDataProviderComparator<WorkflowFormTO> comparator;
 
         public ApprovalProvider() {
             //Default sorting
@@ -407,7 +407,7 @@ public class Todo extends BasePage {
 
         private static final long serialVersionUID = -2311716167583335852L;
 
-        private SortableDataProviderComparator<UserRequestTO> comparator;
+        private final SortableDataProviderComparator<UserRequestTO> comparator;
 
         public UserRequestProvider() {
             //Default sorting

Modified: syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/pages/UserRequestModalPage.java
URL: http://svn.apache.org/viewvc/syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/pages/UserRequestModalPage.java?rev=1423393&r1=1423392&r2=1423393&view=diff
==============================================================================
--- syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/pages/UserRequestModalPage.java
(original)
+++ syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/pages/UserRequestModalPage.java
Tue Dec 18 10:22:09 2012
@@ -47,8 +47,8 @@ public class UserRequestModalPage extend
 
     private UserRequestTO userRequestTO;
 
-    public UserRequestModalPage(final PageReference callerPageRef, final ModalWindow window,
final UserTO userTO,
-            final Mode mode) {
+    public UserRequestModalPage(final PageReference callerPageRef, final ModalWindow window,
+            final UserTO userTO, final Mode mode) {
 
         super(callerPageRef, window, userTO, mode, false);
 
@@ -61,19 +61,19 @@ public class UserRequestModalPage extend
         super(callerPageRef, window, null, mode, false);
 
         switch (userRequestTO.getType()) {
-            case CREATE:
-                userTO = userRequestTO.getUserTO();
-                this.initialUserTO = AttributableOperations.clone(userTO);
-                break;
+        case CREATE:
+            userTO = userRequestTO.getUserTO();
+            this.initialUserTO = AttributableOperations.clone(userTO);
+            break;
 
-            case UPDATE:
-                this.initialUserTO = userRestClient.read(userRequestTO.getUserMod().getId());
+        case UPDATE:
+            this.initialUserTO = userRestClient.read(userRequestTO.getUserMod().getId());
 
-                userTO = AttributableOperations.apply(initialUserTO, userRequestTO.getUserMod());
-                break;
+            userTO = AttributableOperations.apply(initialUserTO, userRequestTO.getUserMod());
+            break;
 
-            case DELETE:
-            default:
+        case DELETE:
+        default:
         }
 
         this.userRequestTO = userRequestTO;
@@ -92,19 +92,23 @@ public class UserRequestModalPage extend
 
         if (updatedUserTO.getId() == 0) {
             switch (mode) {
-                case SELF:
-                    requestRestClient.requestCreate(updatedUserTO);
-                    break;
+            case SELF:
+                requestRestClient.requestCreate(updatedUserTO);
+                break;
 
-                case ADMIN:
+            case ADMIN:
+                try {
                     userRestClient.create(updatedUserTO);
-                    if (userRequestTO != null) {
-                        requestRestClient.delete(userRequestTO.getId());
-                    }
-                    break;
+                } catch (Exception e) {
+                    LOG.error("Could not create User. \n {}", e.getMessage());
+                }
+                if (userRequestTO != null) {
+                    requestRestClient.delete(userRequestTO.getId());
+                }
+                break;
 
-                default:
-                    LOG.warn("Invalid mode specified for {}: {}", getClass().getName(), mode);
+            default:
+                LOG.warn("Invalid mode specified for {}: {}", getClass().getName(), mode);
             }
         } else {
             final UserMod userMod = AttributableOperations.diff(updatedUserTO,
@@ -113,19 +117,23 @@ public class UserRequestModalPage extend
             // update user only if it has changed
             if (!userMod.isEmpty()) {
                 switch (mode) {
-                    case SELF:
-                        requestRestClient.requestUpdate(userMod);
-                        break;
-
-                    case ADMIN:
-                        userRestClient.update(userMod);
-                        if (userRequestTO != null) {
-                            requestRestClient.delete(userRequestTO.getId());
-                        }
-                        break;
+                case SELF:
+                    requestRestClient.requestUpdate(userMod);
+                    break;
+
+                case ADMIN:
+                    try {
+                    userRestClient.update(userMod);
+                    } catch (Exception e) {
+                        LOG.error("Could not update user. \n {}", e.getMessage());
+                    }
+                    if (userRequestTO != null) {
+                        requestRestClient.delete(userRequestTO.getId());
+                    }
+                    break;
 
-                    default:
-                        LOG.warn("Invalid mode specified for {}: {}", getClass().getName(),
mode);
+                default:
+                    LOG.warn("Invalid mode specified for {}: {}", getClass().getName(), mode);
                 }
             }
         }

Modified: syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/pages/panels/ResultSetPanel.java
URL: http://svn.apache.org/viewvc/syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/pages/panels/ResultSetPanel.java?rev=1423393&r1=1423392&r2=1423393&view=diff
==============================================================================
--- syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/pages/panels/ResultSetPanel.java
(original)
+++ syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/pages/panels/ResultSetPanel.java
Tue Dec 18 10:22:09 2012
@@ -22,6 +22,7 @@ import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+
 import org.apache.syncope.console.commons.Constants;
 import org.apache.syncope.console.commons.PreferenceManager;
 import org.apache.syncope.console.commons.UserDataProvider;
@@ -39,7 +40,6 @@ import org.apache.syncope.console.wicket
 import org.apache.syncope.search.NodeCond;
 import org.apache.syncope.to.AbstractAttributableTO;
 import org.apache.syncope.to.UserTO;
-import org.apache.syncope.validation.SyncopeClientCompositeErrorException;
 import org.apache.wicket.Component;
 import org.apache.wicket.Page;
 import org.apache.wicket.PageReference;
@@ -498,7 +498,7 @@ public class ResultSetPanel extends Pane
 
                             editmodal.show(target);
 
-                        } catch (SyncopeClientCompositeErrorException scce) {
+                        } catch (Exception scce) {
                             error(getString("operation_error") + ": " + scce.getMessage());
                             target.add(feedbackPanel);
                         }

Modified: syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/rest/EntitlementRestClient.java
URL: http://svn.apache.org/viewvc/syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/rest/EntitlementRestClient.java?rev=1423393&r1=1423392&r2=1423393&view=diff
==============================================================================
--- syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/rest/EntitlementRestClient.java
(original)
+++ syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/rest/EntitlementRestClient.java
Tue Dec 18 10:22:09 2012
@@ -18,11 +18,14 @@
  */
 package org.apache.syncope.console.rest;
 
-import java.util.Arrays;
+import java.util.ArrayList;
 import java.util.List;
-import org.springframework.stereotype.Component;
-import org.apache.syncope.console.SyncopeSession;
+import java.util.Set;
+
+import org.apache.syncope.services.AuthenticationService;
+import org.apache.syncope.to.EntitlementTO;
 import org.apache.syncope.validation.SyncopeClientCompositeErrorException;
+import org.springframework.stereotype.Component;
 
 /**
  * Console client for invoking Rest Resources services.
@@ -30,21 +33,30 @@ import org.apache.syncope.validation.Syn
 @Component
 public class EntitlementRestClient extends AbstractBaseRestClient {
 
+    private final AuthenticationService as = super.getRestService(AuthenticationService.class);
+
     /**
      * Get all Entitlements.
      *
      * @return List<String>
      */
     public List<String> getAllEntitlements() {
-        List<String> entitlements = null;
+        Set<EntitlementTO> entitlements = null;
+        List<String> result = new ArrayList<String>();
 
         try {
-            entitlements = Arrays.asList(SyncopeSession.get().getRestTemplate().getForObject(
-                    baseURL + "auth/allentitlements.json", String[].class));
+            // entitlements =
+            // Arrays.asList(SyncopeSession.get().getRestTemplate().getForObject(
+            // baseURL + "auth/allentitlements.json", String[].class));
+            entitlements = as.getAllEntitlements();
+            for (EntitlementTO e : entitlements) {
+                result.add(e.getName());
+            }
+
         } catch (SyncopeClientCompositeErrorException e) {
             LOG.error("While reading all the entitlements", e);
         }
 
-        return entitlements;
+        return result;
     }
 }

Modified: syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/rest/RoleRestClient.java
URL: http://svn.apache.org/viewvc/syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/rest/RoleRestClient.java?rev=1423393&r1=1423392&r2=1423393&view=diff
==============================================================================
--- syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/rest/RoleRestClient.java
(original)
+++ syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/rest/RoleRestClient.java
Tue Dec 18 10:22:09 2012
@@ -21,9 +21,9 @@ package org.apache.syncope.console.rest;
 import java.util.List;
 
 import org.apache.syncope.NotFoundException;
+import org.apache.syncope.exceptions.UnauthorizedRoleException;
 import org.apache.syncope.mod.RoleMod;
 import org.apache.syncope.services.RoleService;
-import org.apache.syncope.services.UnauthorizedRoleException;
 import org.apache.syncope.to.RoleTO;
 import org.apache.syncope.validation.SyncopeClientCompositeErrorException;
 import org.springframework.stereotype.Component;
@@ -34,11 +34,11 @@ import org.springframework.stereotype.Co
 @Component
 public class RoleRestClient extends AbstractBaseRestClient {
 
-	private RoleService rs = super.getRestService(RoleService.class);
+	private final RoleService rs = super.getRestService(RoleService.class);
 
 	/**
 	 * Get all Roles.
-	 * 
+	 *
 	 * @return SchemaTOs
 	 */
 	public List<RoleTO> getAllRoles()

Modified: syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/rest/UserRestClient.java
URL: http://svn.apache.org/viewvc/syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/rest/UserRestClient.java?rev=1423393&r1=1423392&r2=1423393&view=diff
==============================================================================
--- syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/rest/UserRestClient.java
(original)
+++ syncope/branches/cxf/console/src/main/java/org/apache/syncope/console/rest/UserRestClient.java
Tue Dec 18 10:22:09 2012
@@ -28,18 +28,19 @@ import javax.ws.rs.MessageProcessingExce
 import org.apache.syncope.NotFoundException;
 import org.apache.syncope.console.SyncopeSession;
 import org.apache.syncope.console.commons.StatusBean;
+import org.apache.syncope.exceptions.InvalidSearchConditionException;
+import org.apache.syncope.exceptions.UnauthorizedRoleException;
 import org.apache.syncope.mod.StatusMod;
 import org.apache.syncope.mod.StatusMod.Status;
 import org.apache.syncope.mod.UserMod;
 import org.apache.syncope.propagation.PropagationException;
 import org.apache.syncope.search.NodeCond;
-import org.apache.syncope.services.InvalidSearchConditionException;
-import org.apache.syncope.services.UnauthorizedRoleException;
 import org.apache.syncope.services.UserService;
 import org.apache.syncope.to.ConnObjectTO;
 import org.apache.syncope.to.UserTO;
 import org.apache.syncope.validation.SyncopeClientCompositeErrorException;
 import org.apache.syncope.workflow.WorkflowException;
+import org.springframework.http.HttpStatus;
 import org.springframework.stereotype.Component;
 
 /**
@@ -49,7 +50,7 @@ import org.springframework.stereotype.Co
 public class UserRestClient extends AbstractBaseRestClient {
 
 	UserService us = super.getRestService(UserService.class);
-	
+
     public Integer count() {
         //return SyncopeSession.get().getRestTemplate().getForObject(baseURL + "user/count.json",
Integer.class);
     	return us.count();
@@ -76,14 +77,14 @@ public class UserRestClient extends Abst
     }
 
     public UserTO update(UserMod userModTO)
-            throws SyncopeClientCompositeErrorException, NotFoundException, PropagationException
{
+            throws SyncopeClientCompositeErrorException, NotFoundException, PropagationException,
UnauthorizedRoleException, WorkflowException {
 
         //return SyncopeSession.get().getRestTemplate().postForObject(baseURL + "user/update",
userModTO, UserTO.class);
     	return us.update(userModTO.getId(), userModTO);
     }
 
     public UserTO delete(Long id)
-            throws SyncopeClientCompositeErrorException, NotFoundException, PropagationException
{
+            throws SyncopeClientCompositeErrorException, WorkflowException, UnauthorizedRoleException,
NotFoundException, PropagationException {
 
         //return SyncopeSession.get().getRestTemplate().getForObject(baseURL + "user/delete/{userId}",
UserTO.class, id);
     	UserTO returnValue = read(id);
@@ -162,7 +163,7 @@ public class UserRestClient extends Abst
 
         boolean performLocal = false;
         Set<String> resources = new HashSet<String>();
-        
+
         for (StatusBean status : statuses) {
             if ((enable && !status.getStatus().isActive()) || (!enable &&
status.getStatus().isActive())) {
 

Modified: syncope/branches/cxf/core/src/test/java/org/apache/syncope/core/rest/AbstractAuthenticationTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/branches/cxf/core/src/test/java/org/apache/syncope/core/rest/AbstractAuthenticationTestITCase.java?rev=1423393&r1=1423392&r2=1423393&view=diff
==============================================================================
--- syncope/branches/cxf/core/src/test/java/org/apache/syncope/core/rest/AbstractAuthenticationTestITCase.java
(original)
+++ syncope/branches/cxf/core/src/test/java/org/apache/syncope/core/rest/AbstractAuthenticationTestITCase.java
Tue Dec 18 10:22:09 2012
@@ -33,6 +33,8 @@ import javax.ws.rs.core.Response;
 import org.apache.syncope.NotFoundException;
 import org.apache.syncope.exceptions.InvalidSearchConditionException;
 import org.apache.syncope.exceptions.UnauthorizedRoleException;
+import org.apache.syncope.mod.StatusMod;
+import org.apache.syncope.mod.StatusMod.Status;
 import org.apache.syncope.propagation.PropagationException;
 import org.apache.syncope.search.AttributeCond;
 import org.apache.syncope.search.NodeCond;
@@ -75,7 +77,8 @@ public abstract class AbstractAuthentica
     }
 
     @Test
-    public void testUserSchemaAuthorization() throws UnauthorizedRoleException, PropagationException,
WorkflowException, NotFoundException {
+    public void testUserSchemaAuthorization() throws UnauthorizedRoleException, PropagationException,
+            WorkflowException, NotFoundException {
         // 0. create a role that can only read schemas
         RoleTO authRoleTO = new RoleTO();
         authRoleTO.setName("authRole");
@@ -91,7 +94,8 @@ public abstract class AbstractAuthentica
         schemaTO.setMandatoryCondition("false");
         schemaTO.setType(SchemaType.String);
 
-        SchemaTO newSchemaTO = restTemplate.postForObject(BASE_URL + "schema/user/create",
schemaTO, SchemaTO.class);
+        SchemaTO newSchemaTO = restTemplate.postForObject(BASE_URL + "schema/user/create",
schemaTO,
+                SchemaTO.class);
         assertEquals(schemaTO, newSchemaTO);
 
         // 2. create an user with the role created above (as admin)
@@ -109,13 +113,15 @@ public abstract class AbstractAuthentica
         userTO = resolve(UserTO.class, r, us);
 
         // 3. read the schema created above (as admin) - success
-        schemaTO = restTemplate.getForObject(BASE_URL + "schema/user/read/authTestSchema.json",
SchemaTO.class);
+        schemaTO = restTemplate.getForObject(BASE_URL + "schema/user/read/authTestSchema.json",
+                SchemaTO.class);
         assertNotNull(schemaTO);
 
         // 4. read the schema created above (as user) - success
         super.setupRestTemplate(userTO.getUsername(), "password123");
 
-        schemaTO = restTemplate.getForObject(BASE_URL + "schema/user/read/authTestSchema.json",
SchemaTO.class);
+        schemaTO = restTemplate.getForObject(BASE_URL + "schema/user/read/authTestSchema.json",
+                SchemaTO.class);
         assertNotNull(schemaTO);
 
         // 5. update the schema create above (as user) - failure
@@ -139,7 +145,8 @@ public abstract class AbstractAuthentica
     }
 
     @Test
-    public void testUserRead() throws UnauthorizedRoleException, PropagationException, WorkflowException,
NotFoundException {
+    public void testUserRead() throws UnauthorizedRoleException, PropagationException, WorkflowException,
+            NotFoundException {
         UserTO userTO = AbstractUserTestITCase.getSampleTO();
 
         MembershipTO membershipTO = new MembershipTO();
@@ -174,7 +181,8 @@ public abstract class AbstractAuthentica
     }
 
     @Test
-    public void testUserSearch() throws UnauthorizedRoleException, PropagationException,
WorkflowException, NotFoundException, InvalidSearchConditionException {
+    public void testUserSearch() throws UnauthorizedRoleException, PropagationException,
WorkflowException,
+            NotFoundException, InvalidSearchConditionException {
         UserTO userTO = AbstractUserTestITCase.getSampleTO();
 
         MembershipTO membershipTO = new MembershipTO();
@@ -224,7 +232,8 @@ public abstract class AbstractAuthentica
     }
 
     @Test
-    public void checkFailedLogins() throws UnauthorizedRoleException, PropagationException,
WorkflowException, NotFoundException {
+    public void checkFailedLogins() throws UnauthorizedRoleException, PropagationException,
+            WorkflowException, NotFoundException {
         UserTO userTO = AbstractUserTestITCase.getSampleTO();
 
         MembershipTO membershipTO = new MembershipTO();
@@ -249,41 +258,42 @@ public abstract class AbstractAuthentica
         assertEquals(Integer.valueOf(0), readUserTO.getFailedLogins());
 
         // authentications failed ...
-
         super.setupRestTemplate(userTO.getUsername(), "wrongpwd1");
         UserService us2 = createServiceInstance(UserService.class, userTO.getUsername(),
"wrongpwd1", us);
 
-
         try {
             readUserTO = us2.read(userTO.getId());
             fail();
-        } catch (Exception e) {
            assertNotNull(e);
+        } catch (Exception e) {
+            assertNotNull(e);
         }
-
+        // Try twice
         try {
-            restTemplate.getForObject(BASE_URL + "user/read/{userId}.json", UserTO.class,
userTO.getId());
-           assertNotNull(readUserTO);;
-        } catch (Exception e) {
            assertNotNull(e);;
+            readUserTO = us2.read(userTO.getId());
+            fail();
+        } catch (Exception e) {
+            assertNotNull(e);
         }
 
         // reset admin credentials for restTemplate
         super.resetRestTemplate();
 
-        readUserTO = restTemplate.getForObject(BASE_URL + "user/read/{userId}.json", UserTO.class,
userTO.getId());
+        readUserTO = us.read(userTO.getId());
         assertNotNull(readUserTO);
         assertNotNull(readUserTO.getFailedLogins());
         assertEquals(Integer.valueOf(2), readUserTO.getFailedLogins());
 
         super.setupRestTemplate(userTO.getUsername(), "password123");
 
-        readUserTO = restTemplate.getForObject(BASE_URL + "user/read/{userId}.json", UserTO.class,
userTO.getId());
+        readUserTO = us1.read(userTO.getId());
         assertNotNull(readUserTO);
         assertNotNull(readUserTO.getFailedLogins());
         assertEquals(Integer.valueOf(0), readUserTO.getFailedLogins());
     }
 
     @Test
-    public void checkUserSuspension() {
+    public void checkUserSuspension() throws UnauthorizedRoleException, WorkflowException,
+            PropagationException, NotFoundException {
         UserTO userTO = AbstractUserTestITCase.getSampleTO("checkSuspension@syncope.apache.org");
 
         MembershipTO membershipTO = new MembershipTO();
@@ -294,12 +304,14 @@ public abstract class AbstractAuthentica
         membershipTO.addAttribute(testAttributeTO);
         userTO.addMembership(membershipTO);
 
-        userTO = restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);
+        Response r = us.create(userTO);
+        userTO = resolve(UserTO.class, r, us);
         assertNotNull(userTO);
 
         super.setupRestTemplate(userTO.getUsername(), "password123");
+        UserService us1 = createServiceInstance(UserService.class, userTO.getUsername(),
"password123", us);
 
-        userTO = restTemplate.getForObject(BASE_URL + "user/read/{userId}.json", UserTO.class,
userTO.getId());
+        userTO = us1.read(userTO.getId());
 
         assertNotNull(userTO);
         assertNotNull(userTO.getFailedLogins());
@@ -308,40 +320,32 @@ public abstract class AbstractAuthentica
         // authentications failed ...
 
         super.setupRestTemplate(userTO.getUsername(), "wrongpwd1");
-
-        Throwable t = null;
+        UserService us2 = createServiceInstance(UserService.class, userTO.getUsername(),
"wrongpwd1", us);
 
         try {
-            restTemplate.getForObject(BASE_URL + "user/read/{userId}.json", UserTO.class,
userTO.getId());
+            userTO = us2.read(userTO.getId());
+            fail();
         } catch (Exception e) {
-            t = e;
+            assertNotNull(e);
         }
 
-        assertNotNull(t);
-        t = null;
-
         try {
-            restTemplate.getForObject(BASE_URL + "user/read/{userId}.json", UserTO.class,
userTO.getId());
+            userTO = us2.read(userTO.getId());
+            fail();
         } catch (Exception e) {
-            t = e;
+            assertNotNull(e);
         }
-
-        assertNotNull(t);
-        t = null;
-
         try {
-            restTemplate.getForObject(BASE_URL + "user/read/{userId}.json", UserTO.class,
userTO.getId());
+            userTO = us2.read(userTO.getId());
+            fail();
         } catch (Exception e) {
-            t = e;
+            assertNotNull(e);
         }
 
-        assertNotNull(t);
-        t = null;
-
         // reset admin credentials for restTemplate
         super.resetRestTemplate();
 
-        userTO = restTemplate.getForObject(BASE_URL + "user/read/{userId}.json", UserTO.class,
userTO.getId());
+        userTO = us.read(userTO.getId());
 
         assertNotNull(userTO);
         assertNotNull(userTO.getFailedLogins());
@@ -351,18 +355,16 @@ public abstract class AbstractAuthentica
         super.setupRestTemplate(userTO.getUsername(), "wrongpwd1");
 
         try {
-            restTemplate.getForObject(BASE_URL + "user/read/{userId}.json", UserTO.class,
userTO.getId());
+            userTO = us2.read(userTO.getId());
+            fail();
         } catch (Exception e) {
-            t = e;
+            assertNotNull(e);
         }
 
-        assertNotNull(t);
-        t = null;
-
         // reset admin credentials for restTemplate
         super.resetRestTemplate();
 
-        userTO = restTemplate.getForObject(BASE_URL + "user/read/{userId}.json", UserTO.class,
userTO.getId());
+        userTO = us.read(userTO.getId());
 
         assertNotNull(userTO);
         assertNotNull(userTO.getFailedLogins());
@@ -370,37 +372,36 @@ public abstract class AbstractAuthentica
         assertEquals("suspended", userTO.getStatus());
 
         // check for authentication
-
         super.setupRestTemplate(userTO.getUsername(), "password123");
 
         try {
-            restTemplate.getForObject(BASE_URL + "user/read/{userId}.json", UserTO.class,
userTO.getId());
-            assertNotNull(userTO);
+            userTO = us1.read(userTO.getId());
+            fail("User should be suspended");
         } catch (Exception e) {
-            t = e;
+            assertNotNull(e);
         }
 
-        assertNotNull(t);
-        t = null;
-
         // reset admin credentials for restTemplate
         super.resetRestTemplate();
 
-        userTO = restTemplate.getForObject(BASE_URL + "user/reactivate/" + userTO.getId(),
UserTO.class);
+        StatusMod status = new StatusMod(userTO.getId(), Status.REACTIVATE);
+        userTO = us.setStatus(userTO.getId(), status);
+        //userTO = restTemplate.getForObject(BASE_URL + "user/reactivate/" + userTO.getId(),
UserTO.class);
 
         assertNotNull(userTO);
         assertEquals("active", userTO.getStatus());
 
         super.setupRestTemplate(userTO.getUsername(), "password123");
 
-        userTO = restTemplate.getForObject(BASE_URL + "user/read/{userId}.json", UserTO.class,
userTO.getId());
+        userTO = us1.read(userTO.getId());
 
         assertNotNull(userTO);
         assertEquals(Integer.valueOf(0), userTO.getFailedLogins());
     }
 
     @Test
-    public void issueSYNCOPE48() {
+    public void issueSYNCOPE48() throws UnauthorizedRoleException, WorkflowException, PropagationException,
+            NotFoundException {
         // Parent role, able to create users with role 1
         RoleTO parentRole = new RoleTO();
         parentRole.setName("parentAdminRole");
@@ -408,7 +409,8 @@ public abstract class AbstractAuthentica
         parentRole.addEntitlement("ROLE_1");
         parentRole.setParent(1L);
 
-        parentRole = restTemplate.postForObject(BASE_URL + "role/create", parentRole, RoleTO.class);
+        Response r = rs.create(parentRole);
+        parentRole = resolve(RoleTO.class, r, rs);
         assertNotNull(parentRole);
 
         // Child role, with no entitlements
@@ -416,33 +418,36 @@ public abstract class AbstractAuthentica
         childRole.setName("childAdminRole");
         childRole.setParent(parentRole.getId());
 
-        childRole = restTemplate.postForObject(BASE_URL + "role/create", childRole, RoleTO.class);
+        r = rs.create(parentRole);
+        childRole = resolve(RoleTO.class, r, rs);
         assertNotNull(childRole);
 
         // User with child role, created by admin
-        UserTO role1Admin = AbstractUserTestITCase.getSampleTO("syncope48admin@apache.org");
+        UserTO role1Admin = AbstractUserTestITCase.getSampleTO();
         role1Admin.setPassword("password");
         MembershipTO membershipTO = new MembershipTO();
         membershipTO.setRoleId(childRole.getId());
         role1Admin.addMembership(membershipTO);
 
-        role1Admin = restTemplate.postForObject(BASE_URL + "user/create", role1Admin, UserTO.class);
+        r = us.create(role1Admin);
+        role1Admin = resolve(UserTO.class, r, us);
         assertNotNull(role1Admin);
 
         super.setupRestTemplate(role1Admin.getUsername(), "password");
+        UserService us1 = createServiceInstance(UserService.class, role1Admin.getUsername(),
"password", us);
 
         // User with role 1, created by user with child role created above
-        UserTO role1User = AbstractUserTestITCase.getSampleTO("syncope48user@apache.org");
+        UserTO role1User = AbstractUserTestITCase.getSampleTO();
         membershipTO = new MembershipTO();
         membershipTO.setRoleId(1L);
         role1User.addMembership(membershipTO);
 
-        role1User = restTemplate.postForObject(BASE_URL + "user/create", role1User, UserTO.class);
+        r = us1.create(role1User);
+        role1User = resolve(UserTO.class, r, us1);
         assertNotNull(role1User);
 
         // reset admin credentials for restTemplate
         super.resetRestTemplate();
     }
 
-
 }

Modified: syncope/branches/cxf/core/src/test/resources/restClientContext.xml
URL: http://svn.apache.org/viewvc/syncope/branches/cxf/core/src/test/resources/restClientContext.xml?rev=1423393&r1=1423392&r2=1423393&view=diff
==============================================================================
--- syncope/branches/cxf/core/src/test/resources/restClientContext.xml (original)
+++ syncope/branches/cxf/core/src/test/resources/restClientContext.xml Tue Dec 18 10:22:09
2012
@@ -65,7 +65,7 @@
    </jaxrs:client-->
 
    <bean id="restClientFactory" class="org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean">
-      <property name="address" value="http://localhost:9080/syncope/cxf" />
+      <property name="address" value="http://localhost:9081/syncope/cxf" />
       <property name="threadSafe" value="true" />
       <property name="username" value="admin" />
       <property name="password" value="password" />



Mime
View raw message