You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ra...@apache.org on 2015/08/14 21:08:03 UTC
[30/50] [abbrv] qpid-proton git commit: Added impl for SASL types.
Added impl for SASL types.
Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/9114e13f
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/9114e13f
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/9114e13f
Branch: refs/heads/rajith-codec
Commit: 9114e13fae9fd55b9d1ee25f253d343627baf246
Parents: 240a07d
Author: Rajith Attapattu <ra...@apache.org>
Authored: Fri Feb 20 20:21:51 2015 -0500
Committer: Rajith Attapattu <ra...@apache.org>
Committed: Thu Jul 9 09:12:38 2015 -0400
----------------------------------------------------------------------
.../qpid/proton/security/SaslChallenge.java | 86 +++++++++++++
.../apache/qpid/proton/security/SaslCode.java | 38 ++++++
.../apache/qpid/proton/security/SaslInit.java | 122 +++++++++++++++++++
.../qpid/proton/security/SaslMechanisms.java | 103 ++++++++++++++++
.../qpid/proton/security/SaslOutcome.java | 115 +++++++++++++++++
.../qpid/proton/security/SaslResponse.java | 86 +++++++++++++
6 files changed, 550 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/9114e13f/proton-j/src/main/java/org/apache/qpid/proton/security/SaslChallenge.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/security/SaslChallenge.java b/proton-j/src/main/java/org/apache/qpid/proton/security/SaslChallenge.java
new file mode 100644
index 0000000..462118d
--- /dev/null
+++ b/proton-j/src/main/java/org/apache/qpid/proton/security/SaslChallenge.java
@@ -0,0 +1,86 @@
+/*
+ *
+ * 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.qpid.proton.security;
+
+import java.util.List;
+
+import org.apache.qpid.proton.codec2.DecodeException;
+import org.apache.qpid.proton.codec2.DescribedTypeFactory;
+import org.apache.qpid.proton.codec2.Encodable;
+import org.apache.qpid.proton.codec2.Encoder;
+
+public final class SaslChallenge implements Encodable
+{
+ public final static long DESCRIPTOR_LONG = 0x0000000000000042L;
+
+ public final static String DESCRIPTOR_STRING = "amqp:sasl-challenge:list";
+
+ private byte[] _challenge;
+
+ public byte[] getChallenge()
+ {
+ return _challenge;
+ }
+
+ public void setChallenge(byte[] challenge)
+ {
+ if (challenge == null)
+ {
+ throw new NullPointerException("the challenge field is mandatory");
+ }
+
+ _challenge = challenge;
+ }
+
+ @Override
+ public void encode(Encoder encoder)
+ {
+ encoder.putDescriptor();
+ encoder.putUlong(DESCRIPTOR_LONG);
+ encoder.putList();
+ encoder.putBinary(_challenge, 0, _challenge.length);
+ encoder.end();
+ }
+
+ public static final class Factory implements DescribedTypeFactory
+ {
+ @SuppressWarnings("unchecked")
+ public Object create(Object in) throws DecodeException
+ {
+ List<Object> l = (List<Object>) in;
+ SaslChallenge saslChallenge = new SaslChallenge();
+
+ if (l.size() > 0)
+ {
+ saslChallenge.setChallenge((byte[]) l.get(0));
+ }
+
+ return saslChallenge;
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ return "SaslChallenge{" + "challenge=" + _challenge + '}';
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/9114e13f/proton-j/src/main/java/org/apache/qpid/proton/security/SaslCode.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/security/SaslCode.java b/proton-j/src/main/java/org/apache/qpid/proton/security/SaslCode.java
new file mode 100644
index 0000000..9d6b055
--- /dev/null
+++ b/proton-j/src/main/java/org/apache/qpid/proton/security/SaslCode.java
@@ -0,0 +1,38 @@
+/*
+ *
+ * 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.qpid.proton.security;
+
+public enum SaslCode
+{
+ OK, AUTH, SYS, SYS_PERM, SYS_TEMP;
+
+ public byte getValue()
+ {
+ return (byte) ordinal();
+ }
+
+ public static SaslCode valueOf(byte b)
+ {
+ return SaslCode.values()[b];
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/9114e13f/proton-j/src/main/java/org/apache/qpid/proton/security/SaslInit.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/security/SaslInit.java b/proton-j/src/main/java/org/apache/qpid/proton/security/SaslInit.java
new file mode 100644
index 0000000..e7bcbcf
--- /dev/null
+++ b/proton-j/src/main/java/org/apache/qpid/proton/security/SaslInit.java
@@ -0,0 +1,122 @@
+/*
+ *
+ * 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.qpid.proton.security;
+
+import java.util.List;
+
+import org.apache.qpid.proton.codec2.DecodeException;
+import org.apache.qpid.proton.codec2.DescribedTypeFactory;
+import org.apache.qpid.proton.codec2.Encodable;
+import org.apache.qpid.proton.codec2.Encoder;
+
+public final class SaslInit implements Encodable
+{
+ public final static long DESCRIPTOR_LONG = 0x0000000000000042L;
+
+ public final static String DESCRIPTOR_STRING = "amqp:sasl-challenge:list";
+
+ private String _mechanism;
+
+ private byte[] _initialResponse;
+
+ private String _hostname;
+
+ public String getMechanism()
+ {
+ return _mechanism;
+ }
+
+ public void setMechanism(String mechanism)
+ {
+ if (mechanism == null)
+ {
+ throw new NullPointerException("the mechanism field is mandatory");
+ }
+
+ _mechanism = mechanism;
+ }
+
+ public byte[] getInitialResponse()
+ {
+ return _initialResponse;
+ }
+
+ public void setInitialResponse(byte[] initialResponse)
+ {
+ _initialResponse = initialResponse;
+ }
+
+ public String getHostname()
+ {
+ return _hostname;
+ }
+
+ public void setHostname(String hostname)
+ {
+ _hostname = hostname;
+ }
+
+ @Override
+ public void encode(Encoder encoder)
+ {
+ encoder.putDescriptor();
+ encoder.putUlong(DESCRIPTOR_LONG);
+ encoder.putList();
+ encoder.putSymbol(_mechanism);
+ encoder.putBinary(_initialResponse, 0, _initialResponse.length);
+ encoder.putString(_hostname);
+ encoder.end();
+ }
+
+ public static final class Factory implements DescribedTypeFactory
+ {
+ @SuppressWarnings("unchecked")
+ public Object create(Object in) throws DecodeException
+ {
+ List<Object> l = (List<Object>) in;
+ SaslInit saslInit = new SaslInit();
+
+ switch (3 - l.size())
+ {
+
+ case 0:
+ saslInit.setHostname((String) l.get(2));
+ case 1:
+ saslInit.setInitialResponse((byte[]) l.get(1));
+ case 2:
+ saslInit.setMechanism((String) l.get(0));
+ }
+
+ return saslInit;
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ return "SaslInit{" +
+ "mechanism=" + _mechanism +
+ ", initialResponse=" + _initialResponse +
+ ", hostname='" + _hostname + '\'' +
+ '}';
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/9114e13f/proton-j/src/main/java/org/apache/qpid/proton/security/SaslMechanisms.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/security/SaslMechanisms.java b/proton-j/src/main/java/org/apache/qpid/proton/security/SaslMechanisms.java
new file mode 100644
index 0000000..74e5800
--- /dev/null
+++ b/proton-j/src/main/java/org/apache/qpid/proton/security/SaslMechanisms.java
@@ -0,0 +1,103 @@
+/*
+ *
+ * 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.qpid.proton.security;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.qpid.proton.codec2.DecodeException;
+import org.apache.qpid.proton.codec2.DescribedTypeFactory;
+import org.apache.qpid.proton.codec2.Encodable;
+import org.apache.qpid.proton.codec2.Encoder;
+import org.apache.qpid.proton.codec2.Type;
+
+public final class SaslMechanisms implements Encodable
+{
+ public final static long DESCRIPTOR_LONG = 0x0000000000000040L;
+
+ public final static String DESCRIPTOR_STRING = "amqp:sasl-mechanisms:list";
+
+ private String[] _saslServerMechanisms;
+
+ public String[] getSaslServerMechanisms()
+ {
+ return _saslServerMechanisms;
+ }
+
+ public void setSaslServerMechanisms(String... saslServerMechanisms)
+ {
+ if (saslServerMechanisms == null)
+ {
+ throw new NullPointerException("the sasl-server-mechanisms field is mandatory");
+ }
+
+ _saslServerMechanisms = saslServerMechanisms;
+ }
+
+ @Override
+ public void encode(Encoder encoder)
+ {
+ encoder.putDescriptor();
+ encoder.putUlong(DESCRIPTOR_LONG);
+ encoder.putList();
+ encoder.putArray(Type.SYMBOL);
+ for (String mech : _saslServerMechanisms)
+ {
+ encoder.putSymbol(mech);
+ }
+ encoder.end();
+ encoder.end();
+ }
+
+ public static final class Factory implements DescribedTypeFactory
+ {
+ @SuppressWarnings("unchecked")
+ public Object create(Object in) throws DecodeException
+ {
+ List<Object> l = (List<Object>) in;
+ SaslMechanisms saslMech = new SaslMechanisms();
+
+ if (l.isEmpty())
+ {
+ throw new DecodeException("The sasl-server-mechanisms field cannot be omitted");
+ }
+
+ Object val0 = l.get(0);
+ if (val0 == null || val0.getClass().isArray())
+ {
+ saslMech.setSaslServerMechanisms((String[]) val0);
+ }
+ else
+ {
+ saslMech.setSaslServerMechanisms((String) val0);
+ }
+ return saslMech;
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ return "SaslMechanisms{" + "saslServerMechanisms="
+ + (_saslServerMechanisms == null ? null : Arrays.asList(_saslServerMechanisms)) + '}';
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/9114e13f/proton-j/src/main/java/org/apache/qpid/proton/security/SaslOutcome.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/security/SaslOutcome.java b/proton-j/src/main/java/org/apache/qpid/proton/security/SaslOutcome.java
new file mode 100644
index 0000000..7e87f9c
--- /dev/null
+++ b/proton-j/src/main/java/org/apache/qpid/proton/security/SaslOutcome.java
@@ -0,0 +1,115 @@
+/*
+ *
+ * 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.qpid.proton.security;
+
+import java.util.List;
+
+import org.apache.qpid.proton.codec2.DecodeException;
+import org.apache.qpid.proton.codec2.DescribedTypeFactory;
+import org.apache.qpid.proton.codec2.Encodable;
+import org.apache.qpid.proton.codec2.Encoder;
+
+public final class SaslOutcome implements Encodable
+{
+ public final static long DESCRIPTOR_LONG = 0x0000000000000044L;
+
+ public final static String DESCRIPTOR_STRING = "amqp:sasl-saslOutcome:list";
+
+ private SaslCode _code;
+
+ private byte[] _additionalData;
+
+ public SaslCode getCode()
+ {
+ return _code;
+ }
+
+ public void setCode(SaslCode code)
+ {
+ if (code == null)
+ {
+ throw new NullPointerException("the code field is mandatory");
+ }
+
+ _code = code;
+ }
+
+ public byte[] getAdditionalData()
+ {
+ return _additionalData;
+ }
+
+ public void setAdditionalData(byte[] additionalData)
+ {
+ _additionalData = additionalData;
+ }
+
+ @Override
+ public void encode(Encoder encoder)
+ {
+ encoder.putDescriptor();
+ encoder.putUlong(DESCRIPTOR_LONG);
+ encoder.putList();
+ encoder.putUbyte(_code.getValue());
+ if (_additionalData != null)
+ {
+ encoder.putBinary(_additionalData, 0, _additionalData.length);
+ }
+ encoder.end();
+ }
+
+ public static final class Factory implements DescribedTypeFactory
+ {
+ @SuppressWarnings("unchecked")
+ public Object create(Object in) throws DecodeException
+ {
+ List<Object> l = (List<Object>) in;
+ SaslOutcome saslOutcome = new SaslOutcome();
+
+ if(l.isEmpty())
+ {
+ throw new DecodeException("The code field cannot be omitted");
+ }
+
+ switch(2 - l.size())
+ {
+
+ case 0:
+ saslOutcome.setAdditionalData( (byte[]) l.get( 1 ) );
+ case 1:
+ saslOutcome.setCode(SaslCode.valueOf((byte)l.get(0)));
+ }
+
+
+ return saslOutcome;
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ return "SaslOutcome{" +
+ "_code=" + _code +
+ ", _additionalData=" + _additionalData +
+ '}';
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/9114e13f/proton-j/src/main/java/org/apache/qpid/proton/security/SaslResponse.java
----------------------------------------------------------------------
diff --git a/proton-j/src/main/java/org/apache/qpid/proton/security/SaslResponse.java b/proton-j/src/main/java/org/apache/qpid/proton/security/SaslResponse.java
new file mode 100644
index 0000000..a698f6d
--- /dev/null
+++ b/proton-j/src/main/java/org/apache/qpid/proton/security/SaslResponse.java
@@ -0,0 +1,86 @@
+/*
+ *
+ * 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.qpid.proton.security;
+
+import java.util.List;
+
+import org.apache.qpid.proton.codec2.DecodeException;
+import org.apache.qpid.proton.codec2.DescribedTypeFactory;
+import org.apache.qpid.proton.codec2.Encodable;
+import org.apache.qpid.proton.codec2.Encoder;
+
+public final class SaslResponse implements Encodable
+{
+ public final static long DESCRIPTOR_LONG = 0x0000000000000043L;
+
+ public final static String DESCRIPTOR_STRING = "amqp:sasl-response:list";
+
+ private byte[] _response;
+
+ public byte[] getResponse()
+ {
+ return _response;
+ }
+
+ public void setResponse(byte[] response)
+ {
+ if (response == null)
+ {
+ throw new NullPointerException("the response field is mandatory");
+ }
+
+ _response = response;
+ }
+
+ @Override
+ public void encode(Encoder encoder)
+ {
+ encoder.putDescriptor();
+ encoder.putUlong(DESCRIPTOR_LONG);
+ encoder.putList();
+ encoder.putBinary(_response, 0, _response.length);
+ encoder.end();
+ }
+
+ public static final class Factory implements DescribedTypeFactory
+ {
+ @SuppressWarnings("unchecked")
+ public Object create(Object in) throws DecodeException
+ {
+ List<Object> l = (List<Object>) in;
+ SaslResponse saslResponse = new SaslResponse();
+
+ if (l.size() > 0)
+ {
+ saslResponse.setResponse((byte[]) l.get(0));
+ }
+
+ return saslResponse;
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ return "SaslResponse{response=" + _response + '}';
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org