Author: keith
Date: Sun Jan 20 21:05:39 2008
New Revision: 12555
Log:
Moving creation of secureRegistry to a util cause we need to configure admin
behaviour on every creation.
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/transport/MashupServerInitializer.java
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/InfoCardHandler.java
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/RegistrationBean.java
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/utils/RegistryUtils.java
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JSDeployer.java
trunk/mashup/java/modules/www/signin.jsp
trunk/mashup/java/modules/www/signout.jsp
trunk/mashup/java/modules/www/validate_login.jsp
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/transport/MashupServerInitializer.java
==============================================================================
---
trunk/mashup/java/modules/core/src/org/wso2/mashup/transport/MashupServerInitializer.java
(original)
+++
trunk/mashup/java/modules/core/src/org/wso2/mashup/transport/MashupServerInitializer.java
Sun Jan 20 21:05:39 2008
@@ -111,8 +111,8 @@
// Applying a dummy tag so that searching works
// https://wso2.org/jira/browse/REGISTRY-24
- SecureRegistry secureRegistry =
- new SecureRegistry(MashupConstants.SYSTEM_USER, registry,
realm);
+ SecureRegistry secureRegistry =
RegistryUtils.createSecureRegistry(MashupConstants.SYSTEM_USER, registry,
+ realm);
secureRegistry.applyTag("/mashups/system/version", "built-in");
secureRegistry.applyTag("/mashups/system/version", "management");
secureRegistry.applyTag("/mashups/system/version", "scraping");
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/InfoCardHandler.java
==============================================================================
---
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/InfoCardHandler.java
(original)
+++
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/InfoCardHandler.java
Sun Jan 20 21:05:39 2008
@@ -63,16 +63,9 @@
String ppid = (String)
request.getAttribute(IdentityConstants.CLAIM_PPID);
String userName = MashupUtils.login(ppid, session.getId());
SecureRegistry secureRegistry = null;
- try {
- secureRegistry = new SecureRegistry(userName,
-
jdbcRegistry, realm);
- } catch (RegistryException e) {
- log.error("Cannot get secureRegistry for user " + userName);
- throw new MashupFault("Cannot get secureRegistry for user " +
userName, e);
- }
- request.getSession().setAttribute(MashupConstants.USER_REGISTRY,
- secureRegistry);
- success = true;
+ secureRegistry = RegistryUtils.createSecureRegistry(userName,
jdbcRegistry, realm);
+ request.getSession().setAttribute(MashupConstants.USER_REGISTRY,
secureRegistry);
+ success = true;
} else {
String reason =
(String)
request.getAttribute(TokenVerifierConstants.FAILURE_REASON);
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/RegistrationBean.java
==============================================================================
---
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/RegistrationBean.java
(original)
+++
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/identity/RegistrationBean.java
Sun Jan 20 21:05:39 2008
@@ -18,6 +18,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.mashup.MashupConstants;
+import org.wso2.mashup.MashupFault;
import org.wso2.mashup.utils.MashupUtils;
import org.wso2.mashup.webapp.userprofile.ManageUsers;
import org.wso2.mashup.webapp.utils.RegistryUtils;
@@ -140,13 +141,13 @@
/**
* Accepts users information submitted and creates the admin ID.
*/
- public void createAdmin(HttpServletRequest request) throws
UserManagerException,
+ public void createAdmin(HttpServletRequest request) throws MashupFault,
RegistryException {
ServletContext context = request.getSession().getServletContext();
JDBCRegistry jdbcRegistry = (JDBCRegistry) context.getAttribute(
RegistryConstants.REGISTRY);
Realm realm = (Realm)
context.getAttribute(RegistryConstants.REGISTRY_REALM);
- SecureRegistry registry = new
SecureRegistry(MashupConstants.SYSTEM_USER,
+ SecureRegistry registry =
RegistryUtils.createSecureRegistry(MashupConstants.SYSTEM_USER,
MashupConstants.SYSTEM_USER_PASSWORD,
jdbcRegistry, realm);
try {
@@ -166,10 +167,10 @@
MashupUtils.setInitialSetupComplete(true);
} catch (UserManagerException e) {
log.error("Error creating admin user in user manager", e);
- throw new UserManagerException("Could not create admin user", e);
+ throw new MashupFault("Could not create admin user", e);
} catch (RegistryException e) {
log.error("Error adding admin user resources", e);
- throw new RegistryException("Could not create admin user", e);
+ throw new MashupFault("Could not create admin user", e);
}
}
@@ -190,7 +191,7 @@
* @param request Servlet request.
* @return true if user is successfully validated.
*/
- public static boolean validate(HttpServletRequest request) {
+ public static boolean validate(HttpServletRequest request) throws
MashupFault{
boolean isVerified = false;
String confValue = request.getParameter("confirmation");
String userName;
@@ -206,6 +207,7 @@
}
} catch (UserManagerException e) {
log.error("Error verifying user registration", e);
+ throw new MashupFault("Error verifying user registration", e);
}
}
return isVerified;
@@ -240,7 +242,7 @@
* @param userName Identifier of user to be authorized.
* @return true if user authorization succeeds.
*/
- private static boolean authorizeUser(HttpServletRequest request, String
userName) {
+ private static boolean authorizeUser(HttpServletRequest request, String
userName) throws MashupFault{
boolean isAuthorized = false;
ServletContext context = request.getSession().getServletContext();
JDBCRegistry jdbcRegistry =
@@ -254,7 +256,7 @@
String eMail = (String) userProps.get(MashupConstants.EMAIL_ID);
// Create secure registry instance using the admin ID.
- SecureRegistry secureRegistry = new
SecureRegistry(MashupConstants.SYSTEM_USER,
+ SecureRegistry secureRegistry =
RegistryUtils.createSecureRegistry(MashupConstants.SYSTEM_USER,
MashupConstants.SYSTEM_USER_PASSWORD,
jdbcRegistry,
realm);
// Add user to registry.
@@ -262,8 +264,10 @@
isAuthorized = true;
} catch (UserManagerException e) {
log.error("Error adding user to role", e);
+ throw new MashupFault("Error adding user to role", e);
} catch (RegistryException e) {
log.error("Error adding user resources", e);
+ throw new MashupFault("Error adding user to role", e);
}
return isAuthorized;
}
Modified:
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/utils/RegistryUtils.java
==============================================================================
---
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/utils/RegistryUtils.java
(original)
+++
trunk/mashup/java/modules/core/src/org/wso2/mashup/webapp/utils/RegistryUtils.java
Sun Jan 20 21:05:39 2008
@@ -18,23 +18,15 @@
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.deployment.DeploymentEngine;
import org.wso2.mashup.MashupConstants;
+import org.wso2.mashup.MashupFault;
import org.wso2.mashup.utils.QueryResult;
import org.wso2.mashup.utils.QueryResults;
import org.wso2.mashup.webapp.userprofile.User;
-import org.wso2.registry.ActionConstants;
-import org.wso2.registry.LogEntry;
-import org.wso2.registry.Registry;
-import org.wso2.registry.RegistryConstants;
-import org.wso2.registry.RegistryException;
-import org.wso2.registry.Resource;
+import org.wso2.registry.*;
import org.wso2.registry.jdbc.JDBCRegistry;
import org.wso2.registry.secure.SecureRegistry;
-import org.wso2.usermanager.AccessControlAdmin;
-import org.wso2.usermanager.Realm;
-import org.wso2.usermanager.UserManagerConstants;
-import org.wso2.usermanager.UserManagerException;
-import org.wso2.usermanager.UserStoreAdmin;
-import org.wso2.usermanager.UserStoreReader;
+import org.wso2.usermanager.*;
+import org.wso2.usermanager.acl.realm.AuthorizingRealmConfig;
import org.wso2.utils.ServerConfiguration;
import org.wso2.wsas.ServerManager;
@@ -44,16 +36,11 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.*;
public class RegistryUtils {
- public static Registry getRegistry(HttpServletRequest request) throws
RegistryException {
+ public static Registry getRegistry(HttpServletRequest request) throws
MashupFault {
Registry registry =
(Registry)
request.getSession().getAttribute(MashupConstants.USER_REGISTRY);
@@ -69,8 +56,7 @@
Realm realm = (Realm)
context.getAttribute(RegistryConstants.REGISTRY_REALM);
- SecureRegistry secureRegistry = new SecureRegistry(
- RegistryConstants.ANONYMOUS_USER, "guest", jdbcRegistry,
realm);
+ SecureRegistry secureRegistry =
createSecureRegistry(RegistryConstants.ANONYMOUS_USER, "guest", jdbcRegistry,
realm);
request.getSession().setAttribute(MashupConstants.USER_REGISTRY,
secureRegistry);
@@ -79,6 +65,41 @@
return registry;
}
+ public static SecureRegistry createSecureRegistry(String username, String
password, Registry registry,
+ Realm realm) throws
MashupFault {
+ SecureRegistry secureRegistry = null;
+ try {
+ secureRegistry = new SecureRegistry(username, password, registry,
realm);
+ setAdminBehaviour(secureRegistry);
+ } catch (RegistryException e) {
+ throw new MashupFault("Unable to create registry instance for user
" + username, e);
+ } catch (UserManagerException e) {
+ throw new MashupFault("Unable to set admin role to usernamager.",
e);
+ }
+ return secureRegistry;
+ }
+
+ public static SecureRegistry createSecureRegistry(String username,
Registry registry, Realm realm)
+ throws MashupFault {
+ SecureRegistry secureRegistry = null;
+ try {
+ secureRegistry = new SecureRegistry(username, registry, realm);
+ setAdminBehaviour(secureRegistry);
+ } catch (RegistryException e) {
+ throw new MashupFault("Unable to create registry instance for user
" + username, e);
+ } catch (UserManagerException e) {
+ throw new MashupFault("Unable to set admin role to usernamager.",
e);
+ }
+ return secureRegistry;
+ }
+
+ private static void setAdminBehaviour(SecureRegistry secureRegistry)
throws UserManagerException {
+ Realm userRealm = secureRegistry.getUserRealm();
+ AuthorizingRealmConfig authorizingRealmConfig =
(AuthorizingRealmConfig)userRealm.getRealmConfiguration();
+ authorizingRealmConfig.setEnableAdminBehavior(true);
+ authorizingRealmConfig.setAdminRoleName(RegistryConstants.ADMIN_ROLE);
+ }
+
public static boolean isLoggedIn(Registry registry) throws
RegistryException {
if (registry instanceof SecureRegistry) {
Modified:
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JSDeployer.java
==============================================================================
---
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JSDeployer.java
(original)
+++
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JSDeployer.java
Sun Jan 20 21:05:39 2008
@@ -430,7 +430,7 @@
JDBCRegistry registry =
(JDBCRegistry)
configCtx.getAxisConfiguration().getParameterValue(
RegistryConstants.REGISTRY);
- SecureRegistry secureRegistry = new SecureRegistry(username,
registry, realm);
+ SecureRegistry secureRegistry =
RegistryUtils.createSecureRegistry(username, registry, realm);
// create a content resource
Resource resource1 = new Resource();
@@ -877,7 +877,7 @@
MashupConstants.ALL_MASHUPS_QUERY_PATH,
UserManagerConstants.READ);
// Instantiating a secure registry, in order to create user
profiles.
- SecureRegistry secureRegistry = new SecureRegistry(
+ SecureRegistry secureRegistry =
RegistryUtils.createSecureRegistry(
MashupConstants.SYSTEM_USER,
MashupConstants.SYSTEM_USER_PASSWORD, registry,
realm);
Modified: trunk/mashup/java/modules/www/signin.jsp
==============================================================================
--- trunk/mashup/java/modules/www/signin.jsp (original)
+++ trunk/mashup/java/modules/www/signin.jsp Sun Jan 20 21:05:39 2008
@@ -81,7 +81,7 @@
MashupUtils.login(nameProvided, passwordProvided,
session.getId());
SecureRegistry secureRegistry =
- new SecureRegistry(nameProvided, jdbcRegistry, realm);
+ RegistryUtils.createSecureRegistry(nameProvided,
jdbcRegistry, realm);
request.getSession().setAttribute(MashupConstants.USER_REGISTRY,
secureRegistry);
@@ -127,11 +127,9 @@
} else {
success = false;
}
- } catch (RegistryException e) {
- success = false;
} catch (MashupFault e) {
success = false;
- }
+ }
}
}
Modified: trunk/mashup/java/modules/www/signout.jsp
==============================================================================
--- trunk/mashup/java/modules/www/signout.jsp (original)
+++ trunk/mashup/java/modules/www/signout.jsp Sun Jan 20 21:05:39 2008
@@ -84,7 +84,7 @@
MashupUtils.logout(session.getId());
SecureRegistry secureRegistry =
- new SecureRegistry(RegistryConstants.ANONYMOUS_USER, "guest",
jdbcRegistry, realm);
+
RegistryUtils.createSecureRegistry(RegistryConstants.ANONYMOUS_USER, "guest",
jdbcRegistry, realm);
request.getSession().setAttribute(MashupConstants.USER_REGISTRY,
secureRegistry);
@@ -110,7 +110,7 @@
response.sendRedirect(bounceback);
- } catch (RegistryException e) {
+ } catch (MashupFault e) {
}
/*
}
Modified: trunk/mashup/java/modules/www/validate_login.jsp
==============================================================================
--- trunk/mashup/java/modules/www/validate_login.jsp (original)
+++ trunk/mashup/java/modules/www/validate_login.jsp Sun Jan 20 21:05:39 2008
@@ -77,7 +77,7 @@
MashupUtils.login(userNameStored, passwordStored,
session.getId());
SecureRegistry secureRegistry =
- new SecureRegistry(userNameStored, jdbcRegistry,
realm);
+ RegistryUtils.createSecureRegistry(userNameStored,
jdbcRegistry, realm);
request.getSession().setAttribute(MashupConstants.USER_REGISTRY,
secureRegistry);
_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev