Skip to content

Commit 42aca8c

Browse files
author
Lloyd Watkin
committed
Merge branch 'master' of github.com:buddycloud/buddycloud-server-java
2 parents d0066ce + bcabf86 commit 42aca8c

File tree

12 files changed

+402
-177
lines changed

12 files changed

+402
-177
lines changed

configuration.properties.example

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
2727
# NOTE: This will only work on local private channels
2828
channels.autosubscribe.autoapprove=false
2929

30-
# Default channels configuration related to access and permissions
31-
channels.default.accessmodel=open
32-
channels.default.role=follower+post
30+
# Channel configuration related to access model and affiliation
31+
32+
channel.configuration.default.accessmodel=open
33+
channel.configuration.default.affiliation=member
34+
35+
# Overrides for default configuration
36+
channel.configuration.posts.affiliation=publisher
37+
38+
channel.configuration.geo.next.accessmodel=authorize
39+
channel.configuration.geo.current.accessmodel=authorize
40+
channel.configuration.geo.previous.accessmodel=authorize
41+
42+
channel.configuration.status.description=%jid%'s status
43+
channel.configuration.status.description=The current status of %jid%

pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
<url>https://github.com/buddycloud/buddycloud-server-java</url>
1111
</scm>
1212
<dependencies>
13+
<dependency>
14+
<groupId>org.xbill</groupId>
15+
<artifactId>dnsjava</artifactId>
16+
<version>2.1.6</version>
17+
</dependency>
1318
<dependency>
1419
<groupId>junit</groupId>
1520
<artifactId>junit</artifactId>
@@ -70,7 +75,7 @@
7075
<groupId>xmlunit</groupId>
7176
<artifactId>xmlunit</artifactId>
7277
<version>1.3</version>
73-
</dependency>
78+
</dependency>
7479
<dependency>
7580
<groupId>xpp3</groupId>
7681
<artifactId>xpp3</artifactId>
298 KB
Binary file not shown.

src/main/java/org/buddycloud/channelserver/Configuration.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ public class Configuration extends Properties {
2828

2929
public static final String CONFIGURATION_CHANNELS_AUTOSUBSCRIBE = "channels.autosubscribe";
3030
public static final String CONFIGURATION_CHANNELS_AUTOSUBSCRIBE_AUTOAPPROVE = "channels.autosubscribe.autoapprove";
31-
public static final String CONFIGURATION_CHANNELS_DEFAULT_ROLE = "channels.default.role";
32-
public static final String CONFIGURATION_CHANNELS_DEFAULT_ACCESSMODEL = "channels.default.accessmodel";
31+
public static final String CONFIGURATION_CHANNELS_DEFAULT_AFFILIATION = "channel.configuration.default.affiliation";
32+
public static final String CONFIGURATION_CHANNELS_DEFAULT_ACCESSMODEL = "channel.configuration.default.accessmodel";
33+
public static final String CONFIGURATION_CHANNELS_DEFAULT_DESCRIPTION = "channel.configuration.default.description";
34+
public static final String CONFIGURATION_CHANNELS_DEFAULT_TITLE = "channel.configuration.default.title";
3335

3436
private static final String CONFIGURATION_FILE = "configuration.properties";
37+
3538
private static Configuration instance = null;
3639

3740
private Collection<JID> adminUsers = new ArrayList<JID>();
@@ -42,14 +45,16 @@ public class Configuration extends Properties {
4245
private Configuration() {
4346
try {
4447
conf = new Properties();
45-
InputStream confFile = this.getClass().getClassLoader().getResourceAsStream(CONFIGURATION_FILE);
46-
if(confFile != null) {
48+
InputStream confFile = this.getClass().getClassLoader()
49+
.getResourceAsStream(CONFIGURATION_FILE);
50+
if (confFile != null) {
4751
load(confFile);
4852
LOGGER.info("Loaded " + CONFIGURATION_FILE + " from classpath.");
4953
} else {
5054
File f = new File(CONFIGURATION_FILE);
5155
load(new FileInputStream(f));
52-
LOGGER.info("Loaded " + CONFIGURATION_FILE + " from working directory.");
56+
LOGGER.info("Loaded " + CONFIGURATION_FILE
57+
+ " from working directory.");
5358
}
5459
} catch (Exception e) {
5560
LOGGER.error("Could not load " + CONFIGURATION_FILE + "!");
@@ -125,20 +130,21 @@ public String getServerTopicsDomain() {
125130
return getProperty(CONFIGURATION_SERVER_TOPICS_DOMAIN);
126131
}
127132

128-
public boolean getBooleanProperty(
129-
final String key, final boolean defaultValue) {
133+
public boolean getBooleanProperty(final String key,
134+
final boolean defaultValue) {
130135
String value = getProperty(key);
131-
132-
if(value != null) {
133-
if(value.equalsIgnoreCase("true")) {
136+
137+
if (value != null) {
138+
if (value.equalsIgnoreCase("true")) {
134139
return true;
135140
}
136-
if(value.equalsIgnoreCase("false")) {
141+
if (value.equalsIgnoreCase("false")) {
137142
return false;
138143
}
139-
LOGGER.warn("Invalid boolean property value for " + key + ": " + value);
144+
LOGGER.warn("Invalid boolean property value for " + key + ": "
145+
+ value);
140146
}
141-
147+
142148
return defaultValue;
143149
}
144150
}

src/main/java/org/buddycloud/channelserver/channel/Conf.java

Lines changed: 116 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,40 +28,45 @@ public class Conf {
2828
public static final String NOTIFY_CONFIG = "pubsub#notify_config";
2929
public static final String CHANNEL_TYPE = "buddycloud#channel_type";
3030
private static final String PUBLISHERS = "publishers";
31-
public static final DateTimeFormatter ISO_8601_PARSER = ISODateTimeFormat.dateTimeParser();
32-
public static final DateTimeFormatter ISO_8601_FORMATTER = ISODateTimeFormat.dateTime();
31+
public static final DateTimeFormatter ISO_8601_PARSER = ISODateTimeFormat
32+
.dateTimeParser();
33+
public static final DateTimeFormatter ISO_8601_FORMATTER = ISODateTimeFormat
34+
.dateTime();
35+
36+
private static Configuration projectConf;
37+
private static HashMap<String, String> conf;
3338

3439
public static String getPostChannelNodename(JID channelJID) {
3540
return "/user/" + channelJID.toBareJID() + "/posts";
3641
}
3742

3843
/**
3944
* Parses a ISO 8601 to a string
40-
*
45+
*
4146
* @param iso8601Str
4247
* @return
43-
* @throws IllegalArgumentException if the provided string is not ISO 8601
48+
* @throws IllegalArgumentException
49+
* if the provided string is not ISO 8601
4450
*/
45-
public static Date parseDate(String iso8601Str) throws IllegalArgumentException {
51+
public static Date parseDate(String iso8601Str)
52+
throws IllegalArgumentException {
4653
return ISO_8601_PARSER.parseDateTime(iso8601Str).toDate();
4754
}
4855

4956
public static String formatDate(Date date) {
5057
return ISO_8601_FORMATTER.print(date.getTime());
5158
}
5259

53-
public static HashMap<String, String> getDefaultChannelConf(JID channelJID, JID ownerJID) {
54-
HashMap<String, String> conf = getDefaultConf(channelJID);
55-
conf.put(TITLE, channelJID.toBareJID() + "'s title");
56-
conf.put(DESCRIPTION, channelJID.toBareJID() + "'s description");
60+
public static HashMap<String, String> getDefaultChannelConf(JID channelJID,
61+
JID ownerJID) {
62+
HashMap<String, String> conf = getDefaultConf(channelJID, null);
5763
conf.put(OWNER, ownerJID.toBareJID());
5864
return conf;
5965
}
6066

61-
public static HashMap<String, String> getDefaultPostChannelConf(JID channelJID) {
62-
HashMap<String, String> conf = getDefaultConf(channelJID);
63-
conf.put(TITLE, channelJID.toBareJID() + "'s very own buddycloud channel!");
64-
conf.put(DESCRIPTION, "This channel belongs to " + channelJID.toBareJID() + ". To nobody else!");
67+
public static HashMap<String, String> getDefaultPostChannelConf(
68+
JID channelJID) {
69+
HashMap<String, String> conf = getDefaultConf(channelJID, "posts");
6570
conf.put(CHANNEL_TYPE, "personal");
6671
return conf;
6772
}
@@ -70,71 +75,141 @@ public static String getStatusChannelNodename(JID channelJID) {
7075
return "/user/" + channelJID.toBareJID() + "/status";
7176
}
7277

73-
public static HashMap<String, String> getDefaultStatusChannelConf(JID channelJID) {
74-
HashMap<String, String> conf = getDefaultConf(channelJID);
75-
conf.put(TITLE, channelJID.toBareJID() + "'s very own buddycloud status!");
76-
conf.put(DESCRIPTION, "This is " + channelJID.toBareJID() + "'s mood a.k.a status -channel. Depends how geek you are.");
78+
public static HashMap<String, String> getDefaultStatusChannelConf(
79+
JID channelJID) {
80+
HashMap<String, String> conf = getDefaultConf(channelJID, "status");
7781
return conf;
7882
}
7983

8084
public static String getGeoPreviousChannelNodename(JID channelJID) {
8185
return "/user/" + channelJID.toBareJID() + "/geo/previous";
8286
}
8387

84-
public static HashMap<String, String> getDefaultGeoPreviousChannelConf(JID channelJID) {
85-
HashMap<String, String> conf = getDefaultConf(channelJID);
86-
conf.put(TITLE, channelJID.toBareJID() + "'s previous location.");
87-
conf.put(DESCRIPTION, "Where " + channelJID.toBareJID() + " has been before.");
88+
public static HashMap<String, String> getDefaultGeoPreviousChannelConf(
89+
JID channelJID) {
90+
HashMap<String, String> conf = getDefaultConf(channelJID,
91+
"geo/previous");
8892
return conf;
8993
}
9094

9195
public static String getGeoCurrentChannelNodename(JID channelJID) {
9296
return "/user/" + channelJID.toBareJID() + "/geo/current";
9397
}
9498

95-
public static HashMap<String, String> getDefaultGeoCurrentChannelConf(JID channelJID) {
96-
HashMap<String, String> conf = getDefaultConf(channelJID);
97-
conf.put(TITLE, channelJID.toBareJID() + "'s current location.");
98-
conf.put(DESCRIPTION, "Where " + channelJID.toBareJID() + " is now.");
99+
public static HashMap<String, String> getDefaultGeoCurrentChannelConf(
100+
JID channelJID) {
101+
HashMap<String, String> conf = getDefaultConf(channelJID, "geo/current");
99102
return conf;
100103
}
101104

102105
public static String getGeoNextChannelNodename(JID channelJID) {
103106
return "/user/" + channelJID.toBareJID() + "/geo/next";
104107
}
105108

106-
public static HashMap<String, String> getDefaultGeoNextChannelConf(JID channelJID) {
107-
HashMap<String, String> conf = getDefaultConf(channelJID);
108-
conf.put(TITLE, channelJID.toBareJID() + "'s next location.");
109-
conf.put(DESCRIPTION, "Where " + channelJID.toBareJID() + " is going to go.");
109+
public static HashMap<String, String> getDefaultGeoNextChannelConf(
110+
JID channelJID) {
111+
HashMap<String, String> conf = getDefaultConf(channelJID, "geo/next");
110112
return conf;
111113
}
112114

113115
public static String getSubscriptionsChannelNodename(JID channelJID) {
114116
return "/user/" + channelJID.toBareJID() + "/subscriptions";
115117
}
116118

117-
public static HashMap<String, String> getDefaultSubscriptionsChannelConf(JID channelJID) {
118-
HashMap<String, String> conf = getDefaultConf(channelJID);
119-
conf.put(TITLE, channelJID.toBareJID() + "'s susbcriptions.");
120-
conf.put(DESCRIPTION, channelJID.toBareJID() + "'s subscriptions. ");
119+
public static HashMap<String, String> getDefaultSubscriptionsChannelConf(
120+
JID channelJID) {
121+
HashMap<String, String> conf = getDefaultConf(channelJID,
122+
"subscriptions");
121123
return conf;
122124
}
123125

124-
private static HashMap<String, String> getDefaultConf(JID channelJID) {
125-
HashMap<String, String> conf = new HashMap<String, String>();
126-
Configuration projectConf = Configuration.getInstance();
126+
private static HashMap<String, String> getDefaultConf(JID channelJID,
127+
String node) {
128+
129+
conf = new HashMap<String, String>();
130+
projectConf = Configuration.getInstance();
131+
conf.put(
132+
TITLE,
133+
projectConf.getProperty(
134+
Configuration.CONFIGURATION_CHANNELS_DEFAULT_TITLE,
135+
"%jid%'s very own buddycloud channel").replace("%jid%",
136+
channelJID.toBareJID()));
137+
138+
conf.put(
139+
DESCRIPTION,
140+
projectConf
141+
.getProperty(
142+
Configuration.CONFIGURATION_CHANNELS_DEFAULT_DESCRIPTION,
143+
"%jid%'s very own buddycloud channel").replace(
144+
"%jid%", channelJID.toBareJID()));
145+
127146
conf.put(TYPE, "http://www.w3.org/2005/Atom");
128147
conf.put(PUBLISH_MODEL, PUBLISHERS);
129148
conf.put(CREATION_DATE, formatDate(new Date()));
130149
conf.put(OWNER, channelJID.toBareJID());
131-
conf.put(ACCESS_MODEL, AccessModels.createFromString(projectConf.getProperty(
132-
Configuration.CONFIGURATION_CHANNELS_DEFAULT_ACCESSMODEL)).toString());
133-
conf.put(DEFAULT_AFFILIATION, Affiliations.createFromBuddycloudString(
134-
projectConf.getProperty(Configuration.CONFIGURATION_CHANNELS_DEFAULT_ROLE))
135-
.toString());
150+
151+
conf.put(
152+
ACCESS_MODEL,
153+
AccessModels
154+
.createFromString(
155+
projectConf
156+
.getProperty(
157+
Configuration.CONFIGURATION_CHANNELS_DEFAULT_ACCESSMODEL,
158+
AccessModels.open.toString()))
159+
.toString());
160+
conf.put(
161+
DEFAULT_AFFILIATION,
162+
Affiliations
163+
.createFromString(
164+
projectConf
165+
.getProperty(
166+
Configuration.CONFIGURATION_CHANNELS_DEFAULT_AFFILIATION,
167+
Affiliations.member.toString()))
168+
.toString());
136169
conf.put(NUM_SUBSCRIBERS, "1");
137170
conf.put(NOTIFY_CONFIG, "1");
171+
172+
getConfigurationOverrides(channelJID, node);
138173
return conf;
139174
}
175+
176+
private static void getConfigurationOverrides(JID channelJID, String node) {
177+
178+
if (null == node)
179+
return;
180+
181+
String accessModelKey = Configuration.CONFIGURATION_CHANNELS_DEFAULT_ACCESSMODEL
182+
.replace("default", node.replace("/", "."));
183+
if (null != projectConf.getProperty(accessModelKey)) {
184+
conf.put(
185+
ACCESS_MODEL,
186+
AccessModels.createFromString(
187+
projectConf.getProperty(accessModelKey)).toString());
188+
}
189+
190+
String affiliationKey = Configuration.CONFIGURATION_CHANNELS_DEFAULT_AFFILIATION
191+
.replace("default", node.replace("/", "."));
192+
if (null != projectConf.getProperty(affiliationKey)) {
193+
conf.put(
194+
DEFAULT_AFFILIATION,
195+
Affiliations.createFromString(
196+
projectConf.getProperty(affiliationKey)).toString());
197+
}
198+
String titleKey = Configuration.CONFIGURATION_CHANNELS_DEFAULT_TITLE
199+
.replace("default", node.replace("/", "."));
200+
201+
if (null != projectConf.getProperty(titleKey)) {
202+
String title = projectConf.getProperty(titleKey).replace("%jid%",
203+
channelJID.toBareJID());
204+
conf.put(TITLE, title);
205+
}
206+
String descriptionKey = Configuration.CONFIGURATION_CHANNELS_DEFAULT_DESCRIPTION
207+
.replace("default", node.replace("/", "."));
208+
if (null != projectConf.getProperty(descriptionKey)) {
209+
String description = projectConf.getProperty(descriptionKey)
210+
.replace("%jid%", channelJID.toBareJID());
211+
conf.put(DESCRIPTION, description);
212+
}
213+
214+
}
140215
}

src/main/java/org/buddycloud/channelserver/packetprocessor/iq/IQProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void process(IQ packet) throws Exception {
6060
try {
6161
processPacket(packet);
6262
} catch (Exception e) {
63-
if (true == packet.getType().toString().equals("result")) return;
63+
if (packet.getType().equals(IQ.Type.result) || packet.getType().equals(IQ.Type.error)) return;
6464
IQ reply = IQ.createResultIQ(packet);
6565
reply.setChildElement(packet.getChildElement().createCopy());
6666
reply.setType(Type.error);
@@ -101,7 +101,7 @@ private void processPacket(IQ packet) throws Exception,
101101
}
102102
logger.debug("Couldn't find processor for packet");
103103

104-
if (packet.getType() == IQ.Type.set || packet.getType() == IQ.Type.get) {
104+
if (packet.getType().equals(IQ.Type.set) || packet.getType().equals(IQ.Type.get)) {
105105

106106
IQ reply = IQ.createResultIQ(packet);
107107
reply.setChildElement(packet.getChildElement().createCopy());

src/main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/SubscribeSet.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ public void process(Element elm, JID actorJID, IQ reqIQ, Element rsm)
126126
return;
127127
}
128128

129-
Affiliations defaultAffiliation = null;
130-
Subscriptions defaultSubscription = null;
129+
Affiliations defaultAffiliation = Affiliations.member;
130+
Subscriptions defaultSubscription = Subscriptions.none;
131131

132132
if (!possibleExistingSubscription.in(Subscriptions.none) &&
133133
!possibleExistingAffiliation.in(Affiliations.none)) {
@@ -138,16 +138,17 @@ public void process(Element elm, JID actorJID, IQ reqIQ, Element rsm)
138138
defaultSubscription = possibleExistingSubscription;
139139
} else {
140140
try {
141-
String nodeDefAffiliation = nodeConf.get(Conf.DEFAULT_AFFILIATION);
142-
LOGGER.debug("Node default affiliation: '" + nodeDefAffiliation + "'");
143-
defaultAffiliation = Affiliations.createFromString(nodeDefAffiliation);
141+
String nodeDefaultAffiliation = nodeConf.get(Conf.DEFAULT_AFFILIATION);
142+
LOGGER.debug("Node default affiliation: '" + nodeDefaultAffiliation + "'");
143+
if (!Affiliations.none.equals(Affiliations.createFromString(nodeDefaultAffiliation))) {
144+
defaultAffiliation = Affiliations.createFromString(nodeDefaultAffiliation);
145+
}
144146
} catch (NullPointerException e) {
145147
LOGGER.error("Could not create affiliation.", e);
146148
defaultAffiliation = Affiliations.member;
147149
}
148150
defaultSubscription = Subscriptions.subscribed;
149151
String accessModel = nodeConf.get(Conf.ACCESS_MODEL);
150-
151152
if ((null == accessModel)
152153
|| (true == accessModel.equals(AccessModels.authorize
153154
.toString()))

0 commit comments

Comments
 (0)