PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/remoting/src/main/java/org/jboss/as/remoting/RemotingSubsystemProviders.java

https://github.com/pepite/jboss-as
Java | 253 lines | 172 code | 55 blank | 26 comment | 2 complexity | 98098dfb8363d911e66ecdfcca920bc5 MD5 | raw file
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2010, Red Hat, Inc., and individual contributors
  4. * as indicated by the @author tags. See the copyright.txt file in the
  5. * distribution for a full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jboss.as.remoting;
  23. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ATTRIBUTES;
  24. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.CHILDREN;
  25. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DEFAULT;
  26. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DESCRIPTION;
  27. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.HEAD_COMMENT_ALLOWED;
  28. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAME;
  29. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.NAMESPACE;
  30. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_NAME;
  31. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REQUEST_PROPERTIES;
  32. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.REQUIRED;
  33. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.TAIL_COMMENT_ALLOWED;
  34. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.TYPE;
  35. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE_TYPE;
  36. import static org.jboss.as.remoting.CommonAttributes.AUTHENTICATION_PROVIDER;
  37. import static org.jboss.as.remoting.CommonAttributes.CONNECTOR;
  38. import static org.jboss.as.remoting.CommonAttributes.FORWARD_SECRECY;
  39. import static org.jboss.as.remoting.CommonAttributes.INCLUDE_MECHANISMS;
  40. import static org.jboss.as.remoting.CommonAttributes.NO_ACTIVE;
  41. import static org.jboss.as.remoting.CommonAttributes.NO_ANONYMOUS;
  42. import static org.jboss.as.remoting.CommonAttributes.NO_DICTIONARY;
  43. import static org.jboss.as.remoting.CommonAttributes.NO_PLAINTEXT;
  44. import static org.jboss.as.remoting.CommonAttributes.PASS_CREDENTIALS;
  45. import static org.jboss.as.remoting.CommonAttributes.POLICY;
  46. import static org.jboss.as.remoting.CommonAttributes.PROPERTIES;
  47. import static org.jboss.as.remoting.CommonAttributes.QOP;
  48. import static org.jboss.as.remoting.CommonAttributes.REUSE_SESSION;
  49. import static org.jboss.as.remoting.CommonAttributes.SASL;
  50. import static org.jboss.as.remoting.CommonAttributes.SERVER_AUTH;
  51. import static org.jboss.as.remoting.CommonAttributes.SOCKET_BINDING;
  52. import static org.jboss.as.remoting.CommonAttributes.THREAD_POOL;
  53. import java.util.Locale;
  54. import java.util.ResourceBundle;
  55. import org.jboss.as.controller.descriptions.DescriptionProvider;
  56. import org.jboss.dmr.ModelNode;
  57. import org.jboss.dmr.ModelType;
  58. /**
  59. * The remoting subsystem description providers.
  60. *
  61. * @author Emanuel Muckenhuber
  62. */
  63. class RemotingSubsystemProviders {
  64. static final String RESOURCE_NAME = RemotingSubsystemProviders.class.getPackage().getName() + ".LocalDescriptions";
  65. static final DescriptionProvider SUBSYSTEM = new DescriptionProvider() {
  66. @Override
  67. public ModelNode getModelDescription(Locale locale) {
  68. final ResourceBundle bundle = getResourceBundle(locale);
  69. final ModelNode subsystem = new ModelNode();
  70. subsystem.get(DESCRIPTION).set(bundle.getString("remoting"));
  71. subsystem.get(HEAD_COMMENT_ALLOWED).set(true);
  72. subsystem.get(TAIL_COMMENT_ALLOWED).set(true);
  73. subsystem.get(NAMESPACE).set(Namespace.REMOTING_1_0.getUriString());
  74. subsystem.get(ATTRIBUTES, THREAD_POOL, TYPE).set(ModelType.STRING);
  75. subsystem.get(ATTRIBUTES, THREAD_POOL, DESCRIPTION).set(bundle.getString("remoting.thread-pool"));
  76. subsystem.get(ATTRIBUTES, THREAD_POOL, REQUIRED).set(true);
  77. subsystem.get(CHILDREN, CONNECTOR).set(getConnectorDescription(bundle));
  78. return subsystem;
  79. }
  80. };
  81. static final DescriptionProvider SUBSYSTEM_ADD = new DescriptionProvider() {
  82. @Override
  83. public ModelNode getModelDescription(final Locale locale) {
  84. final ResourceBundle bundle = getResourceBundle(locale);
  85. final ModelNode operation = new ModelNode();
  86. operation.get(OPERATION_NAME).set("add");
  87. operation.get(REQUEST_PROPERTIES, THREAD_POOL, TYPE).set(ModelType.STRING);
  88. operation.get(REQUEST_PROPERTIES, THREAD_POOL, DESCRIPTION).set(bundle.getString("remoting.thread-pool"));
  89. operation.get(REQUEST_PROPERTIES, THREAD_POOL, REQUIRED).set(true);
  90. return operation;
  91. }
  92. };
  93. static final DescriptionProvider CONNECTOR_ADD = new DescriptionProvider() {
  94. @Override
  95. public ModelNode getModelDescription(final Locale locale) {
  96. final ResourceBundle bundle = getResourceBundle(locale);
  97. final ModelNode operation = new ModelNode();
  98. operation.get(OPERATION_NAME).set("add-connector");
  99. operation.get(REQUEST_PROPERTIES, NAME, TYPE).set(ModelType.STRING);
  100. operation.get(REQUEST_PROPERTIES, NAME, DESCRIPTION).set(bundle.getString("remoting.connector.name"));
  101. operation.get(REQUEST_PROPERTIES, NAME, REQUIRED).set(true);
  102. operation.get(REQUEST_PROPERTIES, SOCKET_BINDING, TYPE).set(ModelType.STRING);
  103. operation.get(REQUEST_PROPERTIES, SOCKET_BINDING, DESCRIPTION).set(bundle.getString("remoting.connector.socket-binding"));
  104. operation.get(REQUEST_PROPERTIES, SOCKET_BINDING, REQUIRED).set(true);
  105. operation.get(REQUEST_PROPERTIES, AUTHENTICATION_PROVIDER, TYPE).set(ModelType.STRING);
  106. operation.get(REQUEST_PROPERTIES, AUTHENTICATION_PROVIDER, DESCRIPTION).set(bundle.getString("remoting.connector.authentication-provider"));
  107. operation.get(REQUEST_PROPERTIES, AUTHENTICATION_PROVIDER, REQUIRED).set(false);
  108. operation.get(REQUEST_PROPERTIES, SASL).set(getSaslElement(bundle));
  109. return operation;
  110. }
  111. };
  112. static final DescriptionProvider CONNECTOR_REMOVE = new DescriptionProvider() {
  113. @Override
  114. public ModelNode getModelDescription(final Locale locale) {
  115. final ResourceBundle bundle = getResourceBundle(locale);
  116. final ModelNode operation = new ModelNode();
  117. operation.get(OPERATION_NAME).set("remove-connector");
  118. operation.get(REQUEST_PROPERTIES, NAME, TYPE).set(ModelType.STRING);
  119. operation.get(REQUEST_PROPERTIES, NAME, DESCRIPTION).set(bundle.getString("remoting.connector.name"));
  120. operation.get(REQUEST_PROPERTIES, NAME, REQUIRED).set(true);
  121. return operation;
  122. }
  123. };
  124. static final DescriptionProvider CONNECTOR_SPEC = new DescriptionProvider( ) {
  125. @Override
  126. public ModelNode getModelDescription(Locale locale) {
  127. final ResourceBundle bundle = getResourceBundle(locale);
  128. return getConnectorDescription(bundle);
  129. }
  130. };
  131. static ModelNode getConnectorDescription(final ResourceBundle bundle) {
  132. final ModelNode connector = new ModelNode();
  133. connector.get(TYPE).set(ModelType.OBJECT);
  134. connector.get(DESCRIPTION).set(bundle.getString("remoting.connector"));
  135. connector.get(ATTRIBUTES, NAME, TYPE).set(ModelType.STRING);
  136. connector.get(ATTRIBUTES, NAME, DESCRIPTION).set(bundle.getString("remoting.connector.name"));
  137. connector.get(ATTRIBUTES, NAME, REQUIRED).set(true);
  138. connector.get(ATTRIBUTES, SOCKET_BINDING, TYPE).set(ModelType.STRING);
  139. connector.get(ATTRIBUTES, SOCKET_BINDING, DESCRIPTION).set(bundle.getString("remoting.connector.socket-binding"));
  140. connector.get(ATTRIBUTES, SOCKET_BINDING, REQUIRED).set(true);
  141. connector.get(ATTRIBUTES, AUTHENTICATION_PROVIDER, TYPE).set(ModelType.STRING);
  142. connector.get(ATTRIBUTES, AUTHENTICATION_PROVIDER, DESCRIPTION).set(bundle.getString("remoting.connector.authentication-provider"));
  143. connector.get(ATTRIBUTES, AUTHENTICATION_PROVIDER, REQUIRED).set(false);
  144. connector.get(CHILDREN, SASL).set(getSaslElement(bundle));
  145. return connector;
  146. }
  147. static ModelNode getSaslElement(final ResourceBundle bundle) {
  148. final ModelNode sasl = new ModelNode();
  149. sasl.get(TYPE).set(ModelType.OBJECT);
  150. sasl.get(DESCRIPTION).set(bundle.getString("remoting.sasl"));
  151. sasl.get(REQUIRED).set(false);
  152. sasl.get(ATTRIBUTES, REUSE_SESSION, TYPE).set(ModelType.BOOLEAN);
  153. sasl.get(ATTRIBUTES, REUSE_SESSION, DESCRIPTION).set(bundle.getString("remoting.sasl.reuse-session"));
  154. sasl.get(ATTRIBUTES, REUSE_SESSION, REQUIRED).set(false);
  155. sasl.get(ATTRIBUTES, REUSE_SESSION, DEFAULT).set(false);
  156. sasl.get(ATTRIBUTES, SERVER_AUTH, TYPE).set(ModelType.BOOLEAN);
  157. sasl.get(ATTRIBUTES, SERVER_AUTH, DESCRIPTION).set(bundle.getString("remoting.sasl.server-auth"));
  158. sasl.get(ATTRIBUTES, SERVER_AUTH, REQUIRED).set(false);
  159. sasl.get(ATTRIBUTES, SERVER_AUTH, DEFAULT).set(false);
  160. sasl.get(CHILDREN, INCLUDE_MECHANISMS, TYPE).set(ModelType.LIST);
  161. sasl.get(CHILDREN, INCLUDE_MECHANISMS, VALUE_TYPE).set(ModelType.STRING);
  162. sasl.get(CHILDREN, INCLUDE_MECHANISMS, DESCRIPTION).set(bundle.getString("remoting.sasl.include-mechanisms"));
  163. sasl.get(CHILDREN, INCLUDE_MECHANISMS, REQUIRED).set(false);
  164. sasl.get(CHILDREN, QOP, TYPE).set(ModelType.LIST);
  165. sasl.get(CHILDREN, QOP, VALUE_TYPE).set(ModelType.STRING);
  166. sasl.get(CHILDREN, QOP, DESCRIPTION).set(bundle.getString("remoting.sasl.qop"));
  167. sasl.get(CHILDREN, QOP, REQUIRED).set(false);
  168. sasl.get(CHILDREN, POLICY).set(getPolicyElement(bundle));
  169. sasl.get(CHILDREN, PROPERTIES, TYPE).set(ModelType.LIST);
  170. sasl.get(CHILDREN, PROPERTIES, VALUE_TYPE).set(ModelType.PROPERTY);
  171. return sasl;
  172. }
  173. static ModelNode getPolicyElement(final ResourceBundle bundle) {
  174. final ModelNode policy = new ModelNode();
  175. policy.get(TYPE).set(ModelType.PROPERTY);
  176. policy.get(VALUE_TYPE).set(ModelType.BOOLEAN);
  177. policy.get(DESCRIPTION).set(bundle.getString("remoting.sasl.policy"));
  178. policy.get(ATTRIBUTES, FORWARD_SECRECY, TYPE).set(ModelType.BOOLEAN);
  179. policy.get(ATTRIBUTES, FORWARD_SECRECY, DESCRIPTION).set(bundle.getString("remoting.sasl.policy.forward-secrecy"));
  180. policy.get(ATTRIBUTES, NO_ACTIVE, TYPE).set(ModelType.BOOLEAN);
  181. policy.get(ATTRIBUTES, NO_ACTIVE, DESCRIPTION).set(bundle.getString("remoting.sasl.policy.no-active"));
  182. policy.get(ATTRIBUTES, NO_ANONYMOUS, TYPE).set(ModelType.BOOLEAN);
  183. policy.get(ATTRIBUTES, NO_ANONYMOUS, DESCRIPTION).set(bundle.getString("remoting.sasl.policy.no-anonymous"));
  184. policy.get(ATTRIBUTES, NO_DICTIONARY, TYPE).set(ModelType.BOOLEAN);
  185. policy.get(ATTRIBUTES, NO_DICTIONARY, DESCRIPTION).set(bundle.getString("remoting.sasl.policy.no-dictionary"));
  186. policy.get(ATTRIBUTES, NO_PLAINTEXT, TYPE).set(ModelType.BOOLEAN);
  187. policy.get(ATTRIBUTES, NO_PLAINTEXT, DESCRIPTION).set(bundle.getString("remoting.sasl.policy.no-plain-text"));
  188. policy.get(ATTRIBUTES, PASS_CREDENTIALS, TYPE).set(ModelType.BOOLEAN);
  189. policy.get(ATTRIBUTES, PASS_CREDENTIALS, DESCRIPTION).set(bundle.getString("remoting.sasl.policy.pass-credentials"));
  190. return policy;
  191. }
  192. private static ResourceBundle getResourceBundle(Locale locale) {
  193. if (locale == null) {
  194. locale = Locale.getDefault();
  195. }
  196. return ResourceBundle.getBundle(RESOURCE_NAME, locale);
  197. }
  198. }