Skip to content

Commit d1788c4

Browse files
committed
Merge branch 'master' into recent-items-rsm
2 parents 992cf43 + e36d711 commit d1788c4

8 files changed

Lines changed: 333 additions & 125 deletions

File tree

configuration.properties.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ users.admin = user1@example.com;crawler@searchengine.org
2121
# A list of channels (local or remote) to which to subscribe new users
2222
# Note that the channels will not be created - they must already exist
2323
channels.autosubscribe=lounge@example.com;welcome@example.com
24+
25+
# If any of the 'channels.autosubscribe' channels are private local channels,
26+
# then whether to automatically approve the user.
27+
# NOTE: This will only work on local private channels
28+
channels.autosubscribe.autoapprove=false

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

Lines changed: 115 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -13,118 +13,134 @@
1313
import org.apache.log4j.Logger;
1414
import org.xmpp.packet.JID;
1515

16-
public class Configuration extends Properties
17-
{
16+
public class Configuration extends Properties {
1817
private static final Logger LOGGER = Logger.getLogger(Configuration.class);
19-
18+
2019
private static final long serialVersionUID = 1L;
21-
20+
2221
private static final String ARRAY_PROPERTY_SEPARATOR = ";";
2322

2423
public static final String CONFIGURATION_SERVER_DOMAIN = "server.domain";
2524
public static final String CONFIGURATION_SERVER_CHANNELS_DOMAIN = "server.domain.channels";
2625
public static final String CONFIGURATION_SERVER_TOPICS_DOMAIN = "server.domain.topics";
27-
26+
2827
public static final String CONFIGURATION_ADMIN_USERS = "users.admin";
2928

3029
public static final String CONFIGURATION_CHANNELS_AUTOSUBSCRIBE = "channels.autosubscribe";
31-
30+
public static final String CONFIGURATION_CHANNELS_AUTOSUBSCRIBE_AUTOAPPROVE = "channels.autosubscribe.autoapprove";
31+
3232
private static final String CONFIGURATION_FILE = "configuration.properties";
33-
private static Configuration instance = null;
34-
33+
private static Configuration instance = null;
34+
3535
private Collection<JID> adminUsers = new ArrayList<JID>();
3636
private Collection<JID> autosubscribeChannels = new ArrayList<JID>();
37-
37+
3838
private Properties conf;
39-
40-
private Configuration()
41-
{
42-
try {
43-
conf = new Properties();
44-
File f = new File(CONFIGURATION_FILE);
45-
46-
if(f.exists()) {
47-
LOGGER.info("Found " + CONFIGURATION_FILE + " in working directory.");
48-
load(new FileInputStream(f));
49-
} else {
50-
// Otherwise attempt to load it from the classpath
51-
LOGGER.info("No " + CONFIGURATION_FILE + " found in working directory. Attempting to load from classpath.");
52-
load(this.getClass().getClassLoader().getResourceAsStream(CONFIGURATION_FILE));
53-
}
54-
} catch (Exception e) {
55-
System.out.println(e.getMessage());
56-
System.exit(1);
57-
}
58-
}
59-
60-
private void setupCollections() {
61-
adminUsers = getJIDArrayProperty(CONFIGURATION_ADMIN_USERS);
62-
autosubscribeChannels = getJIDArrayProperty(CONFIGURATION_CHANNELS_AUTOSUBSCRIBE);
39+
40+
private Configuration() {
41+
try {
42+
conf = new Properties();
43+
File f = new File(CONFIGURATION_FILE);
44+
45+
if (f.exists()) {
46+
LOGGER.info("Found " + CONFIGURATION_FILE
47+
+ " in working directory.");
48+
load(new FileInputStream(f));
49+
} else {
50+
// Otherwise attempt to load it from the classpath
51+
LOGGER.info("No "
52+
+ CONFIGURATION_FILE
53+
+ " found in working directory. Attempting to load from classpath.");
54+
load(this.getClass().getClassLoader()
55+
.getResourceAsStream(CONFIGURATION_FILE));
56+
}
57+
} catch (Exception e) {
58+
System.out.println(e.getMessage());
59+
System.exit(1);
60+
}
61+
}
62+
63+
private void setupCollections() {
64+
adminUsers = getJIDArrayProperty(CONFIGURATION_ADMIN_USERS);
65+
autosubscribeChannels = getJIDArrayProperty(CONFIGURATION_CHANNELS_AUTOSUBSCRIBE);
66+
}
67+
68+
public Collection<JID> getAdminUsers() {
69+
return adminUsers;
70+
}
71+
72+
public Collection<JID> getAutosubscribeChannels() {
73+
return autosubscribeChannels;
74+
}
75+
76+
public static Configuration getInstance() {
77+
if (null == instance) {
78+
instance = new Configuration();
79+
}
80+
return instance;
81+
}
82+
83+
public String getProperty(String key) {
84+
return conf.getProperty(key);
85+
}
86+
87+
public String getProperty(String key, String defaultValue) {
88+
return conf.getProperty(key, defaultValue);
89+
}
90+
91+
public void load(InputStream inputStream) throws IOException {
92+
conf.load(inputStream);
93+
setupCollections();
94+
}
95+
96+
private Collection<String> getStringArrayProperty(String key) {
97+
String prop = getProperty(key);
98+
99+
if (null == prop) {
100+
return Collections.emptyList();
101+
}
102+
103+
return Arrays.asList(prop.split(ARRAY_PROPERTY_SEPARATOR));
104+
}
105+
106+
private Collection<JID> getJIDArrayProperty(String key) {
107+
Collection<String> props = getStringArrayProperty(key);
108+
109+
Collection<JID> jids = new ArrayList<JID>(props.size());
110+
111+
for (String prop : props) {
112+
jids.add(new JID(prop));
113+
}
114+
115+
return jids;
116+
}
117+
118+
public String getServerDomain() {
119+
return getProperty(CONFIGURATION_SERVER_DOMAIN);
120+
}
121+
122+
public String getServerChannelsDomain() {
123+
return getProperty(CONFIGURATION_SERVER_CHANNELS_DOMAIN);
124+
}
125+
126+
public String getServerTopicsDomain() {
127+
return getProperty(CONFIGURATION_SERVER_TOPICS_DOMAIN);
128+
}
129+
130+
public boolean getBooleanProperty(
131+
final String key, final boolean defaultValue) {
132+
String value = getProperty(key);
133+
134+
if(value != null) {
135+
if(value.equalsIgnoreCase("true")) {
136+
return true;
137+
}
138+
if(value.equalsIgnoreCase("false")) {
139+
return false;
140+
}
141+
LOGGER.warn("Invalid boolean property value for " + key + ": " + value);
142+
}
143+
144+
return defaultValue;
63145
}
64-
65-
public Collection<JID> getAdminUsers() {
66-
return adminUsers;
67-
}
68-
69-
public Collection<JID> getAutosubscribeChannels() {
70-
return autosubscribeChannels;
71-
}
72-
73-
public static Configuration getInstance()
74-
{
75-
if (null == instance) {
76-
instance = new Configuration();
77-
}
78-
return instance;
79-
}
80-
81-
public String getProperty(String key)
82-
{
83-
return conf.getProperty(key);
84-
}
85-
86-
public String getProperty(String key, String defaultValue)
87-
{
88-
return conf.getProperty(key, defaultValue);
89-
}
90-
91-
public void load(InputStream inputStream) throws IOException
92-
{
93-
conf.load(inputStream);
94-
setupCollections();
95-
}
96-
97-
private Collection<String> getStringArrayProperty(String key) {
98-
String prop = getProperty(key);
99-
100-
if(null == prop) {
101-
return Collections.emptyList();
102-
}
103-
104-
return Arrays.asList(prop.split(ARRAY_PROPERTY_SEPARATOR));
105-
}
106-
107-
private Collection<JID> getJIDArrayProperty(String key) {
108-
Collection<String> props = getStringArrayProperty(key);
109-
110-
Collection<JID> jids = new ArrayList<JID>(props.size());
111-
112-
for(String prop : props) {
113-
jids.add(new JID(prop));
114-
}
115-
116-
return jids;
117-
}
118-
119-
public String getServerDomain() {
120-
return getProperty(CONFIGURATION_SERVER_DOMAIN);
121-
}
122-
123-
public String getServerChannelsDomain() {
124-
return getProperty(CONFIGURATION_SERVER_CHANNELS_DOMAIN);
125-
}
126-
127-
public String getServerTopicsDomain() {
128-
return getProperty(CONFIGURATION_SERVER_TOPICS_DOMAIN);
129-
}
130146
}

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

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,39 @@
22

33
import org.buddycloud.channelserver.db.NodeStore;
44
import org.buddycloud.channelserver.db.exception.NodeStoreException;
5-
import org.buddycloud.channelserver.pubsub.model.NodeAffiliation;
5+
import org.buddycloud.channelserver.pubsub.affiliation.Affiliations;
66
import org.xmpp.packet.JID;
7-
import org.xmpp.resultsetmanagement.ResultSet;
87

98
public interface ChannelManager extends NodeStore {
10-
9+
1110
/**
1211
* Creates a channel.
13-
* @param channelJID the JID of the channel.
14-
* @throws NodeStoreException
12+
*
13+
* @param channelJID
14+
* the JID of the channel.
15+
* @throws NodeStoreException
1516
*/
1617
void createPersonalChannel(JID ownerJID) throws NodeStoreException;
17-
18+
1819
/**
1920
* Determines whether the node id given refers to a local node.
20-
* @param nodeId the node id
21-
* @return <code>true</code> if the node appears to be local, <code>false</code> otherwise.
22-
* @throws NodeStoreException
21+
*
22+
* @param nodeId
23+
* the node id
24+
* @return <code>true</code> if the node appears to be local,
25+
* <code>false</code> otherwise.
26+
* @throws NodeStoreException
2327
*/
2428
boolean isLocalNode(String nodeId) throws NodeStoreException;
25-
29+
2630
/**
2731
* Determines whether the jid refers to a local user.
28-
* @param jid the user's jid
29-
* @return <code>true</code> if the jid appears to be local, <code>false</code> otherwise.
30-
* @throws NodeStoreException
32+
*
33+
* @param jid
34+
* the user's jid
35+
* @return <code>true</code> if the jid appears to be local,
36+
* <code>false</code> otherwise.
37+
* @throws NodeStoreException
3138
*/
3239
boolean isLocalJID(JID jid) throws NodeStoreException;
3340

@@ -37,4 +44,12 @@ public interface ChannelManager extends NodeStore {
3744
* @throws NodeStoreException
3845
*/
3946
void deleteRemoteData() throws NodeStoreException;
47+
48+
/**
49+
* Gets the default affiliation for a node
50+
* @return
51+
*
52+
* @throws NodeStoreException
53+
*/
54+
Affiliations getDefaultNodeAffiliation(String nodeId) throws NodeStoreException;
4055
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,4 +414,21 @@ public CloseableIterator<NodeItem> getFirehose(int limit,
414414
public int getFirehoseItemCount(boolean isAdmin) throws NodeStoreException {
415415
return nodeStore.getFirehoseItemCount(isAdmin);
416416
}
417+
418+
@Override
419+
public Affiliations getDefaultNodeAffiliation(String nodeId)
420+
throws NodeStoreException {
421+
String affiliationString = getNodeConfValue(nodeId, Conf.DEFAULT_AFFILIATION);
422+
423+
if(affiliationString != null) {
424+
try {
425+
return Affiliations.valueOf(affiliationString);
426+
}
427+
catch(IllegalArgumentException e) {
428+
logger.error("Invalid default affiliation stored for node " + nodeId + ": " + affiliationString, e);
429+
}
430+
}
431+
432+
return Affiliations.member;
433+
}
417434
}

0 commit comments

Comments
 (0)