Placeholders within UAA_CONFIG_YAML environment variable - cloudfoundry-uaa

I'm trying to set the SMTP settings within the UAA_CONFIG_YAML section of the manifest.
smtp:
host: ${vcap.services.smtpdev.credentials.hostname:localhost}
port: 2525
user: ${vcap.services.smtpdev.credentials.username:user}
password: ${vcap.services.smtpdev.credentials.password:password}
This doesn't work yet the default of localhost is being picked up. If I provide an invalid placeholder it throws an error.

The way I have done it, I have set the UAA_CONFIG_PATH environment variable which points to the location of the yaml file.
The settings are provided as follows:
smtp:
host: smtp.gmail.com
port: <port_number>
auth: true
starttls.enable: false
user: <username>
password: <password>
These values are getting picked up by uaa.
Please let me know if it was helpful.

Related

"Couldn't connect to host" occurs when trying to send mail from Gmail with Spring-Boot mail in Admin Server

I want to send mail as a reminder in Admin Server
But get this error:
com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.gmail.com, 587; timeout 20000
...
I have searched a lot online but still don't work
My Admin Server Application YAML configuration file:
spring:
security:
user:
name: admin
password: 123456
boot:
admin:
notify:
mail:
enabled: true
# receivers
to: xxx#outlook.com
ignore-changes: {"UNKNOWN:UP"}
# copy-to list
cc:
from: Spring Boot Admin<xxx#gmail.com>
# mail sender
mail:
host: smtp.gmail.com
port: 587
username: xxx#gmail.com
# with 2-factor authentication, we should get app password from Google
password: my-app-password
default-encoding: UTF-8
properties:
mail:
smtp:
connectiontimeout: 20000
timeout: 20000
writetimeout: 20000
starttls:
enable: true
required: true
auth: true
ssl:
enable: true
required: true
debug: true
server:
port: 8081
I config the settings with the help of this instruction
btw, 2-factor authentication is enabled with my Google account, so I followed this instruction to get my "app password"
But after I start my Admin Server application, and wait 20 second, the error appears
I have tried change port to 465, not working
I have tried spring.mail.properties.mail.smtp.socketFactory.port and configure it to 465, not working
I'm using Windows 11 and windows firewall has no Outbound rule against java, java platform, intelliJ idea, there're Inbound rules that block java and java(TM) platform, not working
With my config above, Admin Server should send a mail to xxx#outlook.com from xxx#gmail.com.

How to disable authentication while testing email service using greenmail

I have written an email service using Spring Email and then used Greenmail to test the email service. But while running the test case it gives an error Authentication failed as below:
javax.mail.AuthenticationFailedException: 535 5.7.0 Authentication credentials invalid at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:965)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:876)
How can this error be resolved without giving my username/password in the code. Note that I have also tried giving username/password but it failed with the same exception. Thanks for any help.
greenMail = new GreenMail(new ServerSetup(2525, "127.0.0.1", "smtp"));
greenMail.setUser("username", "secret");
When Setting up your greenmail instance for testing you need to use the setUser and enter
username and password above and then add the properties specified in the #One Guy post above this. has worked for me after I received the Authentication credentials invalid Exception.
Hope this helps anyone facing a the issue
See AuthenticationDisabledTest.java how to configure a GreenMail junit test using disabled authentication.
Looks like you don't added the mock credentials i.e. a a resource file called application-test.yml file which is located in the src/test/resources folder.
application.yml
spring:
mail:
default-encoding: UTF-8
host: localhost
jndi-name:
username: username
password: secret
port: 2525
properties:
mail:
debug: false
smtp:
debug: false
auth: true
starttls: true
protocol: smtp
test-connection: false
You can take a look an example by following link:
https://memorynotfound.com/spring-mail-integration-testing-junit-greenmail-example/

How to run Mongodb as a service with authentication on a windows machine

remark: I am using win10.
My goal is when windows boot mongodb as a service with authentication start( you can not enter the database without authenticate) but I can not manage to do it on a windows machine ( in linux it worked)
I write here the steps I tried:
dowlnload MongoDB
change conf from default to the following
# mongod.conf
http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: C:\MongoDB\Server\4.0\data
journal:
enabled: true
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: C:\MongoDB\Server\4.0\log\mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
security:
authorization: enabled
setParameter:
enableLocalhostAuthBypass: false
create a Admin user in the Admin collection.
db.createUser(
{
user: "....",
pwd: "...",
roles:
[
{ role: "root", db: "admin" }
]
}
)
Made it a service:
sc.exe create MongoDB
binPath=“\”C:\MongoDB\Server\4.0\bin\mongod.exe\”
–service
config=\”C:\MongoDB\Server\4.0\bin\mongod.cfg\”” DisplayName= “MongoDB” start= “auto”
getting feedback Successful.
but when i restart the computer, mongod is not starting and if i dont specify mongod --auth i can still enter without a authentication
How can I run Mongod as service with authentication? what am i doing wrong?
When i am trying to activate the service manually I get the following error
Error photo
The issue with the security tag. I have the same issue when I wanted to start the service in Windows 10. I copy the command from Windows service properties and then run on the command prompt.
The prompt shows me the error:
Unrecognized category : security
I found the solution and it is to write the security tag with options properly.
YAML need some specific input I guess. Here it is the solution.
security:
authorization: enabled
I had the same issue.
In your mongodb.cfg, use 2 spaces (instead of TAB) to indent authorization: enabled

ELK stack configure alert email

Trying to configure email in Kibana, documentation states to modify elasticsearch.yml
elasticsearch\config\elasticsearch.yml
Added the following at the bottom:
xpack.notification.email.account:
account:
smtp:
auth: false
starttls.enable: true
starttls.required: false
host: localhost
port: 25
When I start service and do "test send email" i get error sending email
How does one configure emailing for alerts.
Am i editing the right configuration file?
Figured it out. I was able to enable emailing through gmail.
elasticsearch\config\elasticsearch.yml
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
xpack.notification.email.account:
gmail_account:
profile: gmail
smtp:
auth: true
starttls.enable: true
host: smtp.gmail.com
port: 587
user: yourmeail#gmail.com
password: ******* your password

How to configure SSL mongodb connection in YML file spring boot?

I was trying to setup a ssl mongodb connection from spring boot but I couldn't able to find a way to set a connection from YML file(beacuse it's easy to maintain dev and prod environment). How can I add client.PEM and rootCA.pem keys to below connection?
Please note this not a database administration question!
data:
mongodb:
authentication-database: admin
database: <database>
host: <host>
password: <password>
port: <port>
username: <username>
One way to resolve it is simple use URI string connect and database name in your application.yml file. Example:
data:
mongodb:
database: &ltdatabaseName&gt
uri: &ltmongodb://[username:password#]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]&gt
Example with SSL option:
mongodb://user:password#mongoServer:27017/?ssl=true
More info here https://docs.mongodb.com/manual/reference/connection-string/

Resources