Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
user-manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OZG-Cloud
app
user-manager
Commits
d722ac58
Commit
d722ac58
authored
2 years ago
by
OZGCloud
Browse files
Options
Downloads
Patches
Plain Diff
OZG-3322 build key store like in zufi
parent
3202951f
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
user-manager-server/src/main/java/de/itvsh/kop/user/MongodbCertificateLoader.java
+33
-2
33 additions, 2 deletions
...main/java/de/itvsh/kop/user/MongodbCertificateLoader.java
with
33 additions
and
2 deletions
user-manager-server/src/main/java/de/itvsh/kop/user/MongodbCertificateLoader.java
+
33
−
2
View file @
d722ac58
...
@@ -8,7 +8,9 @@ import java.nio.file.Paths;
...
@@ -8,7 +8,9 @@ import java.nio.file.Paths;
import
java.security.KeyStore
;
import
java.security.KeyStore
;
import
java.security.KeyStoreException
;
import
java.security.KeyStoreException
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.cert.Certificate
;
import
java.security.cert.CertificateException
;
import
java.security.cert.CertificateException
;
import
java.security.cert.CertificateFactory
;
import
javax.enterprise.context.ApplicationScoped
;
import
javax.enterprise.context.ApplicationScoped
;
import
javax.enterprise.event.Observes
;
import
javax.enterprise.event.Observes
;
...
@@ -27,15 +29,44 @@ class MongodbCertificateLoader {
...
@@ -27,15 +29,44 @@ class MongodbCertificateLoader {
void
onStart
(
@Observes
StartupEvent
ev
)
throws
KeyStoreException
,
CertificateException
,
IOException
,
NoSuchAlgorithmException
{
void
onStart
(
@Observes
StartupEvent
ev
)
throws
KeyStoreException
,
CertificateException
,
IOException
,
NoSuchAlgorithmException
{
if
(
Files
.
exists
(
Paths
.
get
(
mongoDbCaCert
)))
{
if
(
Files
.
exists
(
Paths
.
get
(
mongoDbCaCert
)))
{
buildKeyStore
();
System
.
out
.
println
(
"loading cert..."
);
System
.
out
.
println
(
"loading cert..."
);
KeyStore
keystore
=
KeyStore
.
getInstance
(
"pkcs12"
);
//
KeyStore keystore = KeyStore.getInstance("pkcs12");
keystore
.
load
(
loadCaCrt
(),
null
);
//
keystore.load(loadCaCrt(), null);
System
.
out
.
println
(
"cert loaded"
);
System
.
out
.
println
(
"cert loaded"
);
}
else
{
}
else
{
System
.
out
.
println
(
"cert file does not exists"
);
System
.
out
.
println
(
"cert file does not exists"
);
}
}
}
}
KeyStore
buildKeyStore
()
{
try
{
var
trustStore
=
initKeyStore
();
trustStore
.
setCertificateEntry
(
"ca"
,
generateCertificate
());
return
trustStore
;
}
catch
(
Exception
e
)
{
throw
new
TechnicalException
(
"Error building KeyStore"
,
e
);
}
}
KeyStore
initKeyStore
()
{
try
{
var
trustStore
=
KeyStore
.
getInstance
(
"pkcs12"
);
trustStore
.
load
(
null
,
null
);
return
trustStore
;
}
catch
(
Exception
e
)
{
throw
new
TechnicalException
(
"Error init KeyStore"
,
e
);
}
}
Certificate
generateCertificate
()
{
try
{
return
CertificateFactory
.
getInstance
(
"X.509"
).
generateCertificate
(
loadCaCrt
());
}
catch
(
Exception
e
)
{
throw
new
TechnicalException
(
"Error generating Certificate"
,
e
);
}
}
InputStream
loadCaCrt
()
{
InputStream
loadCaCrt
()
{
try
{
try
{
return
Files
.
newInputStream
(
Paths
.
get
(
mongoDbCaCert
));
return
Files
.
newInputStream
(
Paths
.
get
(
mongoDbCaCert
));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment