You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@activemq.apache.org by "gtully (via GitHub)" <gi...@apache.org> on 2023/04/27 15:37:15 UTC

[GitHub] [activemq-artemis] gtully opened a new pull request, #4458: [ARTEMIS-4263] - authenticator to adapt to artemis jaas login modules…

gtully opened a new pull request, #4458:
URL: https://github.com/apache/activemq-artemis/pull/4458

   … callback handler


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [activemq-artemis] gtully commented on a diff in pull request #4458: [ARTEMIS-4263] - authenticator to adapt to artemis jaas login modules…

Posted by "gtully (via GitHub)" <gi...@apache.org>.
gtully commented on code in PR #4458:
URL: https://github.com/apache/activemq-artemis/pull/4458#discussion_r1180465177


##########
artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/jaas/AuthenticatorAdapter.java:
##########
@@ -0,0 +1,128 @@
+/**

Review Comment:
   think javadoc is ok for the description, why not?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [activemq-artemis] jbertram commented on pull request #4458: [ARTEMIS-4263] - authenticator to adapt to artemis jaas login modules…

Posted by "jbertram (via GitHub)" <gi...@apache.org>.
jbertram commented on PR #4458:
URL: https://github.com/apache/activemq-artemis/pull/4458#issuecomment-1526484809

   What's the use-case for this?
   
   Also, you can omit the square brackets and dash from your commit message so that it's just:
   ```
   ARTEMIS-4263 authenticator to adapt to artemis jaas login modules callback handler
   ```
   IMO it makes it easier to read and follows the pattern from the [hacking guide](https://github.com/apache/activemq-artemis/blob/main/docs/hacking-guide/en/code.md#commitMessageDetails).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [activemq-artemis] gtully commented on pull request #4458: [ARTEMIS-4263] - authenticator to adapt to artemis jaas login modules…

Posted by "gtully (via GitHub)" <gi...@apache.org>.
gtully commented on PR #4458:
URL: https://github.com/apache/activemq-artemis/pull/4458#issuecomment-1527166106

   thanks Justin, fixed the commit message.
   the use case is the jolokia jvm agent that uses the jdk http stack, it can do jaas delegation via a user/pass authenticator but it does not know about the artemis callback handler so cannot populate all of our login modules. This is an authenticator that knows about artemis. It is generic, the autnenticator is an extension point for the jdk http stack, nothing jolokia specific in this.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [activemq-artemis] gemmellr commented on a diff in pull request #4458: [ARTEMIS-4263] - authenticator to adapt to artemis jaas login modules…

Posted by "gemmellr (via GitHub)" <gi...@apache.org>.
gemmellr commented on code in PR #4458:
URL: https://github.com/apache/activemq-artemis/pull/4458#discussion_r1182446328


##########
artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/jaas/HttpServerAuthenticator.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.activemq.artemis.spi.core.security.jaas;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.login.LoginContext;
+
+import java.nio.charset.StandardCharsets;
+import java.security.Principal;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.StringTokenizer;
+
+import com.sun.net.httpserver.Authenticator;
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpPrincipal;
+import com.sun.net.httpserver.HttpsExchange;
+
+/**
+ * delegate to our JAAS login modules by adapting our handlers to httpserver.httpExchange
+ */
+public class HttpServerAuthenticator extends Authenticator {
+
+   static final String REALM_PROPERTY_NAME = "httpServerAuthenticator.realm";
+   static final String REQUEST_SUBJECT_ATTRIBUTE_PROPERTY_NAME = "httpServerAuthenticator.requestSubjectAttribute";
+   static String DEFAULT_SUBJECT_ATTRIBUTE = "org.apache.activemq.artemis.jaasSubject";
+   static final String DEFAULT_REALM = "http_server_authenticator";
+   static final String AUTHORIZATION_HEADER_NAME = "Authorization";
+
+   final String realm = System.getProperty(REALM_PROPERTY_NAME, DEFAULT_REALM);
+   final String subjectRequestAttribute = System.getProperty(REQUEST_SUBJECT_ATTRIBUTE_PROPERTY_NAME, DEFAULT_SUBJECT_ATTRIBUTE);
+
+   @Override
+   public Result authenticate(HttpExchange httpExchange) {
+
+      try {
+         LoginContext loginContext = new LoginContext(realm, callbacks -> {
+            for (Callback callback : callbacks) {
+               if (callback instanceof PasswordCallback) {
+                  PasswordCallback passwordCallback = (PasswordCallback) callback;
+
+                  StringTokenizer stringTokenizer = new StringTokenizer(extractAuthHeader(httpExchange));
+                  String method = stringTokenizer.nextToken();
+                  if ("Basic".equalsIgnoreCase(method)) {
+                     byte[] authHeaderBytes = Base64.getDecoder().decode(stringTokenizer.nextToken());
+
+                     // :pass
+                     byte[] password = Arrays.copyOfRange(authHeaderBytes, Arrays.binarySearch(authHeaderBytes, (byte) ':') + 1, authHeaderBytes.length);
+                     passwordCallback.setPassword(new String(password, StandardCharsets.UTF_8).toCharArray());
+                  } else if ("Bearer".equalsIgnoreCase(method)) {
+                     passwordCallback.setPassword(stringTokenizer.nextToken().toCharArray());
+                  }
+               } else if (callback instanceof NameCallback) {
+                  NameCallback nameCallback = (NameCallback) callback;
+
+                  StringTokenizer stringTokenizer = new StringTokenizer(extractAuthHeader(httpExchange));
+                  String method = stringTokenizer.nextToken();
+                  if ("Basic".equalsIgnoreCase(method)) {
+                     byte[] authHeaderBytes = Base64.getDecoder().decode(stringTokenizer.nextToken());
+
+                     // user:
+                     byte[] user = Arrays.copyOfRange(authHeaderBytes, 0, Arrays.binarySearch(authHeaderBytes, (byte) ':'));
+                     nameCallback.setName(new String(user));

Review Comment:
   same charset issue as earlier comment



##########
artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/jaas/HttpServerAuthenticator.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>

Review Comment:
   Content is still the old javadoc/mis-formatted version. Copy over the comment version from other files.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [activemq-artemis] gemmellr commented on a diff in pull request #4458: [ARTEMIS-4263] - authenticator to adapt to artemis jaas login modules…

Posted by "gemmellr (via GitHub)" <gi...@apache.org>.
gemmellr commented on code in PR #4458:
URL: https://github.com/apache/activemq-artemis/pull/4458#discussion_r1180167688


##########
artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/jaas/AuthenticatorAdapter.java:
##########
@@ -0,0 +1,128 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.activemq.artemis.spi.core.security.jaas;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.login.LoginContext;
+
+import java.security.Principal;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.StringTokenizer;
+
+import com.sun.net.httpserver.Authenticator;
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpPrincipal;
+import com.sun.net.httpserver.HttpsExchange;
+
+// delegate to our JAAS login modules by adapting our handlers to httpExchange
+// allow the jolokia jvm agent to integrate with our auth
+public class AuthenticatorAdapter extends Authenticator {

Review Comment:
   I think I would give this a more targeted name than just AuthenticatorAdapter, that seems a bit of an 'general/obvious/primary name', whereas this seems like its actually going to be more of a niche class used to satisfy a specific use case.  Perhaps HttpServerAuthenticatorAdapter since its so tied to com.sun.net.httpserver (which I was initially concerned at seeing, but it does seem to be a public JDK-supported API...albeit still not a Java SE API)?



##########
artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/jaas/AuthenticatorAdapter.java:
##########
@@ -0,0 +1,128 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.activemq.artemis.spi.core.security.jaas;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.login.LoginContext;
+
+import java.security.Principal;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.StringTokenizer;
+
+import com.sun.net.httpserver.Authenticator;
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpPrincipal;
+import com.sun.net.httpserver.HttpsExchange;
+
+// delegate to our JAAS login modules by adapting our handlers to httpExchange
+// allow the jolokia jvm agent to integrate with our auth
+public class AuthenticatorAdapter extends Authenticator {
+
+   static final String REALM_PROPERTY_NAME = "jolokiaJvmAgent.realm";
+   static final String REQUEST_SUBJECT_ATTRIBUTE_PROPERTY_NAME = "jolokiaJvmAgent.requestSubjectAttribute";
+   static String DEFAULT_SUBJECT_ATTRIBUTE = "org.jolokia.jaasSubject";
+   static final String DEFAULT_REALM = "jolokia_jvm_agent";

Review Comment:
   You commented this isnt Jolokia specific, but this actually seems more like it is.
   



##########
artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/jaas/AuthenticatorAdapter.java:
##########
@@ -0,0 +1,128 @@
+/**

Review Comment:
   Should be a comment rather than javadoc. Can lose the needless space after also.



##########
artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/jaas/AuthenticatorAdapter.java:
##########
@@ -0,0 +1,128 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.activemq.artemis.spi.core.security.jaas;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.login.LoginContext;
+
+import java.security.Principal;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.StringTokenizer;
+
+import com.sun.net.httpserver.Authenticator;
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpPrincipal;
+import com.sun.net.httpserver.HttpsExchange;
+
+// delegate to our JAAS login modules by adapting our handlers to httpExchange
+// allow the jolokia jvm agent to integrate with our auth
+public class AuthenticatorAdapter extends Authenticator {
+
+   static final String REALM_PROPERTY_NAME = "jolokiaJvmAgent.realm";
+   static final String REQUEST_SUBJECT_ATTRIBUTE_PROPERTY_NAME = "jolokiaJvmAgent.requestSubjectAttribute";
+   static String DEFAULT_SUBJECT_ATTRIBUTE = "org.jolokia.jaasSubject";
+   static final String DEFAULT_REALM = "jolokia_jvm_agent";
+   static final String AUTHORIZATION_HEADER_NAME = "Authorization";
+
+   final String realm = System.getProperty(REALM_PROPERTY_NAME, DEFAULT_REALM);
+   final String subjectRequestAttribute = System.getProperty(REQUEST_SUBJECT_ATTRIBUTE_PROPERTY_NAME, DEFAULT_SUBJECT_ATTRIBUTE);
+
+   @Override
+   public Result authenticate(HttpExchange httpExchange) {
+
+      try {
+         LoginContext loginContext = new LoginContext(realm, callbacks -> {
+            for (Callback callback : callbacks) {
+               if (callback instanceof PasswordCallback) {
+                  PasswordCallback passwordCallback = (PasswordCallback) callback;
+
+                  StringTokenizer stringTokenizer = new StringTokenizer(extractAuthHeader(httpExchange));
+                  String method = stringTokenizer.nextToken();
+                  if ("Basic".equalsIgnoreCase(method)) {
+                     byte[] authHeaderBytes = Base64.getDecoder().decode(stringTokenizer.nextToken());
+
+                     // :pass
+                     byte[] password = Arrays.copyOfRange(authHeaderBytes, Arrays.binarySearch(authHeaderBytes, (byte) ':') + 1, authHeaderBytes.length);
+                     passwordCallback.setPassword(new String(password).toCharArray());

Review Comment:
   I'd wonder if this (and others elsewhere) shouldnt be defining a charset, rather than relying on the variable platform default (at least up to JDK18 when it was finally defaulted to UTF-8: https://openjdk.org/jeps/400) ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [activemq-artemis] gtully commented on a diff in pull request #4458: [ARTEMIS-4263] - authenticator to adapt to artemis jaas login modules…

Posted by "gtully (via GitHub)" <gi...@apache.org>.
gtully commented on code in PR #4458:
URL: https://github.com/apache/activemq-artemis/pull/4458#discussion_r1180324520


##########
artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/jaas/AuthenticatorAdapter.java:
##########
@@ -0,0 +1,128 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.activemq.artemis.spi.core.security.jaas;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.login.LoginContext;
+
+import java.security.Principal;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.StringTokenizer;
+
+import com.sun.net.httpserver.Authenticator;
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpPrincipal;
+import com.sun.net.httpserver.HttpsExchange;
+
+// delegate to our JAAS login modules by adapting our handlers to httpExchange
+// allow the jolokia jvm agent to integrate with our auth
+public class AuthenticatorAdapter extends Authenticator {

Review Comment:
   agree, thanks for the feedback



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [activemq-artemis] gemmellr commented on a diff in pull request #4458: [ARTEMIS-4263] - authenticator to adapt to artemis jaas login modules…

Posted by "gemmellr (via GitHub)" <gi...@apache.org>.
gemmellr commented on code in PR #4458:
URL: https://github.com/apache/activemq-artemis/pull/4458#discussion_r1180602494


##########
artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/jaas/AuthenticatorAdapter.java:
##########
@@ -0,0 +1,128 @@
+/**

Review Comment:
   Because this isnt the description, it isnt actually doc, its a licence header.  Its a waste of time for the javadoc processor to even be looking at it. Its formatted differently than it should be (has tags, and changed indent). Its inconsistent with the rest of the codebase (even the test in this same PR).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [activemq-artemis] gtully commented on a diff in pull request #4458: [ARTEMIS-4263] - authenticator to adapt to artemis jaas login modules…

Posted by "gtully (via GitHub)" <gi...@apache.org>.
gtully commented on code in PR #4458:
URL: https://github.com/apache/activemq-artemis/pull/4458#discussion_r1180324332


##########
artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/jaas/AuthenticatorAdapter.java:
##########
@@ -0,0 +1,128 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.activemq.artemis.spi.core.security.jaas;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.login.LoginContext;
+
+import java.security.Principal;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.StringTokenizer;
+
+import com.sun.net.httpserver.Authenticator;
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpPrincipal;
+import com.sun.net.httpserver.HttpsExchange;
+
+// delegate to our JAAS login modules by adapting our handlers to httpExchange
+// allow the jolokia jvm agent to integrate with our auth
+public class AuthenticatorAdapter extends Authenticator {
+
+   static final String REALM_PROPERTY_NAME = "jolokiaJvmAgent.realm";
+   static final String REQUEST_SUBJECT_ATTRIBUTE_PROPERTY_NAME = "jolokiaJvmAgent.requestSubjectAttribute";
+   static String DEFAULT_SUBJECT_ATTRIBUTE = "org.jolokia.jaasSubject";
+   static final String DEFAULT_REALM = "jolokia_jvm_agent";
+   static final String AUTHORIZATION_HEADER_NAME = "Authorization";
+
+   final String realm = System.getProperty(REALM_PROPERTY_NAME, DEFAULT_REALM);
+   final String subjectRequestAttribute = System.getProperty(REQUEST_SUBJECT_ATTRIBUTE_PROPERTY_NAME, DEFAULT_SUBJECT_ATTRIBUTE);
+
+   @Override
+   public Result authenticate(HttpExchange httpExchange) {
+
+      try {
+         LoginContext loginContext = new LoginContext(realm, callbacks -> {
+            for (Callback callback : callbacks) {
+               if (callback instanceof PasswordCallback) {
+                  PasswordCallback passwordCallback = (PasswordCallback) callback;
+
+                  StringTokenizer stringTokenizer = new StringTokenizer(extractAuthHeader(httpExchange));
+                  String method = stringTokenizer.nextToken();
+                  if ("Basic".equalsIgnoreCase(method)) {
+                     byte[] authHeaderBytes = Base64.getDecoder().decode(stringTokenizer.nextToken());
+
+                     // :pass
+                     byte[] password = Arrays.copyOfRange(authHeaderBytes, Arrays.binarySearch(authHeaderBytes, (byte) ':') + 1, authHeaderBytes.length);
+                     passwordCallback.setPassword(new String(password).toCharArray());

Review Comment:
   they should, thanks
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [activemq-artemis] gtully commented on a diff in pull request #4458: [ARTEMIS-4263] - authenticator to adapt to artemis jaas login modules…

Posted by "gtully (via GitHub)" <gi...@apache.org>.
gtully commented on code in PR #4458:
URL: https://github.com/apache/activemq-artemis/pull/4458#discussion_r1180323951


##########
artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/jaas/AuthenticatorAdapter.java:
##########
@@ -0,0 +1,128 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.activemq.artemis.spi.core.security.jaas;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.login.LoginContext;
+
+import java.security.Principal;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.StringTokenizer;
+
+import com.sun.net.httpserver.Authenticator;
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpPrincipal;
+import com.sun.net.httpserver.HttpsExchange;
+
+// delegate to our JAAS login modules by adapting our handlers to httpExchange
+// allow the jolokia jvm agent to integrate with our auth
+public class AuthenticatorAdapter extends Authenticator {
+
+   static final String REALM_PROPERTY_NAME = "jolokiaJvmAgent.realm";
+   static final String REQUEST_SUBJECT_ATTRIBUTE_PROPERTY_NAME = "jolokiaJvmAgent.requestSubjectAttribute";
+   static String DEFAULT_SUBJECT_ATTRIBUTE = "org.jolokia.jaasSubject";
+   static final String DEFAULT_REALM = "jolokia_jvm_agent";

Review Comment:
   good catch, those can be more generic, httpServerAuthenticator. without defaults.
   more eyes are great!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [activemq-artemis] gtully commented on a diff in pull request #4458: [ARTEMIS-4263] - authenticator to adapt to artemis jaas login modules…

Posted by "gtully (via GitHub)" <gi...@apache.org>.
gtully commented on code in PR #4458:
URL: https://github.com/apache/activemq-artemis/pull/4458#discussion_r1182300460


##########
artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/jaas/AuthenticatorAdapter.java:
##########
@@ -0,0 +1,128 @@
+/**

Review Comment:
   aah, ok, was looking at the wrong place. see the extra * in the licence template. sorted. thanks



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [activemq-artemis] gemmellr commented on a diff in pull request #4458: [ARTEMIS-4263] - authenticator to adapt to artemis jaas login modules…

Posted by "gemmellr (via GitHub)" <gi...@apache.org>.
gemmellr commented on code in PR #4458:
URL: https://github.com/apache/activemq-artemis/pull/4458#discussion_r1180602494


##########
artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/jaas/AuthenticatorAdapter.java:
##########
@@ -0,0 +1,128 @@
+/**

Review Comment:
   Because this isnt the description, it isnt actually doc, its a licence header.  Its a waste of time for the javadoc processor to even be looking at it. Its formatted differently than it should be (has tags, and changed indent). Its inconsistent with the rest of the codebase.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [activemq-artemis] gtully commented on a diff in pull request #4458: [ARTEMIS-4263] - authenticator to adapt to artemis jaas login modules…

Posted by "gtully (via GitHub)" <gi...@apache.org>.
gtully commented on code in PR #4458:
URL: https://github.com/apache/activemq-artemis/pull/4458#discussion_r1182758196


##########
artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/jaas/HttpServerAuthenticator.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>

Review Comment:
   sorted. thanks!



##########
artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/jaas/HttpServerAuthenticator.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.activemq.artemis.spi.core.security.jaas;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.security.auth.login.LoginContext;
+
+import java.nio.charset.StandardCharsets;
+import java.security.Principal;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.StringTokenizer;
+
+import com.sun.net.httpserver.Authenticator;
+import com.sun.net.httpserver.HttpExchange;
+import com.sun.net.httpserver.HttpPrincipal;
+import com.sun.net.httpserver.HttpsExchange;
+
+/**
+ * delegate to our JAAS login modules by adapting our handlers to httpserver.httpExchange
+ */
+public class HttpServerAuthenticator extends Authenticator {
+
+   static final String REALM_PROPERTY_NAME = "httpServerAuthenticator.realm";
+   static final String REQUEST_SUBJECT_ATTRIBUTE_PROPERTY_NAME = "httpServerAuthenticator.requestSubjectAttribute";
+   static String DEFAULT_SUBJECT_ATTRIBUTE = "org.apache.activemq.artemis.jaasSubject";
+   static final String DEFAULT_REALM = "http_server_authenticator";
+   static final String AUTHORIZATION_HEADER_NAME = "Authorization";
+
+   final String realm = System.getProperty(REALM_PROPERTY_NAME, DEFAULT_REALM);
+   final String subjectRequestAttribute = System.getProperty(REQUEST_SUBJECT_ATTRIBUTE_PROPERTY_NAME, DEFAULT_SUBJECT_ATTRIBUTE);
+
+   @Override
+   public Result authenticate(HttpExchange httpExchange) {
+
+      try {
+         LoginContext loginContext = new LoginContext(realm, callbacks -> {
+            for (Callback callback : callbacks) {
+               if (callback instanceof PasswordCallback) {
+                  PasswordCallback passwordCallback = (PasswordCallback) callback;
+
+                  StringTokenizer stringTokenizer = new StringTokenizer(extractAuthHeader(httpExchange));
+                  String method = stringTokenizer.nextToken();
+                  if ("Basic".equalsIgnoreCase(method)) {
+                     byte[] authHeaderBytes = Base64.getDecoder().decode(stringTokenizer.nextToken());
+
+                     // :pass
+                     byte[] password = Arrays.copyOfRange(authHeaderBytes, Arrays.binarySearch(authHeaderBytes, (byte) ':') + 1, authHeaderBytes.length);
+                     passwordCallback.setPassword(new String(password, StandardCharsets.UTF_8).toCharArray());
+                  } else if ("Bearer".equalsIgnoreCase(method)) {
+                     passwordCallback.setPassword(stringTokenizer.nextToken().toCharArray());
+                  }
+               } else if (callback instanceof NameCallback) {
+                  NameCallback nameCallback = (NameCallback) callback;
+
+                  StringTokenizer stringTokenizer = new StringTokenizer(extractAuthHeader(httpExchange));
+                  String method = stringTokenizer.nextToken();
+                  if ("Basic".equalsIgnoreCase(method)) {
+                     byte[] authHeaderBytes = Base64.getDecoder().decode(stringTokenizer.nextToken());
+
+                     // user:
+                     byte[] user = Arrays.copyOfRange(authHeaderBytes, 0, Arrays.binarySearch(authHeaderBytes, (byte) ':'));
+                     nameCallback.setName(new String(user));

Review Comment:
   indeed, sorted



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [activemq-artemis] gtully merged pull request #4458: [ARTEMIS-4263] - authenticator to adapt to artemis jaas login modules…

Posted by "gtully (via GitHub)" <gi...@apache.org>.
gtully merged PR #4458:
URL: https://github.com/apache/activemq-artemis/pull/4458


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org