You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by in...@apache.org on 2009/03/09 08:47:22 UTC
svn commit: r751606 - in
/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security:
mbean/SecretsMBean.java mbean/SecretsMBeanImplementation.java
secret/handler/JMXSecretCallbackHandler.java
Author: indika
Date: Mon Mar 9 07:47:20 2009
New Revision: 751606
URL: http://svn.apache.org/viewvc?rev=751606&view=rev
Log:
add JMXSecretCallbackHandler
Added:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/mbean/SecretsMBean.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/mbean/SecretsMBeanImplementation.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/secret/handler/JMXSecretCallbackHandler.java
Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/mbean/SecretsMBean.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/mbean/SecretsMBean.java?rev=751606&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/mbean/SecretsMBean.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/mbean/SecretsMBean.java Mon Mar 9 07:47:20 2009
@@ -0,0 +1,27 @@
+package org.apache.synapse.security.mbean;
+
+/**
+ * Managing MBean for secrct
+ */
+public interface SecretsMBean {
+
+ /**
+ * Add a secret through JMX
+ *
+ * @param id identify for what this secret is
+ * @param secret Secret
+ */
+ public void addSecret(String id, String secret);
+
+ /**
+ * Remove a Secect for given ID
+ *
+ * @param id identify for what this secret is
+ */
+ public void removeSecret(String id);
+
+ /**
+ * Clear all secrets
+ */
+ public void clear();
+}
Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/mbean/SecretsMBeanImplementation.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/mbean/SecretsMBeanImplementation.java?rev=751606&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/mbean/SecretsMBeanImplementation.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/mbean/SecretsMBeanImplementation.java Mon Mar 9 07:47:20 2009
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.synapse.security.mbean;
+
+import org.apache.synapse.SynapseException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * SecretsMBean implemetaion
+ */
+public class SecretsMBeanImplementation implements SecretsMBean {
+
+ private static final Log log = LogFactory.getLog(SecretsMBeanImplementation.class);
+ /* Secrets map - id vs secret */
+ private final Map<String, String> secrets = new HashMap<String, String>();
+
+ public void addSecret(String id, String secret) {
+ assertIdEmpty(id);
+ assertSecretEmpty(secret);
+ secrets.put(id, secret);
+ }
+
+ public String getSecret(String id) {
+ assertIdEmpty(id);
+ return secrets.get(id);
+ }
+
+ public void removeSecret(String id) {
+ assertIdEmpty(id);
+ secrets.remove(id);
+ }
+
+ public void clear() {
+ secrets.clear();
+ }
+
+ private void assertIdEmpty(String id) {
+ if (id == null || "".equals(id)) {
+ handleException("ID cannot be empty or null");
+ }
+ }
+
+ private void assertSecretEmpty(String secret) {
+ if (secret == null || "".equals(secret)) {
+ handleException("Secret cannot be empty or null");
+ }
+ }
+
+ private void handleException(String msg) {
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
+}
Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/secret/handler/JMXSecretCallbackHandler.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/secret/handler/JMXSecretCallbackHandler.java?rev=751606&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/secret/handler/JMXSecretCallbackHandler.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/security/secret/handler/JMXSecretCallbackHandler.java Mon Mar 9 07:47:20 2009
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.synapse.security.secret.handler;
+
+import org.apache.synapse.commons.util.secret.AbstractSecretCallbackHandler;
+import org.apache.synapse.commons.util.secret.SingleSecretCallback;
+import org.apache.synapse.commons.util.MBeanRegistrar;
+import org.apache.synapse.security.mbean.SecretsMBeanImplementation;
+
+/**
+ * Get and propagates secrets that have been colleted through JMX Mean
+ */
+public class JMXSecretCallbackHandler extends AbstractSecretCallbackHandler {
+
+ private static SecretsMBeanImplementation secretsMBean;
+
+ static {
+ secretsMBean = new SecretsMBeanImplementation();
+ MBeanRegistrar mBeanRegistrar = MBeanRegistrar.getInstance();
+ mBeanRegistrar.registerMBean(secretsMBean, "SecretsMBean",
+ "SecretsMBean");
+ }
+
+ protected void handleSingleSecretCallback(SingleSecretCallback singleSecretCallback) {
+ String id = singleSecretCallback.getId();
+ if (id != null && !"".equals(id)) {
+ singleSecretCallback.setSecret(secretsMBean.getSecret(id));
+ }
+ }
+}