You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by vk...@apache.org on 2008/09/22 15:28:00 UTC
svn commit: r697818 - in
/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl:
GroupManagerImpl.java RoleManagerImpl.java
Author: vkumar
Date: Mon Sep 22 06:27:59 2008
New Revision: 697818
URL: http://svn.apache.org/viewvc?rev=697818&view=rev
Log:
Simplifying exception hierarchy
Modified:
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/GroupManagerImpl.java
portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/RoleManagerImpl.java
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/GroupManagerImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/GroupManagerImpl.java?rev=697818&r1=697817&r2=697818&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/GroupManagerImpl.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/GroupManagerImpl.java Mon Sep 22 06:27:59 2008
@@ -218,11 +218,9 @@
public void addUserToGroup(String username, String groupName)
throws SecurityException
{
- try
- {
- checkInitialized();
- User user = userManager.getUser(username);
- if (user == null)
+ checkInitialized();
+ User user = userManager.getUser(username);
+ if (user == null)
{
throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.USER_TYPE_NAME, username));
}
@@ -232,20 +230,6 @@
throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.GROUP_TYPE_NAME, groupName));
}
super.addAssociation(user, group, JetspeedPrincipalAssociationType.IS_MEMBER_OF_ASSOCIATION_TYPE_NAME);
- }
- catch (PrincipalNotFoundException e)
- {
- // TODO: determine *which* principal does not exist to provide the correct error message...
- throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST);
- }
- catch (PrincipalAssociationNotAllowedException e)
- {
- throw new SecurityException(SecurityException.PRINCIPAL_ASSOCIATION_NOT_ALLOWED.createScoped(JetspeedPrincipalType.GROUP_TYPE_NAME, groupName));
- }
- catch (PrincipalAssociationUnsupportedException e)
- {
- throw new SecurityException(SecurityException.PRINCIPAL_ASSOCIATION_UNSUPPORTED.createScoped(JetspeedPrincipalType.GROUP_TYPE_NAME, groupName));
- }
}
/**
@@ -255,30 +239,18 @@
public void removeUserFromGroup(String username, String groupName)
throws SecurityException
{
- try
+ checkInitialized();
+ User user = userManager.getUser(username);
+ if (user == null)
{
- checkInitialized();
- User user = userManager.getUser(username);
- if (user == null)
- {
- throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.USER_TYPE_NAME, username));
- }
- Group group = getGroup(groupName);
- if (group == null)
- {
- throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.GROUP_TYPE_NAME, groupName));
- }
- super.removeAssociation(user, group, JetspeedPrincipalAssociationType.IS_MEMBER_OF_ASSOCIATION_TYPE_NAME);
- }
- catch (PrincipalAssociationRequiredException e)
- {
- throw new SecurityException(SecurityException.PRINCIPAL_ASSOCIATION_REQUIRED.createScoped(JetspeedPrincipalType.GROUP_TYPE_NAME, groupName));
+ throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.USER_TYPE_NAME, username));
}
- catch (PrincipalNotFoundException e)
+ Group group = getGroup(groupName);
+ if (group == null)
{
- // TODO: determine *which* principal does not exist to provide the correct error message...
- throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST);
+ throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.GROUP_TYPE_NAME, groupName));
}
+ super.removeAssociation(user, group, JetspeedPrincipalAssociationType.IS_MEMBER_OF_ASSOCIATION_TYPE_NAME);
}
/**
Modified: portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/RoleManagerImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/RoleManagerImpl.java?rev=697818&r1=697817&r2=697818&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/RoleManagerImpl.java (original)
+++ portals/jetspeed-2/portal/branches/security-refactoring/components/jetspeed-security/src/main/java/org/apache/jetspeed/security/impl/RoleManagerImpl.java Mon Sep 22 06:27:59 2008
@@ -223,34 +223,18 @@
*/
public void addRoleToUser(String username, String roleName) throws SecurityException
{
- try
- {
- checkInitialized();
- User user = userManager.getUser(username);
- if (user == null)
- {
- throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.USER_TYPE_NAME, username));
- }
- Role role = getRole(roleName);
- if (role == null)
- {
- throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.ROLE_TYPE_NAME, roleName));
- }
- super.addAssociation(user, role, JetspeedPrincipalAssociationType.IS_MEMBER_OF_ASSOCIATION_TYPE_NAME);
- }
- catch (PrincipalNotFoundException e)
- {
- // TODO: determine *which* principal does not exist to provide the correct error message...
- throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST);
- }
- catch (PrincipalAssociationNotAllowedException e)
+ checkInitialized();
+ User user = userManager.getUser(username);
+ if (user == null)
{
- throw new SecurityException(SecurityException.PRINCIPAL_ASSOCIATION_NOT_ALLOWED.createScoped(JetspeedPrincipalType.ROLE_TYPE_NAME, roleName));
+ throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.USER_TYPE_NAME, username));
}
- catch (PrincipalAssociationUnsupportedException e)
+ Role role = getRole(roleName);
+ if (role == null)
{
- throw new SecurityException(SecurityException.PRINCIPAL_ASSOCIATION_UNSUPPORTED.createScoped(JetspeedPrincipalType.ROLE_TYPE_NAME, roleName));
+ throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.ROLE_TYPE_NAME, roleName));
}
+ super.addAssociation(user, role, JetspeedPrincipalAssociationType.IS_MEMBER_OF_ASSOCIATION_TYPE_NAME);
}
/**
@@ -259,30 +243,18 @@
*/
public void removeRoleFromUser(String username, String roleName) throws SecurityException
{
- try
- {
- checkInitialized();
- User user = userManager.getUser(username);
- if (user == null)
- {
- throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.USER_TYPE_NAME, username));
- }
- Role role = getRole(roleName);
- if (role == null)
- {
- throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.ROLE_TYPE_NAME, roleName));
- }
- super.removeAssociation(user, role, JetspeedPrincipalAssociationType.IS_MEMBER_OF_ASSOCIATION_TYPE_NAME);
- }
- catch (PrincipalAssociationRequiredException e)
+ checkInitialized();
+ User user = userManager.getUser(username);
+ if (user == null)
{
- throw new SecurityException(SecurityException.PRINCIPAL_ASSOCIATION_REQUIRED.createScoped(JetspeedPrincipalType.ROLE_TYPE_NAME, roleName));
+ throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.USER_TYPE_NAME, username));
}
- catch (PrincipalNotFoundException e)
+ Role role = getRole(roleName);
+ if (role == null)
{
- // TODO: determine *which* principal does not exist to provide the correct error message...
- throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST);
- }
+ throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.ROLE_TYPE_NAME, roleName));
+ }
+ super.removeAssociation(user, role, JetspeedPrincipalAssociationType.IS_MEMBER_OF_ASSOCIATION_TYPE_NAME);
}
/**
@@ -300,34 +272,18 @@
*/
public void addRoleToGroup(String roleName, String groupName) throws SecurityException
{
- try
- {
- checkInitialized();
- Group group = groupManager.getGroup(groupName);
- if (group == null)
- {
- throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.GROUP_TYPE_NAME, groupName));
- }
- Role role = getRole(roleName);
- if (role == null)
- {
- throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.ROLE_TYPE_NAME, roleName));
- }
- super.addAssociation(group, role, JetspeedPrincipalAssociationType.IS_MEMBER_OF_ASSOCIATION_TYPE_NAME);
- }
- catch (PrincipalNotFoundException e)
- {
- // TODO: determine *which* principal does not exist to provide the correct error message...
- throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST);
- }
- catch (PrincipalAssociationNotAllowedException e)
+ checkInitialized();
+ Group group = groupManager.getGroup(groupName);
+ if (group == null)
{
- throw new SecurityException(SecurityException.PRINCIPAL_ASSOCIATION_NOT_ALLOWED.createScoped(JetspeedPrincipalType.ROLE_TYPE_NAME, roleName));
+ throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.GROUP_TYPE_NAME, groupName));
}
- catch (PrincipalAssociationUnsupportedException e)
+ Role role = getRole(roleName);
+ if (role == null)
{
- throw new SecurityException(SecurityException.PRINCIPAL_ASSOCIATION_UNSUPPORTED.createScoped(JetspeedPrincipalType.ROLE_TYPE_NAME, roleName));
+ throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.ROLE_TYPE_NAME, roleName));
}
+ super.addAssociation(group, role, JetspeedPrincipalAssociationType.IS_MEMBER_OF_ASSOCIATION_TYPE_NAME);
}
/**
@@ -336,30 +292,18 @@
*/
public void removeRoleFromGroup(String roleName, String groupName) throws SecurityException
{
- try
- {
- checkInitialized();
- Group group = groupManager.getGroup(groupName);
- if (group == null)
- {
- throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.GROUP_TYPE_NAME, groupName));
- }
- Role role = getRole(roleName);
- if (role == null)
- {
- throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.ROLE_TYPE_NAME, roleName));
- }
- super.removeAssociation(group, role, JetspeedPrincipalAssociationType.IS_MEMBER_OF_ASSOCIATION_TYPE_NAME);
- }
- catch (PrincipalAssociationRequiredException e)
+ checkInitialized();
+ Group group = groupManager.getGroup(groupName);
+ if (group == null)
{
- throw new SecurityException(SecurityException.PRINCIPAL_ASSOCIATION_REQUIRED.createScoped(JetspeedPrincipalType.ROLE_TYPE_NAME, roleName));
+ throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.GROUP_TYPE_NAME, groupName));
}
- catch (PrincipalNotFoundException e)
+ Role role = getRole(roleName);
+ if (role == null)
{
- // TODO: determine *which* principal does not exist to provide the correct error message...
- throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST);
- }
+ throw new SecurityException(SecurityException.PRINCIPAL_DOES_NOT_EXIST.createScoped(JetspeedPrincipalType.ROLE_TYPE_NAME, roleName));
+ }
+ super.removeAssociation(group, role, JetspeedPrincipalAssociationType.IS_MEMBER_OF_ASSOCIATION_TYPE_NAME);
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org