You are viewing a plain text version of this content. The canonical link for it is here.
Posted to photark-commits@incubator.apache.org by su...@apache.org on 2010/06/13 15:21:03 UTC
svn commit: r954241 - in /incubator/photark/trunk:
photark-jcr/src/main/java/org/apache/photark/jcr/services/
photark-security/src/main/java/org/apache/photark/security/authentication/
photark-security/src/main/java/org/apache/photark/security/authoriz...
Author: suho
Date: Sun Jun 13 15:21:01 2010
New Revision: 954241
URL: http://svn.apache.org/viewvc?rev=954241&view=rev
Log:
fixing the issue 50
Adding functionality to manage login links
Improvements to the registration framework
submitted by suho
Modified:
incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRAlbumImpl.java
incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRGalleryImpl.java
incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRImageUploadServiceImpl.java
incubator/photark/trunk/photark-security/src/main/java/org/apache/photark/security/authentication/AuthorizationFilter.java
incubator/photark/trunk/photark-security/src/main/java/org/apache/photark/security/authorization/services/SecurityServiceImpl.java
incubator/photark/trunk/photark-ui-admin/src/main/webapp/admin/js/admin.js
incubator/photark/trunk/photark-ui-admin/src/main/webapp/admin/upload.html
incubator/photark/trunk/photark-ui-security/src/main/webapp/home/registration.html
incubator/photark/trunk/photark-ui/src/main/webapp/gallery.html
incubator/photark/trunk/photark-ui/src/main/webapp/js/gallery.js
Modified: incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRAlbumImpl.java
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRAlbumImpl.java?rev=954241&r1=954240&r2=954241&view=diff
==============================================================================
--- incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRAlbumImpl.java (original)
+++ incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRAlbumImpl.java Sun Jun 13 15:21:01 2010
@@ -203,7 +203,7 @@ public class JCRAlbumImpl implements Alb
while (nodes.hasNext()) {
Node node = nodes.nextNode();
- if (node.getPath().equals("/jcr:system"))
+ if (node.getPath().equals("/jcr:system")||node.getPath().equals("/userStore"))
continue;
pictures.add(node.getProperty("location").getString());
}
Modified: incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRGalleryImpl.java
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRGalleryImpl.java?rev=954241&r1=954240&r2=954241&view=diff
==============================================================================
--- incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRGalleryImpl.java (original)
+++ incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRGalleryImpl.java Sun Jun 13 15:21:01 2010
@@ -97,7 +97,7 @@ public class JCRGalleryImpl extends Base
NodeIterator albumNodes = rootNode.getNodes();
while (albumNodes.hasNext()) {
Node albumNode = albumNodes.nextNode();
- if (albumNode.getPath().equals("/jcr:system")) {
+ if (albumNode.getPath().equals("/jcr:system")||albumNode.getPath().equals("/userStore")) {
continue;
}
String albumName = albumNode.getName();
Modified: incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRImageUploadServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRImageUploadServiceImpl.java?rev=954241&r1=954240&r2=954241&view=diff
==============================================================================
--- incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRImageUploadServiceImpl.java (original)
+++ incubator/photark/trunk/photark-jcr/src/main/java/org/apache/photark/jcr/services/JCRImageUploadServiceImpl.java Sun Jun 13 15:21:01 2010
@@ -229,8 +229,8 @@ public class JCRImageUploadServiceImpl e
/**
* @param albumName String
- * @param picture Picture
- * @param String albumDescription
+ * @param albumDescription Picture
+ * @param image albumDescription
*/
private void addPictureToAlbum(String albumName,String albumDescription, Image image) {
gallery.addAlbum(albumName);
Modified: incubator/photark/trunk/photark-security/src/main/java/org/apache/photark/security/authentication/AuthorizationFilter.java
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark-security/src/main/java/org/apache/photark/security/authentication/AuthorizationFilter.java?rev=954241&r1=954240&r2=954241&view=diff
==============================================================================
--- incubator/photark/trunk/photark-security/src/main/java/org/apache/photark/security/authentication/AuthorizationFilter.java (original)
+++ incubator/photark/trunk/photark-security/src/main/java/org/apache/photark/security/authentication/AuthorizationFilter.java Sun Jun 13 15:21:01 2010
@@ -63,8 +63,15 @@ public class AuthorizationFilter impleme
HttpServletResponse httpResp = (HttpServletResponse) response;
if (httpReq.getSession().getAttribute("accessList") != null && ! httpReq.getSession().getAttribute("accessList").equals("")) {
- System.err.println(((AccessList)httpReq.getSession().getAttribute("accessList")).getUserId() +" Accessing Admin page");
- chain.doFilter(request, response);
+ if (httpReq.getSession().getAttribute("toRigester") != null
+ && httpReq.getSession().getAttribute("toRigester").equals("true")) {
+ httpResp.sendRedirect(httpReq.getContextPath() + redirectPage);
+ } else{
+ System.err.println(((AccessList)httpReq.getSession().getAttribute("accessList")).getUserId() +" Accessing Admin page");
+ chain.doFilter(request, response);
+ }
+
+
} else {
httpResp.sendRedirect(httpReq.getContextPath() + redirectPage);
}
Modified: incubator/photark/trunk/photark-security/src/main/java/org/apache/photark/security/authorization/services/SecurityServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark-security/src/main/java/org/apache/photark/security/authorization/services/SecurityServiceImpl.java?rev=954241&r1=954240&r2=954241&view=diff
==============================================================================
--- incubator/photark/trunk/photark-security/src/main/java/org/apache/photark/security/authorization/services/SecurityServiceImpl.java (original)
+++ incubator/photark/trunk/photark-security/src/main/java/org/apache/photark/security/authorization/services/SecurityServiceImpl.java Sun Jun 13 15:21:01 2010
@@ -22,7 +22,6 @@ package org.apache.photark.security.auth
import org.apache.photark.security.authorization.AccessList;
import org.apache.photark.security.authorization.User;
import org.apache.photark.security.authorization.UserInfo;
-import org.apache.photark.security.authorization.services.AccessManager;
import org.oasisopen.sca.annotation.Reference;
import org.oasisopen.sca.annotation.Scope;
import org.oasisopen.sca.annotation.Service;
@@ -40,52 +39,55 @@ import java.io.PrintWriter;
@Scope("COMPOSITE")
public class SecurityServiceImpl extends HttpServlet implements Servlet /*SecurityService*/ {
- /**
- *
- */
- private static final long serialVersionUID = -6452934544772432330L;
- private AccessManager accessManager;
-
- @Reference(name="accessmanager")
- protected void setAccessService(AccessManager accessManager) {
- this.accessManager = accessManager;
- }
-
- @Override
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- response.setContentType("text/html");
- doPost( request, response);
- }
-
- @Override
- public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
- response.setContentType("text/html");
- AccessList accessList= (AccessList)request.getSession().getAttribute("accessList");
- StringBuffer sb = new StringBuffer();
- String userId= accessList.getUserId();
- User user ;
-
- if("get".equalsIgnoreCase(request.getParameter("userInfo"))){
-
- user = accessManager.getUser(userId);
- UserInfo userInfo= user.getUserInfo();
- if(accessManager.isUserStoredInRole(userId, "registeredUserRole")){
+ /**
+ *
+ */
+ private static final long serialVersionUID = -6452934544772432330L;
+ private AccessManager accessManager;
+
+ @Reference(name = "accessmanager")
+ protected void setAccessService(AccessManager accessManager) {
+ this.accessManager = accessManager;
+ }
+
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ response.setContentType("text/html");
+ doPost(request, response);
+ }
+
+ @Override
+ public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ response.setContentType("text/html");
+
+ StringBuffer sb = new StringBuffer();
+
+ if ("getUserInfo".equalsIgnoreCase(request.getParameter("request"))) {
+ AccessList accessList = (AccessList) request.getSession().getAttribute("accessList");
+ String userId = accessList.getUserId();
+ User user;
+ user = accessManager.getUser(userId);
+ UserInfo userInfo = user.getUserInfo();
+ if (accessManager.isUserStoredInRole(userId, "registeredUserRole")) {
request.getSession().setAttribute("toRigester", "false");
- /* sb.append("userId="+ userId);
- sb.append(",displayName=" + userInfo.getDisplayName());
- sb.append(",email=" + userInfo.getEmail());
- sb.append(",realName=" + userInfo.getRealName());
- sb.append(",webSite=" + userInfo.getWebsite());*/
+ /* sb.append("userId="+ userId);
+ sb.append(",displayName=" + userInfo.getDisplayName());
+ sb.append(",email=" + userInfo.getEmail());
+ sb.append(",realName=" + userInfo.getRealName());
+ sb.append(",webSite=" + userInfo.getWebsite());*/
sb.append("registered,").append(userId).append(",").append(userInfo.getRealName()).append(",").append(userInfo.getDisplayName()).append(",").append(userInfo.getEmail()).append(",").append(userInfo.getWebsite());
- }else {
- /*sb.append("userId="+ userId);
- sb.append(",unRegistered=false");*/
+ } else {
+ /*sb.append("userId="+ userId);
+ sb.append(",unRegistered=false");*/
sb.append("unRegistered,").append(userId).append(",").append(userInfo.getRealName()).append(",").append(userInfo.getDisplayName()).append(",").append(userInfo.getEmail()).append(",").append(userInfo.getWebsite());
- }
+ }
- }else if("set".equalsIgnoreCase(request.getParameter("userInfo"))){
- if(request.getParameter("displayName") !=null&& !request.getParameter("displayName").trim().equals("")){
+ } else if ("setUserInfo".equalsIgnoreCase(request.getParameter("request"))) {
+ AccessList accessList = (AccessList) request.getSession().getAttribute("accessList");
+ String userId = accessList.getUserId();
+ User user;
+ if (request.getParameter("displayName") != null && !request.getParameter("displayName").trim().equals("")) {
request.getSession().setAttribute("toRigester", "false");
user = new User(userId);
UserInfo userInfo = new UserInfo(request.getParameter("displayName"),
@@ -94,20 +96,55 @@ public class SecurityServiceImpl extends
request.getParameter("webSite"));
user.setUserInfo(userInfo);
- if(accessManager.isUserStoredInRole(userId, "unRegisteredUserRole")){
- accessManager.removeUserFromRole(userId,"unRegisteredUserRole");
+ if (accessManager.isUserStoredInRole(userId, "unRegisteredUserRole")) {
+ accessManager.removeUserFromRole(userId, "unRegisteredUserRole");
}
- if(!accessManager.isUserStoredInRole(userId, "registeredUserRole")){
- accessManager.addUserToRole(user,"registeredUserRole");
+ if (!accessManager.isUserStoredInRole(userId, "registeredUserRole")) {
+ accessManager.addUserToRole(user, "registeredUserRole");
}
//sb.append("userId="+ userId);
//sb.append(",unRegistered=false");
}
- }
- PrintWriter out = response.getWriter();
- out.write(sb.toString());
- out.flush();
- out.close();
+ } else if ("getUser".equalsIgnoreCase(request.getParameter("request"))) {
+ if (request.getSession().getAttribute("accessList") != null && request.getSession().getAttribute("accessList") != "") {
+
+ AccessList accessList = (AccessList) request.getSession().getAttribute("accessList");
+
+ String userId = accessList.getUserId();
+ if(userId.equals("SuperAdmin")){
+
+ sb.append("{user:{userId:'" + userId +
+ "',userInfo:{realName:'" +
+ "',displayName:'"+userId +
+ "',email:'" +
+ "',website:'" + "'}}}");
+
+ } else{
+ User user;
+ user = accessManager.getUser(userId);
+ UserInfo userInfo = user.getUserInfo();
+
+ /* sb.append("userId="+ userId);
+ sb.append(",displayName=" + userInfo.getDisplayName());
+ sb.append(",email=" + userInfo.getEmail());
+ sb.append(",realName=" + userInfo.getRealName());
+ sb.append(",webSite=" + userInfo.getWebsite());*/
+ sb.append("{user:{userId:'" + userId +
+ "',userInfo:{realName:'" + userInfo.getRealName() +
+ "',displayName:'" + userInfo.getDisplayName() +
+ "',email:'" + userInfo.getEmail() +
+ "',website:'" + userInfo.getWebsite() + "'}}}");
+ }
+
+
+ }else{
+ sb.append("{user:{userId:'null'}}");
+ }
+ }
+ PrintWriter out = response.getWriter();
+ out.write(sb.toString());
+ out.flush();
+ out.close();
- }
+ }
}
Modified: incubator/photark/trunk/photark-ui-admin/src/main/webapp/admin/js/admin.js
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark-ui-admin/src/main/webapp/admin/js/admin.js?rev=954241&r1=954240&r2=954241&view=diff
==============================================================================
--- incubator/photark/trunk/photark-ui-admin/src/main/webapp/admin/js/admin.js (original)
+++ incubator/photark/trunk/photark-ui-admin/src/main/webapp/admin/js/admin.js Sun Jun 13 15:21:01 2010
@@ -195,7 +195,35 @@ var r;
}
}
+
+function populateUserInfo() {
+ dojo.xhrPost({
+ url:"../security", //photark.constants.SecurityEndpoint,
+ content:{request:"getUser"},
+ handleAs: "json",
+ load: function(response, ioArgs) {
+ displayLoginLinks(response);
+ },
+ error: function(response, ioArgs) {
+ console.error("Error in getting user info");
+ }
+ });
+ }
+
+function displayLoginLinks (response) {
+ if(response!=null&&response.user.userId!="null"){
+ var displayName = response.user.userInfo.displayName;
+
+ document.getElementById("loginName").innerHTML="<b>"+displayName+"</b>" ;
+ } else {
+ document.getElementById("loginName").innerHTML="";
+ }
+
+
+}
dojo.addOnLoad( function() {
+ dojo.addOnLoad(populateUserInfo);
populateSelect();
+
});
Modified: incubator/photark/trunk/photark-ui-admin/src/main/webapp/admin/upload.html
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark-ui-admin/src/main/webapp/admin/upload.html?rev=954241&r1=954240&r2=954241&view=diff
==============================================================================
--- incubator/photark/trunk/photark-ui-admin/src/main/webapp/admin/upload.html (original)
+++ incubator/photark/trunk/photark-ui-admin/src/main/webapp/admin/upload.html Sun Jun 13 15:21:01 2010
@@ -40,7 +40,7 @@
<fieldset id="newAlbumDetails" style="text-align:left;">
<legend>Album Details</legend>
<div style="float:right;width:50%;font-size:0.8em;text-align:right;">
- <div><span><a href="../">Gallery</a></span> <span><a href="../logout/">Logout</a></span></div>
+ <div><span id="loginName"></span> <span><a href="../">Gallery</a></span> <span><a href="../logout/">Logout</a></span></div>
</div>
<div style="clear:both"></div>
<ol>
Modified: incubator/photark/trunk/photark-ui-security/src/main/webapp/home/registration.html
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark-ui-security/src/main/webapp/home/registration.html?rev=954241&r1=954240&r2=954241&view=diff
==============================================================================
--- incubator/photark/trunk/photark-ui-security/src/main/webapp/home/registration.html (original)
+++ incubator/photark/trunk/photark-ui-security/src/main/webapp/home/registration.html Sun Jun 13 15:21:01 2010
@@ -35,7 +35,7 @@
function populateInfo() {
dojo.xhrPost({
url:"../security", //photark.constants.SecurityEndpoint,
- content:{userInfo:"get"},
+ content:{request:"getUserInfo"},
handleAs: "text",
load: function(response, ioArgs) {
setUserInfo(response);
@@ -56,7 +56,7 @@
document.getElementById('email').value = array[4];
document.getElementById('webSite').value = array[5];
} else {
- window.location = "/photark/home/registration.html"
+ window.location = "authenticate"
}
}
@@ -96,23 +96,25 @@
function set() {
dojo.xhrPost({
url:"../security", //photark.constants.SecurityEndpoint,
- content:{userInfo:"set",
+ content:{request:"setUserInfo",
realName:document.getElementById('realName').value,
displayName:document.getElementById('displayName').value,
email:document.getElementById('email').value,
webSite:document.getElementById('webSite').value},
handleAs: "text",
load: function(response, ioArgs) {
- window.location = "/photark/home/registration.html"
+ window.location = "authenticate"
},
error: function(response, ioArgs) {
console.error("Error in getting user info");
- window.location = "../logout";
+ logout();
}
});
}
-
+ function logout(){
+ window.location = "../logout";
+ }
</script>
<style type="text/css">
@@ -135,7 +137,7 @@
<div id="container" style="margin-left:5px">
<div style="float:right;width:50%;font-size:0.7em;text-align:right;">
- <div><span><a href="../">Gallery</a></span></div>
+ <div><span><a href="../logout">Gallery</a></span></div>
</div>
<p>Get <span style="color:orange">registered</span> with PhotArk</p>
@@ -179,7 +181,7 @@
</td>
<td>
<button id="submit" type="button" onclick="save()" style="margin-right:5px">Register</button>
- <button id="cancel" type="button" onclick="redirect()">Cancel</button>
+ <button id="cancel" type="button" onclick="logout()">Cancel</button>
</td>
</tr>
</table>
Modified: incubator/photark/trunk/photark-ui/src/main/webapp/gallery.html
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark-ui/src/main/webapp/gallery.html?rev=954241&r1=954240&r2=954241&view=diff
==============================================================================
--- incubator/photark/trunk/photark-ui/src/main/webapp/gallery.html (original)
+++ incubator/photark/trunk/photark-ui/src/main/webapp/gallery.html Sun Jun 13 15:21:01 2010
@@ -33,7 +33,7 @@
<body onload="initGallery()">
<div style="float:right;width:50%;font-size:1em;text-align:right;">
<div> </div>
- <div><span><a href="./admin/authenticate"><u>Super Admin</u></a></span> <span><a href="./home/authenticate"><u>login</u></a></span> <span><a href="./logout/"><u>logout</u></a></span></div>
+ <div id="loginLinks"><span><a href="./admin/authenticate"><u>Super admin</u></a></span> <span><a href="./home/authenticate"><u>Login</u></a></span> <span><a href="./logout/"><u>Logout</u></a></span></div>
</div>
<div style="clear:both"></div>
<div>
Modified: incubator/photark/trunk/photark-ui/src/main/webapp/js/gallery.js
URL: http://svn.apache.org/viewvc/incubator/photark/trunk/photark-ui/src/main/webapp/js/gallery.js?rev=954241&r1=954240&r2=954241&view=diff
==============================================================================
--- incubator/photark/trunk/photark-ui/src/main/webapp/js/gallery.js (original)
+++ incubator/photark/trunk/photark-ui/src/main/webapp/js/gallery.js Sun Jun 13 15:21:01 2010
@@ -42,7 +42,9 @@ var slideShowSpeed=0;
var timer;
dojo.addOnLoad(function() {
+ dojo.require("dojo._base.xhr");
dojo.require("dojo.rpc.JsonService");
+ dojo.addOnLoad(populateUserInfo);
dojo.addOnLoad(initServices);
dojo.addOnLoad(initGallery);
});
@@ -62,6 +64,31 @@ function initGallery() {
}
}
+function populateUserInfo() {
+ dojo.xhrPost({
+ url:"security", //photark.constants.SecurityEndpoint,
+ content:{request:"getUser"},
+ handleAs: "json",
+ load: function(response, ioArgs) {
+ displayLoginLinks(response);
+ },
+ error: function(response, ioArgs) {
+ console.error("Error in getting user info");
+ }
+ });
+ }
+function displayLoginLinks (response) {
+ if(response!=null&&response.user.userId!="null"){
+ var displayName = response.user.userInfo.displayName;
+
+ document.getElementById("loginLinks").innerHTML="Welcome <b>"+displayName+"</b> : <span><a href=\"./admin/upload.html\"><u>Admin page</u></a></span> <span><a href=\"./logout/\"><u>Logout</u></a></span>" ;
+ } else {
+ document.getElementById("loginLinks").innerHTML="<span><a href=\"./admin/authenticate\"><u>Super admin</u></a></span> <span><a href=\"./home/authenticate\"><u>Login</u></a></span>";
+ }
+
+
+}
+
function gallery_getAlbumsResponse(albums, exception) {
if(exception) {
alert(exception.msg);