You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2015/05/09 19:17:56 UTC
[1/4] stratos git commit: This closes #298 on GitHub
Repository: stratos
Updated Branches:
refs/heads/master e72f46d95 -> ff31e107c
This closes #298 on GitHub
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/ff31e107
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/ff31e107
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/ff31e107
Branch: refs/heads/master
Commit: ff31e107c21ba21168cc67d137f703b2c194b6d9
Parents: eae40c4
Author: Imesh Gunaratne <im...@apache.org>
Authored: Sat May 9 22:47:51 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Sat May 9 22:47:51 2015 +0530
----------------------------------------------------------------------
----------------------------------------------------------------------
[2/4] stratos git commit: Logging the UserStoreException
Posted by im...@apache.org.
Logging the UserStoreException
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/d2700221
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/d2700221
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/d2700221
Branch: refs/heads/master
Commit: d270022108e2e62518a33a5e71f35435b5b310de
Parents: 49f34bb
Author: anuruddhal <an...@gmail.com>
Authored: Wed May 6 18:12:17 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Sat May 9 22:47:51 2015 +0530
----------------------------------------------------------------------
.../apache/stratos/rest/endpoint/api/StratosApiV41Utils.java | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/d2700221/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
index fb8c28e..4cc59f3 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
@@ -2885,7 +2885,7 @@ public class StratosApiV41Utils {
}
// filling the email value
- if (tenantInfoBean.getEmail() != null && !tenantInfoBean.getEmail().equals("")) {
+ if (StringUtils.isBlank(tenantInfoBean.getEmail())) {
// validate the email
try {
CommonUtil.validateEmail(tenantInfoBean.getEmail());
@@ -2929,7 +2929,9 @@ public class StratosApiV41Utils {
tenantInfoBean.setAdminPassword("");
}
} catch (UserStoreException e) {
-
+ String msg = "Error in getting the user store manager is read only " +e.getLocalizedMessage();
+ log.error(msg, e);
+ throw new RestAPIException(msg, e);
}
try {
[4/4] stratos git commit: Improving exception handling and validation
Posted by im...@apache.org.
Improving exception handling and validation
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/49f34bb4
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/49f34bb4
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/49f34bb4
Branch: refs/heads/master
Commit: 49f34bb42d9d7a91953d95262bd4552936ea4193
Parents: e72f46d
Author: anuruddhal <an...@gmail.com>
Authored: Wed May 6 18:03:36 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Sat May 9 22:47:51 2015 +0530
----------------------------------------------------------------------
.../rest/endpoint/api/StratosApiV41Utils.java | 90 +++++++++++---------
1 file changed, 51 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/49f34bb4/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
index 195d67e..fb8c28e 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
@@ -2754,15 +2754,16 @@ public class StratosApiV41Utils {
UserRegistry userRegistry = (UserRegistry) PrivilegedCarbonContext.getThreadLocalCarbonContext().
getRegistry(RegistryType.USER_GOVERNANCE);
if (userRegistry == null) {
- log.error("Security alert! User registry is null. A user is trying create a tenant "
- + " without an authenticated session.");
- throw new RestAPIException("Security alert! User registry is null. A user is trying create a tenant "
- + " without an authenticated session.");
+ String msg="Security alert! User registry is null. A user is trying create a tenant "
+ + " without an authenticated session.";
+ log.error(msg);
+ throw new RestAPIException(msg);
}
if (userRegistry.getTenantId() != MultitenantConstants.SUPER_TENANT_ID) {
- log.error("Security alert! None super tenant trying to create a tenant.");
- throw new RestAPIException("Security alert! None super tenant trying to create a tenant.");
+ String msg="Security alert! None super tenant trying to create a tenant.";
+ log.error(msg);
+ throw new RestAPIException(msg);
}
Tenant tenant = TenantMgtUtil
@@ -2784,7 +2785,7 @@ public class StratosApiV41Utils {
try {
TenantMgtUtil.addClaimsToUserStoreManager(tenant);
} catch (Exception e) {
- String msg = "Error in granting permissions for tenant " + tenantDomain;
+ String msg = "Error in granting permissions for tenant " + tenantDomain + e.getLocalizedMessage();
log.error(msg, e);
throw new RestAPIException(msg);
}
@@ -2817,13 +2818,14 @@ public class StratosApiV41Utils {
}
/**
- * Update Existing Tenant
*
* @param tenantInfoBean TenantInfoBean
- * @throws Exception
+ * @throws RestAPIException
+ * @throws InvalidEmailException
+ * @throws RegistryException
*/
public static void updateExistingTenant(org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean) throws
- Exception, InvalidEmailException {
+ RestAPIException, RegistryException,InvalidEmailException {
TenantManager tenantManager = ServiceHolder.getTenantManager();
UserStoreManager userStoreManager;
@@ -2839,42 +2841,48 @@ public class StratosApiV41Utils {
} catch (UserStoreException e) {
String msg = "Error in retrieving the tenant id for the tenant domain: " + tenantDomain + ".";
log.error(msg, e);
- throw new Exception(msg, e);
+ throw new RestAPIException(msg, e);
}
Tenant tenant;
try {
tenant = (Tenant) tenantManager.getTenant(tenantId);
} catch (UserStoreException e) {
- String msg = "Error in retrieving the tenant id for the tenant domain: " +
- tenantDomain + ".";
+ String msg = "Error in retrieving the tenant from tenant id: " +
+ tenantId + ".";
log.error(msg, e);
- throw new TenantNotFoundException(msg, e);
+ throw new RestAPIException(msg, e);
}
// filling the first and last name values
- if (tenantInfoBean.getFirstname() != null && !tenantInfoBean.getFirstname().trim().equals("")) {
+ if (StringUtils.isBlank(tenantInfoBean.getFirstname())) {
try {
CommonUtil.validateName(tenantInfoBean.getFirstname(), "First Name");
} catch (Exception e) {
String msg = "Invalid first name is provided.";
log.error(msg, e);
- throw new Exception(msg, e);
+ throw new RestAPIException(msg, e);
}
}
- if (tenantInfoBean.getLastname() != null && !tenantInfoBean.getLastname().trim().equals("")) {
+ if (StringUtils.isBlank(tenantInfoBean.getLastname())) {
try {
CommonUtil.validateName(tenantInfoBean.getLastname(), "Last Name");
} catch (Exception e) {
String msg = "Invalid last name is provided.";
log.error(msg, e);
- throw new Exception(msg, e);
+ throw new RestAPIException(msg, e);
}
}
tenant.setAdminFirstName(tenantInfoBean.getFirstname());
tenant.setAdminLastName(tenantInfoBean.getLastname());
- TenantMgtUtil.addClaimsToUserStoreManager(tenant);
+ try {
+ TenantMgtUtil.addClaimsToUserStoreManager(tenant);
+ } catch (Exception e) {
+ String msg = "Error in adding claims to the user.";
+ log.error(msg, e);
+ throw new RestAPIException(msg, e);
+ }
// filling the email value
if (tenantInfoBean.getEmail() != null && !tenantInfoBean.getEmail().equals("")) {
@@ -2884,7 +2892,7 @@ public class StratosApiV41Utils {
} catch (Exception e) {
String msg = "Invalid email is provided.";
log.error(msg, e);
- throw new Exception(msg, e);
+ throw new InvalidEmailException(msg);
}
tenant.setEmail(tenantInfoBean.getEmail());
}
@@ -2894,30 +2902,34 @@ public class StratosApiV41Utils {
userStoreManager = userRealm.getUserStoreManager();
} catch (UserStoreException e) {
String msg = "Error in getting the user store manager for tenant, tenant domain: " +
- tenantDomain + ".";
+ tenantDomain + "."+e.getLocalizedMessage();
log.error(msg, e);
- throw new Exception(msg, e);
+ throw new RestAPIException(msg, e);
}
boolean updatePassword = false;
if (tenantInfoBean.getAdminPassword() != null && !tenantInfoBean.getAdminPassword().equals("")) {
updatePassword = true;
}
- if (!userStoreManager.isReadOnly() && updatePassword) {
- // now we will update the tenant admin with the admin given
- // password.
- try {
- userStoreManager.updateCredentialByAdmin(tenantInfoBean.getAdmin(), tenantInfoBean.getAdminPassword());
- } catch (UserStoreException e) {
- String msg = "Error in changing the tenant admin password, tenant domain: " +
- tenantInfoBean.getTenantDomain() + ". " + e.getMessage() + " for: " +
- tenantInfoBean.getAdmin();
- log.error(msg, e);
- throw new Exception(msg, e);
+ try {
+ if (!userStoreManager.isReadOnly() && updatePassword) {
+ // now we will update the tenant admin with the admin given
+ // password.
+ try {
+ userStoreManager.updateCredentialByAdmin(tenantInfoBean.getAdmin(), tenantInfoBean.getAdminPassword());
+ } catch (UserStoreException e) {
+ String msg = "Error in changing the tenant admin password, tenant domain: " +
+ tenantInfoBean.getTenantDomain() + ". " + e.getMessage() + " for: " +
+ tenantInfoBean.getAdmin();
+ log.error(msg, e);
+ throw new RestAPIException(msg, e);
+ }
+ } else {
+ //Password should be empty since no password update done
+ tenantInfoBean.setAdminPassword("");
}
- } else {
- //Password should be empty since no password update done
- tenantInfoBean.setAdminPassword("");
+ } catch (UserStoreException e) {
+
}
try {
@@ -2925,7 +2937,7 @@ public class StratosApiV41Utils {
} catch (UserStoreException e) {
String msg = "Error in updating the tenant for tenant domain: " + tenantDomain + ".";
log.error(msg, e);
- throw new Exception(msg, e);
+ throw new RestAPIException(msg, e);
}
//Notify tenant update to all listeners
@@ -2935,7 +2947,7 @@ public class StratosApiV41Utils {
} catch (StratosException e) {
String msg = "Error in notifying tenant update.";
log.error(msg, e);
- throw new Exception(msg, e);
+ throw new RestAPIException(msg, e);
}
}
@@ -2972,7 +2984,7 @@ public class StratosApiV41Utils {
try {
bean = ObjectConverter
.convertCarbonTenantInfoBeanToTenantInfoBean(TenantMgtUtil.initializeTenantInfoBean(tenantId, tenant));
- } catch (NullPointerException e) {
+ } catch (Exception e) {
log.error(String.format("Couldn't find tenant for provided tenant domain. [Tenant Domain] %s", tenantDomain));
return null;
}
[3/4] stratos git commit: Improving exception handling
Posted by im...@apache.org.
Improving exception handling
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/eae40c44
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/eae40c44
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/eae40c44
Branch: refs/heads/master
Commit: eae40c44db877efa072671766a49990d0bd47b84
Parents: d270022
Author: anuruddhal <an...@gmail.com>
Authored: Thu May 7 09:45:49 2015 +0530
Committer: Imesh Gunaratne <im...@apache.org>
Committed: Sat May 9 22:47:51 2015 +0530
----------------------------------------------------------------------
.../rest/endpoint/api/StratosApiV41Utils.java | 42 +++++++++++++-------
1 file changed, 27 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/eae40c44/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
index 4cc59f3..2d878bc 100644
--- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
+++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/api/StratosApiV41Utils.java
@@ -103,7 +103,7 @@ public class StratosApiV41Utils {
public static final String APPLICATION_STATUS_DEPLOYED = "Deployed";
public static final String APPLICATION_STATUS_CREATED = "Created";
- private static Log log = LogFactory.getLog(StratosApiV41Utils.class);
+ private static final Log log = LogFactory.getLog(StratosApiV41Utils.class);
/**
* Add New Cartridge
@@ -2757,7 +2757,7 @@ public class StratosApiV41Utils {
String msg="Security alert! User registry is null. A user is trying create a tenant "
+ " without an authenticated session.";
log.error(msg);
- throw new RestAPIException(msg);
+ throw new RestAPIException("Could not add tenant: Session is not authenticated");
}
if (userRegistry.getTenantId() != MultitenantConstants.SUPER_TENANT_ID) {
@@ -2970,7 +2970,7 @@ public class StratosApiV41Utils {
} catch (UserStoreException e) {
String msg = "Error in retrieving the tenant id for the tenant domain: " +
tenantDomain + ".";
- log.error(msg);
+ log.error(msg,e);
throw new Exception(msg, e);
}
Tenant tenant;
@@ -2978,7 +2978,7 @@ public class StratosApiV41Utils {
tenant = (Tenant) tenantManager.getTenant(tenantId);
} catch (UserStoreException e) {
String msg = "Error in retrieving the tenant from the tenant manager.";
- log.error(msg);
+ log.error(msg,e);
throw new Exception(msg, e);
}
@@ -2987,7 +2987,7 @@ public class StratosApiV41Utils {
bean = ObjectConverter
.convertCarbonTenantInfoBeanToTenantInfoBean(TenantMgtUtil.initializeTenantInfoBean(tenantId, tenant));
} catch (Exception e) {
- log.error(String.format("Couldn't find tenant for provided tenant domain. [Tenant Domain] %s", tenantDomain));
+ log.error(String.format("Couldn't find tenant for provided tenant domain. [Tenant Domain] %s", tenantDomain),e);
return null;
}
@@ -3017,10 +3017,10 @@ public class StratosApiV41Utils {
List<org.apache.stratos.common.beans.TenantInfoBean> tenantList = new ArrayList<org.apache.stratos.common.beans.TenantInfoBean>();
for (Tenant tenant : tenants) {
- org.apache.stratos.common.beans.TenantInfoBean bean = ObjectConverter
+ org.apache.stratos.common.beans.TenantInfoBean tenantInfoBean = ObjectConverter
.convertCarbonTenantInfoBeanToTenantInfoBean(
TenantMgtUtil.getTenantInfoBeanfromTenant(tenant.getId(), tenant));
- tenantList.add(bean);
+ tenantList.add(tenantInfoBean);
}
return tenantList;
}
@@ -3078,7 +3078,9 @@ public class StratosApiV41Utils {
TenantMgtUtil.activateTenant(tenantDomain, tenantManager, tenantId);
} catch (Exception e) {
- throw new RestAPIException(e);
+ String msg="Error in activating Tenant :"+tenantDomain;
+ log.error(msg,e);
+ throw new RestAPIException(msg,e);
}
//Notify tenant activation all listeners
@@ -3114,7 +3116,9 @@ public class StratosApiV41Utils {
try {
TenantMgtUtil.deactivateTenant(tenantDomain, tenantManager, tenantId);
} catch (Exception e) {
- throw new RestAPIException(e);
+ String msg="Error in deactivating Tenant :"+tenantDomain;
+ log.error(msg,e);
+ throw new RestAPIException(msg,e);
}
//Notify tenant deactivation all listeners
@@ -3140,7 +3144,9 @@ public class StratosApiV41Utils {
try {
StratosUserManagerUtils.addUser(getTenantUserStoreManager(), userInfoBean);
} catch (UserManagerException e) {
- throw new RestAPIException(e.getMessage());
+ String msg = "Error in adding User";
+ log.error(msg, e);
+ throw new RestAPIException(msg, e);
}
}
@@ -3174,21 +3180,23 @@ public class StratosApiV41Utils {
/**
* Delete an user
*
- * @param userName
+ * @param userName userName
* @throws RestAPIException
*/
public static void removeUser(String userName) throws RestAPIException {
try {
StratosUserManagerUtils.removeUser(getTenantUserStoreManager(), userName);
} catch (UserManagerException e) {
- throw new RestAPIException(e.getMessage());
+ String msg = "Error in removing user :"+userName;
+ log.error(msg, e);
+ throw new RestAPIException(msg, e);
}
}
/**
* Update User
*
- * @param userInfoBean
+ * @param userInfoBean UserInfoBean
* @throws RestAPIException
*/
public static void updateUser(UserInfoBean userInfoBean) throws RestAPIException {
@@ -3196,7 +3204,9 @@ public class StratosApiV41Utils {
StratosUserManagerUtils.updateUser(getTenantUserStoreManager(), userInfoBean);
} catch (UserManagerException e) {
- throw new RestAPIException(e.getMessage());
+ String msg = "Error in updating user";
+ log.error(msg, e);
+ throw new RestAPIException(msg,e);
}
}
@@ -3212,7 +3222,9 @@ public class StratosApiV41Utils {
try {
userList = StratosUserManagerUtils.getAllUsers(getTenantUserStoreManager());
} catch (UserManagerException e) {
- throw new RestAPIException(e.getMessage());
+ String msg = "Error in retrieving users";
+ log.error(msg, e);
+ throw new RestAPIException(msg,e);
}
return userList;
}