2019-01-16

ActiveMQ JMX - Password Protecting service:jmx:rmi(port:1099) & tcp(port:61616)


Password Protecting the Broker - service:jmx:rmi: (JMX Connector)
Implemented: activemq.bat & activemq.xml

Reference URL:

in file: activemq.xml
Change:    <broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}">
To:    <broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}" useJmx="true">

Optional:
Change: <managementContext createConnector="false"/>
To: <managementContext createConnector="true" rmiServerPort="1098"  connectorPort="1099" />


in file: activemq.bat
After line of: if "%ACTIVEMQ_SUNJMX_START%" == "" set ACTIVEMQ_SUNJMX_START=-Dcom.sun.management.jmxremote
SET ACTIVEMQ_SUNJMX_START=-Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.password.file="%ACTIVEMQ_BASE%/conf/jmx.password" -Dcom.sun.management.jmxremote.access.file="%ACTIVEMQ_BASE%/conf/jmx.access"
Double quote (") here to avoid space in ur full path.
eg:  "C:\Program Files\ActiveMQ\"



Test if startup correctly:
Reference URL:
http://www.cleantutorials.com/jconsole/downloading-jconsole-and-connecting-it-to-a-local-java-process

Run: C:\Program Files\Java\jdk1.8.0_192\bin\jconsole.exe

host=localhost:1099
id=admin
password=activemq





Caused by:
Error: Password file read access must be restricted: <Path>\ActiveMQ\apache-activemq-5.13.2\bin\../conf/jmx.password
sun.management.AgentConfigurationError
        at sun.management.jmxremote.ConnectorBootstrap.checkPasswordFile(ConnectorBootstrap.java:577)
        at sun.management.jmxremote.ConnectorBootstrap.startRemoteConnectorServer(ConnectorBootstrap.java:426)
        at sun.management.Agent.startAgent(Agent.java:262)
        at sun.management.Agent.startAgent(Agent.java:452)



Reference URL:
https://docs.oracle.com/javase/6/docs/technotes/guides/management/security-windows.html

Solved by:

 To Secure a Password File on Windows XP Home Edition

As stated above, Windows XP Home Edition does not allow you to set file permissions graphically. However, you can set permissions using the cacls command.
  1. Open a command prompt window.
  2. Run the following command
    C:\MyPasswordFile>cacls jmxremote.password
    
    This command displays the access control list (ACL) of the jmxremote.password file.
  3. Set the access rights so that only your username has read access.
    When no users have been configured on the machine the default username is usually Owner, or a localized translation of Owner.
    C:\MyPasswordFile>cacls jmxremote.password /P [Owner]:R
    
    This command grants access to the user Owner with read-only permission, where Owner is the owner of the jmxremote.password file.
  4. Display the ACL again.
    C:\MyPasswordFile>cacls jmxremote.password
    
    This time, you will see that only the Owner has access to the password file.



How to identify [Owner] at above command:


Reference URL:
https://www.windows-commandline.com/current-logged-in-user-name-command/

Solved by:
ECHO %username%
or
whoami



Caused by:
java.lang.SecurityException: Authentication failed! Credentials required



Reference URL:
https://stackoverflow.com/questions/4679877/tomcat-jmx-connection-authentication-failed?rq=1

Solved by: Add credential into config and pass into connect function:

...
String url = "JMSRMIURL=service:jmx:rmi://localhost:1098/jndi/rmi://localhost:1099/jmxrmi";
JMXServiceURL urlJmxService = new JMXServiceURL( url );
Hashtable<String, String[]> credential = new Hashtable<String, String[]>();
credential.put(JMXConnector.CREDENTIALS, new String[]{"your_login_id","your_login_password"});
JMXConnector connector = JMXConnectorFactory.connect( urlJmxService, credential);
connector.connect();
...

Reference:
JMXServiceURL url = new JMXServiceURL(urlString);         
Hashtable<String, String[]> env = new Hashtable<String, String[]>();
String[] credentials = new String[] {user,pass};
env.put(JMXConnector.CREDENTIALS, credentials);         
jmxc = JMXConnectorFactory.connect(url,env); 
mbsc = jmxc.getMBeanServerConnection(); 



How to stop activemq after enabled JMX:
Reference URL: http://activemq.apache.org/activemq-command-line-tools-reference.html
activemq-admin stop --jmxurl service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi --jmxuser admin --jmxpassword activemq

activemq-admin list --jmxurl service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi --jmxuser admin --jmxpassword activemq


But not sure even able to stop it using only: activemq-admin stop










Password Protecting the Broker - TCP(port:61616)
Implemented: activemq.xml, login.config

Reference URL:
https://blog.csdn.net/jaylong35/article/details/6968903





Issue during implementation:

Issue#1of2
...ERROR | Failed to load: class path resource [activemq.xml], reason: Line 53 in XML document from class path resource [activemq.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 53; columnNumber: 27; Element type "authorizationEntry" must be followed by either attribute specifications, ">" or "/>".org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 53 in XML document from class path resource [activemq.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 53; columnNumber: 27; Element type "authorizationEntry" must be followed by either attribute specifications, ">" or "/>"....ERROR: java.lang.RuntimeException: Failed to execute start task. Reason: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 53 in XML document from class path resource [activemq.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 53; columnNumber: 27; Element type "authorizationEntry" must be followed by either attribute specifications, ">" or "/>".java.lang.RuntimeException: Failed to execute start task. Reason: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 53 in XML document from class path resource [activemq.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 53; columnNumber: 27; Element type "authorizationEntry" must be followed by either attribute specifications, ">" or "/>"....



Caused by: Having special character issue between "authorizationEntry" "queue"

authorizationEntry queue

Solved by: Use Notepad++ to replace this character(" ") by a normal space (" ").

Add the <plugin></plugin>
into config/activemq.xml





partial xml in <broker></broker> from config/activemq.xml
<plugins>
<!-- Configure authentication; Username, passwords and groups 添加jaas认证插件 activemq-domain 在login.config里面定义,详细见 login.config -->
<jaasAuthenticationPlugin configuration="ActiveMQ_Credentials" />


<!-- Lets configure a destination based authorization mechanism 配置队列用户权限,>表示任意字符 -->
<authorizationPlugin>
  <map>
    <authorizationMap>
      <authorizationEntries>
        <authorizationEntry queue=">" read="admins" write="admins" admin="admins" />
        <authorizationEntry queue="USERS.>" read="users" write="users" admin="users" />
        <authorizationEntry queue="GUEST.>" read="guests" write="guests,users" admin="guests,users" />


        <authorizationEntry queue="TEST.Q" read="guests" write="guests" />


        <authorizationEntry topic=">" read="admins" write="admins" admin="admins" />
        <authorizationEntry topic="USERS.>" read="users" write="users" admin="users" />
        <authorizationEntry topic="GUEST.>" read="guests" write="guests,users" admin="guests,users" />
        <authorizationEntry topic="ActiveMQ.Advisory.>" read="guests,users" write="guests,users" admin="guests,users"/>
      </authorizationEntries>
    </authorizationMap>
  </map>
</authorizationPlugin>
</plugins>
<!--
===================== 
作者:jaylong35 
来源:CSDN 
原文:https://blog.csdn.net/jaylong35/article/details/6968903 
版权声明:本文为博主原创文章,转载请附上博文链接!
-->










Issue#2of2
in eclipse
Caused by: java.io.IOException: Configuration Error:
Invalid control flag,

Caused by: comment is not support within config


Solved by: Remove comment





in config/login.config


ActiveMQ_Credentials {
    org.apache.activemq.jaas.PropertiesLoginModule required
reload=true
debug=true
        org.apache.activemq.jaas.properties.user="users.properties"        org.apache.activemq.jaas.properties.group="groups.properties";};





in users.properties

admin=adminggggg=aeaea






in groups.properties

admins=adminusers=ggggg







2 implementations above will have 2 sets of credential maintenance.

Following is to simplify this maintenance task:

Reference URL: https://access.redhat.com/documentation/en-US/Fuse_ESB/4.4.1/html/ActiveMQ_Security_Guide/files/JMX-AmqConnector-Authent.html


For my case, both connections(jmx service & tcp), but could be more which refer to <transportConnectors></transportConnectors>



1 of 3 edits; in activemq.xml:
Add <plugins> below into <broker></broker>


<plugins>
<!-- Configure authentication; Username, passwords and groups 添加jaas认证插件 activemq-domain 在login.config里面定义,详细见 login.config -->
<jaasAuthenticationPlugin configuration="ActiveMQ_Credentials" />


<!-- Lets configure a destination based authorization mechanism 配置队列用户权限,>表示任意字符 -->
<authorizationPlugin>
  <map>
    <authorizationMap>
      <authorizationEntries>
        <authorizationEntry queue=">" read="admins" write="admins" admin="admins" />
        <authorizationEntry queue="USERS.>" read="users" write="users" admin="users" />
        <authorizationEntry queue="GUEST.>" read="guests" write="guests,users" admin="guests,users" />


        <authorizationEntry queue="TEST.Q" read="guests" write="guests" />


        <authorizationEntry topic=">" read="admins" write="admins" admin="admins" />
        <authorizationEntry topic="USERS.>" read="users" write="users" admin="users" />
        <authorizationEntry topic="GUEST.>" read="guests" write="guests,users" admin="guests,users" />
        <authorizationEntry topic="ActiveMQ.Advisory.>" read="guests,users" write="guests,users" admin="guests,users"/>
      </authorizationEntries>
    </authorizationMap>
  </map>
</authorizationPlugin>
</plugins>
<!--
===================== 
作者:jaylong35 
来源:CSDN 
原文:https://blog.csdn.net/jaylong35/article/details/6968903 
版权声明:本文为博主原创文章,转载请附上博文链接!
-->


2 of 3 edits; in activemq.xml:
Replace
<managementContext createConnector="false" />
by
<managementContext> at below
into
<managementContext></managementContext>




<managementContext createConnector="true" rmiServerPort="1098"  connectorPort="1099" jmxDomainName="org.apache.activemq" >
<property xmlns="http://www.springframework.org/schema/beans" name="environment">
<map xmlns="http://www.springframework.org/schema/beans">
<entry xmlns="http://www.springframework.org/schema/beans"
   key="jmx.remote.x.login.config"
   value="ActiveMQ_Credentials"/>
  </map>
</property>
</managementContext>



3 of 3 edits; in login.config:
Add block below below activemq block




ActiveMQ_Credentials {
org.apache.activemq.jaas.PropertiesLoginModule required
reload=true
debug=true
org.apache.activemq.jaas.properties.user="users.properties"
org.apache.activemq.jaas.properties.group="groups.properties";
};




















2019-01-15

activemq.bat


Windows 10
portable activemq

failed to start up due to:

JAVA_HOME

and

Error: Could not find or load main class Resources\M1\ActiveMQ\apache-activemq-5.13.2\bin\..\conf\login.config



Reference URL:
https://issues.apache.org/jira/browse/AMQ-5243?focusedCommentId=14349533&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-14349533







JAVA_HOME
Add at the beginning of activemq.bat

SET JAVA_HOME=C:\Program Files\Java\jdk1.8.0_192\


Error: Could not find or load main class Resources\M1\ActiveMQ\apache-activemq-5.13.2\bin\..\conf\login.config

Change
if "%ACTIVEMQ_OPTS%" == "" set ACTIVEMQ_OPTS=-Xms1G -Xmx1G -Djava.util.logging.config.file=logging.properties -Djava.security.auth.login.config=%ACTIVEMQ_CONF%\login.config

to

if "%ACTIVEMQ_OPTS%" == "" set ACTIVEMQ_OPTS=-Xms1G -Xmx1G -Djava.util.logging.config.file=logging.properties -Djava.security.auth.login.config="%ACTIVEMQ_CONF%\login.config"
















2018-12-26

iPhone stuck at apple logo





When you get the option to restore or update, choose Update. iTunes will try to reinstall iOS without erasing your data.

https://support.apple.com/en-sg/HT201412



After install OS, iPhone will restart, and go into this: "Attempting data recovery"
Took 2hrs for:

  1. Download itunes.
  2. Install itunes.
  3. Update iPhone 6 Plus, 128GB.
  4. Turned off, force restart.
  5. Update iPhone 6 Plus, 128GB.
  6. Data recovery.
  7. Update Completed on screen.
















2018-12-21

Maven repository with ID and Password.








Referene URL:
https://www.onehippo.org/library/enterprise/enterprise-developer-information/hippo-maven-enterprise-repository-manual.html













Finding:

seems 2 sets(settings.xml & pom.xml) of maven config above linked by tag "<id>" so username & password in settings.xml will be used for repository.












































2018-12-18

Install DotCms "Caused by: com.dotmarketing.exception.DotRuntimeException: No Company!"



Reference URL:
https://groups.google.com/forum/#!topic/dotcms/fxUv2Q1hy2A





Caused by: ran ./bin/startup.sh script without sudo.


Solutions:
cd /home/dotcms/Programs/CMSs/dotcms_5.0.3;

sudo ./bin/startup.sh













2018-12-11

CsvToBean unable to get 1st column





Reference URL:
https://stackoverflow.com/questions/42328597/opencsv-populating-first-column-as-null


I met the same problem.

Solution

I saved the csv file again by utf-8 without BOM.
Then the first column is set with correct value.
No code needs to be changed.
I use the text editor named sakura.After choosing encoding as utf-8,a checkbox of BOM is enabled.Uncheck it and save the csv file.I think other editors have the same BOM option.

Reason

A BOM-ed UTF-8 string will start with the three following bytes. EF BB BF
The three bytes added to your csv file may changed your first column name.
  • Rather than link to existing questions you should raise a flag to mark this question as a duplicate of the one you believe answers it. – Neil Lunn May 31 '17 at 10:25


Ant builder from old environment hit issue after move to new IDE and new Machine(laptop)




Java Virtual Machine Launcher
A Java Exception has occurred.

Building workspace, Ant build





[eclipse-workspaces]\eclipse-jee-photon-R-win32-x86_64\.metadata\.log



!ENTRY org.eclipse.ant.launching 4 120 2018-12-11 14:46:39.726
!MESSAGE Error logged from Ant UI:
!STACK 0
java.net.SocketTimeoutException: Accept timed out
at java.net.DualStackPlainSocketImpl.waitForNewConnection(Native Method)
at java.net.DualStackPlainSocketImpl.socketAccept(Unknown Source)
at java.net.AbstractPlainSocketImpl.accept(Unknown Source)
at java.net.PlainSocketImpl.accept(Unknown Source)
at java.net.ServerSocket.implAccept(Unknown Source)
at java.net.ServerSocket.accept(Unknown Source)
at org.eclipse.ant.internal.launching.launchConfigurations.RemoteAntBuildListener$ServerConnection.run(RemoteAntBuildListener.java:89)










[Project Properties](Alt + Enter) > Builder

Select Ant Builder from the listing.
Edit
JRE
Separate JRE: Select JDK 1.8

































Windows 10 change login id




Solution
Reference URL:
https://www.groovypost.com/howto/change-account-name-windows-10/





Method 2: User Accounts Advanced Control Panel
There is another way you can do it. Press Windows key + R, type: netplwiz or control userpasswords2 then hit Enter. Select the account then click Properties


Select the General tab then enter the user name you want to use. Click Apply then OK, then click Apply then OK again to confirm the change.


2018-12-10

Spring controller submit chinese character into DB via JPA.






Web page chinese character to tomcat via Spring



Solved by solution below:
https://stackoverflow.com/questions/4318664/save-chinese-characters-with-spring-mvc-java





<filter>
    <filter-name>charsetFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>charsetFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>






Tomcat Java to MySql

SHOW VARIABLES LIKE "%version%";


mysql> SHOW VARIABLES LIKE "%version%";
+-------------------------+------------------------------+
| Variable_name           | Value                        |
+-------------------------+------------------------------+
| innodb_version          | 5.7.23                       |
| protocol_version        | 10                           |
| slave_type_conversions  |                              |
| tls_version             | TLSv1,TLSv1.1                |
| version                 | 5.7.23                       |
| version_comment         | MySQL Community Server (GPL) |
| version_compile_machine | x86_64                       |
| version_compile_os      | Linux                        |
+-------------------------+------------------------------+
8 rows in set (0.00 sec)




Normally with this would be enough to solve the encoding

https://stackoverflow.com/questions/4782077/execute-mysql-query-contains-chinese-character-using-java-program

Try connecting with following switch
 String url = "jdbc:mysql://host/database?characterSetResults=UTF-8&characterEncoding=UTF-8&useUnicode=yes";




But I'm using JPA

https://stackoverflow.com/questions/18163328/jpa-utf-8-characters-not-persisted
Solved by solution below:
use the character encoding in the property of persistence.xml file
<property name="javax.persistence.jdbc.url" 
   value="jdbc:mysql://localhost:3306/blogdatabase?useUnicode=yes&amp;characterEncoding=UTF-8"/>































2018-12-06

eClipse Photon- Run As: maven install hit "Error: Could not find or load main class TLSv1.2"








Caused by: javax.net.ssl.SSLException: Received fatal alert: protocol_version



JDK 7 issues from https://feitianbenyue.iteye.com/blog/2429045:

由于我的同事, 使用的 jdk 是 1.7 , jdk1.7虽然支持TLS 1.2 但是默认是 disabled的, 所以就会出现上面的 Received fatal alert: protocol_version  异常

下表格是 根据Oracle文档 各版本JDK默认使用的TLS协议:

JDK 8
(March 2014 to present)
JDK 7
(July 2011 to present)
JDK 6
(2006 to end of 2013)
TLS ProtocolsTLSv1.2 (default)
TLSv1.1
TLSv1
SSLv3
TLSv1.2
TLSv1.1
TLSv1 (default)
SSLv3

TLS v1.1 (JDK 6 update 111+)
TLSv1 (default)
SSLv3
Resolve by using
3. 解决方案
3.1 方案1 :   使用 http  去访问 maven  中央仓库




In Maven User Settings(settings.xml), assigned xml config below to my profile.

<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://repo1.maven.org/maven2</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>repo.maven.apache.org</id>
<url>https://repo.maven.apache.org/maven2</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>



Reference URL:

  1. https://feitianbenyue.iteye.com/blog/2429045
  2. https://stackoverflow.com/questions/6352208/how-to-solve-plugin-execution-not-covered-by-lifecycle-configuration-for-sprin
  3. https://stackoverflow.com/questions/14396017/difference-between-repository-and-pluginrepository













Google Referrals