📄 externalcomponentmanager.java
字号:
* @param configuration the new configuration for a component.
*/
private static void addConfiguration(ExternalComponentConfiguration configuration) {
// Remove the permission for the entity from the database
java.sql.Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(ADD_CONFIGURATION);
pstmt.setString(1, configuration.getSubdomain());
pstmt.setString(2, configuration.getSecret());
pstmt.setString(3, configuration.getPermission().toString());
pstmt.executeUpdate();
}
catch (SQLException sqle) {
Log.error(sqle);
}
finally {
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
}
/**
* Returns the configuration for an external component.
*
* @param subdomain the subdomain of the external component.
* @return the configuration for an external component.
*/
public static ExternalComponentConfiguration getConfiguration(String subdomain) {
ExternalComponentConfiguration configuration = null;
java.sql.Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(LOAD_CONFIGURATION);
pstmt.setString(1, subdomain);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
configuration = new ExternalComponentConfiguration(subdomain, Permission.valueOf(rs.getString(2)),
rs.getString(1));
}
rs.close();
}
catch (SQLException sqle) {
Log.error(sqle);
}
finally {
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
return configuration;
}
private static Collection<ExternalComponentConfiguration> getConfigurations(
Permission permission) {
Collection<ExternalComponentConfiguration> answer =
new ArrayList<ExternalComponentConfiguration>();
java.sql.Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(LOAD_CONFIGURATIONS);
pstmt.setString(1, permission.toString());
ResultSet rs = pstmt.executeQuery();
ExternalComponentConfiguration configuration;
while (rs.next()) {
configuration = new ExternalComponentConfiguration(rs.getString(1), permission, rs.getString(2));
answer.add(configuration);
}
rs.close();
}
catch (SQLException sqle) {
Log.error(sqle);
}
finally {
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
return answer;
}
/**
* Returns the default secret key to use for those external components that don't have an
* individual configuration.
*
* @return the default secret key to use for those external components that don't have an
* individual configuration.
*/
public static String getDefaultSecret() {
return JiveGlobals.getProperty("xmpp.component.defaultSecret");
}
/**
* Sets the default secret key to use for those external components that don't have an
* individual configuration.
*
* @param defaultSecret the default secret key to use for those external components that
* don't have an individual configuration.
* @throws ModificationNotAllowedException if the operation was denied.
*/
public static void setDefaultSecret(String defaultSecret) throws ModificationNotAllowedException {
// Alert listeners about this event
for (ExternalComponentManagerListener listener : listeners) {
listener.defaultSecretChanged(defaultSecret);
}
JiveGlobals.setProperty("xmpp.component.defaultSecret", defaultSecret);
}
/**
* Returns the shared secret with the specified external component. If no shared secret was
* defined then use the default shared secret.
*
* @param subdomain the subdomain of the external component to get his shared secret.
* (e.g. conference)
* @return the shared secret with the specified external component or the default shared secret.
*/
public static String getSecretForComponent(String subdomain) {
// By default there is no shared secret defined for the XMPP entity
String secret = null;
ExternalComponentConfiguration config = getConfiguration(subdomain);
if (config != null) {
secret = config.getSecret();
}
secret = (secret == null ? getDefaultSecret() : secret);
if (secret == null) {
Log.error("Setup for external components is incomplete. Property " +
"xmpp.component.defaultSecret does not exist.");
}
return secret;
}
/**
* Returns the permission policy being used for new XMPP entities that are trying to
* connect to the server. There are two types of policies: 1) blacklist: where any entity
* is allowed to connect to the server except for those listed in the black list and
* 2) whitelist: where only the entities listed in the white list are allowed to connect to
* the server.
*
* @return the permission policy being used for new XMPP entities that are trying to
* connect to the server.
*/
public static PermissionPolicy getPermissionPolicy() {
try {
return PermissionPolicy.valueOf(JiveGlobals.getProperty("xmpp.component.permission",
PermissionPolicy.blacklist.toString()));
}
catch (Exception e) {
Log.error(e);
return PermissionPolicy.blacklist;
}
}
/**
* Sets the permission policy being used for new XMPP entities that are trying to
* connect to the server. There are two types of policies: 1) blacklist: where any entity
* is allowed to connect to the server except for those listed in the black list and
* 2) whitelist: where only the entities listed in the white list are allowed to connect to
* the server.
*
* @param policy the new PermissionPolicy to use.
* @throws ModificationNotAllowedException if the operation was denied.
*/
public static void setPermissionPolicy(PermissionPolicy policy) throws ModificationNotAllowedException {
// Alert listeners about this event
for (ExternalComponentManagerListener listener : listeners) {
listener.permissionPolicyChanged(policy);
}
JiveGlobals.setProperty("xmpp.component.permission", policy.toString());
// Check if connected components can remain connected to the server
for (ComponentSession session : SessionManager.getInstance().getComponentSessions()) {
for (String domain : session.getExternalComponent().getSubdomains()) {
if (!canAccess(domain)) {
session.close();
break;
}
}
}
}
/**
* Sets the permission policy being used for new XMPP entities that are trying to
* connect to the server. There are two types of policies: 1) blacklist: where any entity
* is allowed to connect to the server except for those listed in the black list and
* 2) whitelist: where only the entities listed in the white list are allowed to connect to
* the server.
*
* @param policy the new policy to use.
* @throws ModificationNotAllowedException if the operation was denied.
*/
public static void setPermissionPolicy(String policy) throws ModificationNotAllowedException {
setPermissionPolicy(PermissionPolicy.valueOf(policy));
}
/**
* Registers a listener to receive events when a configuration change happens. Listeners
* have the chance to deny the operation from happening.
*
* @param listener the listener.
*/
public static void addListener(ExternalComponentManagerListener listener) {
if (listener == null) {
throw new NullPointerException();
}
listeners.add(listener);
}
/**
* Unregisters a listener to receive events.
*
* @param listener the listener.
*/
public static void removeListener(ExternalComponentManagerListener listener) {
listeners.remove(listener);
}
public enum PermissionPolicy {
/**
* Any XMPP entity is allowed to connect to the server except for those listed in
* the <b>not allowed list</b>.
*/
blacklist,
/**
* Only the XMPP entities listed in the <b>allowed list</b> are able to connect to
* the server.
*/
whitelist
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -