-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18049d7
commit c0b1282
Showing
4 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.wso2.samples.is</groupId> | ||
<artifactId>oidc-sso-sample</artifactId> | ||
<version>4.6.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>oidc-keystore-loader</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>servlet-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<sourceDirectory>src/main</sourceDirectory> | ||
<finalName>oidc-jks-loader</finalName> | ||
|
||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>maven-scr-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>generate-scr-scrdescriptor</id> | ||
<phase>none</phase> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> | ||
|
84 changes: 84 additions & 0 deletions
84
...so-sample/oidc-keystore-loader/src/main/java/org/wso2/sample/identity/KeystoreLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. | ||
* | ||
* WSO2 Inc. 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.wso2.sample.identity; | ||
|
||
import java.net.URISyntaxException; | ||
import java.nio.file.Paths; | ||
import javax.servlet.ServletContextEvent; | ||
import javax.servlet.ServletContextListener; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.URL; | ||
import java.util.Properties; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* A listener to get invoked at application deployment. | ||
* This will allow us to set the carbon keystore for HTTPS communication. | ||
*/ | ||
public class KeystoreLoader implements ServletContextListener { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(KeystoreLoader.class.getName()); | ||
|
||
@Override | ||
public void contextInitialized(ServletContextEvent servletContextEvent) { | ||
// First find keystore properties | ||
final InputStream keystoreInputStream = this.getClass().getClassLoader() | ||
.getResourceAsStream("keystore.properties"); | ||
|
||
if (keystoreInputStream == null) { | ||
LOGGER.log(Level.SEVERE, "keystore.properties not found. Trust store properties will not be set."); | ||
return; | ||
} | ||
|
||
// Load properties | ||
final Properties keystoreProperties = new Properties(); | ||
|
||
try { | ||
keystoreProperties.load(keystoreInputStream); | ||
} catch (IOException e) { | ||
LOGGER.log(Level.SEVERE, "Error while loading properties.", e); | ||
return; | ||
} | ||
|
||
// Find and set keystore required for IS server communication | ||
final URL resource = this.getClass().getClassLoader() | ||
.getResource(keystoreProperties.getProperty("keystorename")); | ||
|
||
if (resource != null) { | ||
try { | ||
String trustStorePath = Paths.get(resource.toURI()).toFile().getAbsolutePath(); | ||
LOGGER.log(Level.INFO, "Setting trust store path to : " + trustStorePath); | ||
System.setProperty("javax.net.ssl.trustStore", trustStorePath); | ||
} catch (URISyntaxException e) { | ||
LOGGER.log(Level.SEVERE, "Unable to find keystore defined by properties. " + | ||
"Trust store properties will not be set.", e); | ||
} | ||
System.setProperty("javax.net.ssl.trustStorePassword", keystoreProperties.getProperty("keystorepassword")); | ||
} else { | ||
LOGGER.log(Level.INFO, "Unable to find keystore defined by properties. " + | ||
"Trust store properties will not be set."); | ||
} | ||
} | ||
|
||
@Override | ||
public void contextDestroyed(ServletContextEvent servletContextEvent) { | ||
// Ignored | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters