roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r375629 [2/2] - in /incubator/roller/trunk/sandbox/atomadminprotocol: ./ src/ src/org/ src/org/roller/ src/org/roller/presentation/ src/org/roller/presentation/atomadminapi/ test/
Date Tue, 07 Feb 2006 15:37:04 GMT
Added: incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/WSSEUtilities.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/WSSEUtilities.java?rev=375629&view=auto
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/WSSEUtilities.java
(added)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/WSSEUtilities.java
Tue Feb  7 07:37:00 2006
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2005, Dave Johnson
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.roller.presentation.atomadminapi;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import org.apache.commons.codec.binary.Base64;
+
+/**
+ * Utilties to support WSSE authentication.
+ * @author Dave Johnson
+ */
+class WSSEUtilities {
+    public static synchronized String generateDigest(
+            byte[] nonce, byte[] created, byte[] password) {
+        String result = null;
+        try {
+            MessageDigest digester = MessageDigest.getInstance("SHA");
+            digester.reset();
+            digester.update(nonce);
+            digester.update(created);
+            digester.update(password);
+            byte[] digest = digester.digest();
+            result = new String(base64Encode(digest));
+        }
+        catch (NoSuchAlgorithmException e) {
+            result = null;
+        }
+        return result;
+    }
+    public static byte[] base64Decode(String value) throws IOException {
+        return Base64.decodeBase64(value.getBytes("UTF-8"));
+    }
+    public static String base64Encode(byte[] value) {
+        return new String(Base64.encodeBase64(value));
+    }
+    public static String generateWSSEHeader(String userName, String password) 
+    throws UnsupportedEncodingException {  
+       
+        byte[] nonceBytes = Long.toString(new Date().getTime()).getBytes();
+        String nonce = new String(WSSEUtilities.base64Encode(nonceBytes));
+        
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+        String created = sdf.format(new Date());
+        
+        String digest = WSSEUtilities.generateDigest(
+                nonceBytes, created.getBytes("UTF-8"), password.getBytes("UTF-8"));
+        
+        StringBuffer header = new StringBuffer("UsernameToken Username=\"");
+        header.append(userName);
+        header.append("\", ");
+        header.append("PasswordDigest=\"");
+        header.append(digest);
+        header.append("\", ");
+        header.append("Nonce=\"");
+        header.append(nonce);
+        header.append("\", ");
+        header.append("Created=\"");
+        header.append(created);
+        header.append("\"");
+        return header.toString();
+    }
+}

Added: incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/WeblogEntry.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/WeblogEntry.java?rev=375629&view=auto
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/WeblogEntry.java
(added)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/WeblogEntry.java
Tue Feb  7 07:37:00 2006
@@ -0,0 +1,243 @@
+/*
+ * WeblogEntry.java
+ *
+ * Created on January 17, 2006, 12:44 PM
+ */
+
+package org.roller.presentation.atomadminapi;
+
+import java.util.Date;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.Text;
+import org.roller.pojos.WebsiteData;
+import org.roller.presentation.atomadminapi.Entry.Types;
+
+/**
+ *
+ * @author jtb
+ */
+class WeblogEntry extends Entry {
+    static interface Tags {
+        public static final String WEBLOG = "weblog";
+        public static final String HANDLE = "handle";
+        public static final String NAME = "name";
+        public static final String DESCRIPTION = "description";
+        public static final String LOCALE = "locale";
+        public static final String TIMEZONE = "timezone";
+        public static final String DATE_CREATED = "date-created";
+        public static final String CREATING_USER = "creating-user";
+        public static final String EMAIL_ADDRESS = "email-address";
+    }
+    
+    private String handle;
+    private String name;
+    private String description;
+    private String locale;
+    private String timezone;
+    private Date dateCreated;
+    private String creatingUser;
+    private String emailAddress;
+    
+    public WeblogEntry(Element e, String urlPrefix) throws Exception {
+        // handle
+        Element handleElement = e.getChild(Tags.HANDLE, AtomAdminService.NAMESPACE);
+        if (handleElement == null) {
+            throw new Exception("ERROR: Missing element: " + Tags.HANDLE);
+        }
+        setHandle(handleElement.getText());
+        String href = urlPrefix + "/" + EntrySet.Types.WEBLOGS + "/" + getHandle();     
  
+        setHref(href);        
+        
+        // name
+        Element nameElement = e.getChild(Tags.NAME, AtomAdminService.NAMESPACE);
+        if (nameElement == null) {
+            throw new Exception("ERROR: Missing element: " + Tags.NAME);
+        }
+        setName(nameElement.getText());
+        
+        // description
+        Element descElement = e.getChild(Tags.DESCRIPTION, AtomAdminService.NAMESPACE);
+        if (descElement == null) {
+            throw new Exception("ERROR: Missing element: " + Tags.DESCRIPTION);
+        }
+        setDescription(descElement.getText());
+        
+        // locale
+        Element localeElement = e.getChild(Tags.LOCALE, AtomAdminService.NAMESPACE);
+        if (localeElement == null) {
+            throw new Exception("ERROR: Missing element: " + Tags.LOCALE);
+        }
+        setLocale(localeElement.getText());
+        
+        // timezone
+        Element tzElement = e.getChild(Tags.TIMEZONE, AtomAdminService.NAMESPACE);
+        if (tzElement == null) {
+            throw new Exception("ERROR: Missing element: " + Tags.TIMEZONE);
+        }
+        setTimezone(tzElement.getText());
+        
+        // creator
+        Element creatorElement = e.getChild(Tags.CREATING_USER, AtomAdminService.NAMESPACE);
+        if (creatorElement == null) {
+            throw new Exception("ERROR: Missing element: " + Tags.CREATING_USER);
+        }
+        setCreatingUser(creatorElement.getText());
+        
+        // email address
+        Element emailElement = e.getChild(Tags.EMAIL_ADDRESS, AtomAdminService.NAMESPACE);
+        if (emailElement == null) {
+            throw new Exception("ERROR: Missing element: " + Tags.EMAIL_ADDRESS);
+        }
+        setEmailAddress(emailElement.getText());        
+        
+        // created (optional)
+        Element createdElement = e.getChild(Tags.DATE_CREATED, AtomAdminService.NAMESPACE);
+        if (createdElement != null) {
+            setDateCreated(new Date(Long.valueOf(createdElement.getText()).longValue()));
+        }              
+    }
+    
+    public WeblogEntry(WebsiteData wd, String urlPrefix) {
+        String href = urlPrefix + "/" + EntrySet.Types.WEBLOGS + "/" + wd.getHandle();
+        
+        setHref(href);
+        setHandle(wd.getHandle());
+        setName(wd.getName());
+        setDescription(wd.getDescription());
+        setLocale(wd.getLocale());
+        setTimezone(wd.getTimeZone());
+        setCreatingUser(wd.getCreator().getUserName());
+        setEmailAddress(wd.getEmailAddress());        
+        setDateCreated(wd.getDateCreated());
+    }
+    
+    public String getType() {
+        return Types.WEBLOG;
+    }
+    
+    public Document toDocument() {        
+        Element weblog = new Element(Tags.WEBLOG, AtomAdminService.NAMESPACE);
+        Document doc = new Document(weblog);
+        
+        // link
+        weblog.setAttribute(Attributes.HREF, getHref());
+        
+        // handle
+        Element handle = new Element(Tags.HANDLE, AtomAdminService.NAMESPACE);
+        Text handleText = new Text(getHandle());
+        handle.addContent(handleText);
+        weblog.addContent(handle);
+        
+        // name
+        Element name = new Element(Tags.NAME, AtomAdminService.NAMESPACE);
+        Text nameText = new Text(getName());
+        name.addContent(nameText);
+        weblog.addContent(name);
+        
+        // description
+        Element desc = new Element(Tags.DESCRIPTION, AtomAdminService.NAMESPACE);
+        Text descText = new Text(getDescription());
+        desc.addContent(descText);
+        weblog.addContent(desc);
+        
+        // locale
+        Element locale = new Element(Tags.LOCALE, AtomAdminService.NAMESPACE);
+        Text localeText = new Text(getLocale());
+        locale.addContent(localeText);
+        weblog.addContent(locale);
+        
+        // timezone
+        Element tz = new Element(Tags.TIMEZONE, AtomAdminService.NAMESPACE);
+        Text tzText = new Text(getTimezone());
+        tz.addContent(tzText);
+        weblog.addContent(tz);
+        
+        // creating user
+        Element creator = new Element(Tags.CREATING_USER, AtomAdminService.NAMESPACE);
+        Text creatorText = new Text(String.valueOf(getCreatingUser()));
+        creator.addContent(creatorText);
+        weblog.addContent(creator);
+        
+        // email address
+        Element email = new Element(Tags.EMAIL_ADDRESS, AtomAdminService.NAMESPACE);
+        Text emailText = new Text(String.valueOf(getEmailAddress()));
+        email.addContent(emailText);
+        weblog.addContent(email);        
+        
+        // creation date (optional)
+        Element created = new Element(Tags.DATE_CREATED, AtomAdminService.NAMESPACE);
+        Date datedCreated = getDateCreated();
+        if (dateCreated != null) {
+            Text createdText = new Text(String.valueOf(dateCreated.getTime()));
+            created.addContent(createdText);
+            weblog.addContent(created);
+        }
+        
+        return doc;
+    }    
+    
+    public String getHandle() {
+        return handle;
+    }
+    
+    public void setHandle(String handle) {
+        this.handle = handle;
+    }
+    
+    public String getDescription() {
+        return description;
+    }
+    
+    public void setDescription(String description) {
+        this.description = description;
+    }
+    
+    public String getLocale() {
+        return locale;
+    }
+    
+    public void setLocale(String locale) {
+        this.locale = locale;
+    }
+    
+    public String getTimezone() {
+        return timezone;
+    }
+    
+    public void setTimezone(String timezone) {
+        this.timezone = timezone;
+    }
+    
+    public String getName() {
+        return name;
+    }
+    
+    public void setName(String name) {
+        this.name = name;
+    }
+    
+    public Date getDateCreated() {
+        return dateCreated;
+    }
+    
+    public void setDateCreated(Date dateCreated) {
+        this.dateCreated = dateCreated;
+    }
+    
+    public String getCreatingUser() {
+        return creatingUser;
+    }
+    
+    public void setCreatingUser(String creatingUser) {
+        this.creatingUser = creatingUser;
+    }
+
+    public String getEmailAddress() {
+        return emailAddress;
+    }
+
+    public void setEmailAddress(String emailAddress) {
+        this.emailAddress = emailAddress;
+    }
+}

Added: incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/WeblogEntrySet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/WeblogEntrySet.java?rev=375629&view=auto
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/WeblogEntrySet.java
(added)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/src/org/roller/presentation/atomadminapi/WeblogEntrySet.java
Tue Feb  7 07:37:00 2006
@@ -0,0 +1,84 @@
+/*
+ * WeblogEntrySet.java
+ *
+ * Created on January 17, 2006, 12:44 PM
+ */
+
+package org.roller.presentation.atomadminapi;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.roller.pojos.PermissionsData;
+import org.roller.pojos.UserData;
+import org.roller.pojos.WebsiteData;
+import org.roller.presentation.atomadminapi.EntrySet.Types;
+
+/**
+ * This class describes a set of weblog entries. 
+ * @author jtb
+ */
+class WeblogEntrySet extends EntrySet {
+    static interface Tags {
+        public static final String WEBLOGS = "weblogs";
+    }      
+    
+    public WeblogEntrySet(UserData[] users, String urlPrefix) {
+        if (users == null) {
+            throw new NullPointerException("null users not allowed");
+        }
+        
+        List entries = new ArrayList();        
+        for (int i = 0; i < users.length; i++) {
+            UserData ud = users[i];
+            List permissions = ud.getPermissions();
+            for (Iterator j = permissions.iterator(); j.hasNext(); ) {
+                PermissionsData pd = (PermissionsData)j.next();
+                WebsiteData wd = pd.getWebsite();
+                WeblogEntry entry = new WeblogEntry(wd, urlPrefix);
+                entries.add(entry);
+            }
+        }
+        setEntries((Entry[])entries.toArray(new Entry[0]));
+        setHref(urlPrefix + "/" + Types.WEBLOGS);
+    }
+    
+    public WeblogEntrySet(Document d, String urlPrefix) throws Exception {
+        Element root = d.getRootElement();
+        String rootName = root.getName();
+        if (!rootName.equals(Tags.WEBLOGS)) {
+            throw new Exception("ERROR: Expected root name: " + Tags.WEBLOGS + ", root name
was: " + rootName);
+        }
+        List weblogs = root.getChildren(WeblogEntry.Tags.WEBLOG, AtomAdminService.NAMESPACE);
+        if (weblogs != null) {
+            List entries = new ArrayList();
+            for (Iterator i = weblogs.iterator(); i.hasNext(); ) {
+                Element weblog = (Element)i.next();
+                WeblogEntry entry = new WeblogEntry(weblog, urlPrefix);
+                entries.add(entry);
+            }
+            setEntries((Entry[])entries.toArray(new Entry[0]));
+        }
+        setHref(urlPrefix + "/" + Types.WEBLOGS);
+    }
+    
+    public WeblogEntrySet(WebsiteData[] wds, String urlPrefix) {
+        if (wds == null) {
+            throw new NullPointerException("null website datas not allowed");
+        }
+        
+        List entries = new ArrayList();
+        for (int i = 0; i < wds.length; i++) {
+            WeblogEntry entry = new WeblogEntry(wds[i], urlPrefix);
+            entries.add(entry);
+        }
+        setEntries((Entry[])entries.toArray(new Entry[0]));
+        setHref(urlPrefix + "/" + Types.WEBLOGS);
+    }
+    
+    public String getType() {
+        return Types.WEBLOGS;
+    }    
+}

Added: incubator/roller/trunk/sandbox/atomadminprotocol/test/member-test1.xml
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/test/member-test1.xml?rev=375629&view=auto
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/test/member-test1.xml (added)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/test/member-test1.xml Tue Feb  7 07:37:00
2006
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<members xmlns="http://purl.org/atom/aapp#">
+	<member>
+		<name>test1</name>
+		<handle>test2</handle>
+		<permission>AUTHOR</permission>
+	</member>
+</members>

Added: incubator/roller/trunk/sandbox/atomadminprotocol/test/member-test2.xml
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/test/member-test2.xml?rev=375629&view=auto
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/test/member-test2.xml (added)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/test/member-test2.xml Tue Feb  7 07:37:00
2006
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<members xmlns="http://purl.org/atom/aapp#">
+	<member>
+		<name>test2</name>
+		<handle>test1</handle>
+		<permission>AUTHOR</permission>
+	</member>
+</members>

Added: incubator/roller/trunk/sandbox/atomadminprotocol/test/user-test1.xml
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/test/user-test1.xml?rev=375629&view=auto
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/test/user-test1.xml (added)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/test/user-test1.xml Tue Feb  7 07:37:00
2006
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<users xmlns="http://purl.org/atom/aapp#">
+	<user>
+		<name>test1</name>
+		<full-name>Test One</full-name>
+		<password>test1</password>
+		<locale>en</locale>
+		<timezone>US/Pacific</timezone>
+		<email-address>test1@test.com</email-address>
+	</user>
+</users>

Added: incubator/roller/trunk/sandbox/atomadminprotocol/test/user-test2.xml
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/test/user-test2.xml?rev=375629&view=auto
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/test/user-test2.xml (added)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/test/user-test2.xml Tue Feb  7 07:37:00
2006
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<users xmlns="http://purl.org/atom/aapp#">
+	<user>
+		<name>test2</name>
+		<full-name>Test Two</full-name>
+		<password>test2</password>
+		<locale>en</locale>
+		<timezone>US/Pacific</timezone>
+		<email-address>test2@test.com</email-address>
+	</user>
+</users>

Added: incubator/roller/trunk/sandbox/atomadminprotocol/test/weblog-test1.xml
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/test/weblog-test1.xml?rev=375629&view=auto
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/test/weblog-test1.xml (added)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/test/weblog-test1.xml Tue Feb  7 07:37:00
2006
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<weblogs xmlns="http://purl.org/atom/aapp#">
+	<weblog>
+		<handle>test1</handle>
+		<name>Test 1</name>
+		<description>Test 1</description>
+		<locale>en</locale>
+		<timezone>US/Pacific</timezone>
+		<creating-user>test1</creating-user>
+		<email-address>test1@test.com</email-address>
+	</weblog>
+</weblogs>

Added: incubator/roller/trunk/sandbox/atomadminprotocol/test/weblog-test2.xml
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/sandbox/atomadminprotocol/test/weblog-test2.xml?rev=375629&view=auto
==============================================================================
--- incubator/roller/trunk/sandbox/atomadminprotocol/test/weblog-test2.xml (added)
+++ incubator/roller/trunk/sandbox/atomadminprotocol/test/weblog-test2.xml Tue Feb  7 07:37:00
2006
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<weblogs xmlns="http://purl.org/atom/aapp#">
+	<weblog>
+		<handle>test2</handle>
+		<name>Test 2</name>
+		<description>Test 2</description>
+		<locale>en</locale>
+		<timezone>US/Pacific</timezone>
+		<creating-user>test2</creating-user>
+		<email-address>test2@test.com</email-address>
+	</weblog>
+</weblogs>



Mime
View raw message