Author: trong.tran
Date: 2011-10-18 00:19:04 -0400 (Tue, 18 Oct 2011)
New Revision: 7760
Modified:
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ExoContainerConfig.java
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ExoOAuthModule.java
portal/trunk/gadgets/server/src/main/webapp/containers/default/container.js
Log:
GTNPORTAL-2175 The default OAuth signing key should NOT be automatically generated if it
does not exist
Modified:
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ExoContainerConfig.java
===================================================================
---
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ExoContainerConfig.java 2011-10-17
23:09:57 UTC (rev 7759)
+++
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ExoContainerConfig.java 2011-10-18
04:19:04 UTC (rev 7760)
@@ -88,7 +88,7 @@
private void initializeTokenKeyFile()
{
- String keyPath =
PropertyManager.getProperty("gatein.gadgets.securityTokenKeyFile");
+ String keyPath =
PropertyManager.getProperty("gatein.gadgets.securitytokenkeyfile");
File tokenKeyFile = null;
if (keyPath == null)
@@ -101,82 +101,80 @@
tokenKeyFile = new File(keyPath);
}
- boolean isCreated = initializeKeyFile(tokenKeyFile);
- if (isCreated)
+ keyPath = tokenKeyFile.getAbsolutePath();
+ if (tokenKeyFile.exists())
{
- setTokenKeyPath(tokenKeyFile.getAbsolutePath());
- }
- }
-
- private void initializeSigningKeyFile()
- {
- String signingKey =
PropertyManager.getProperty("gatein.gadgets.signingKeyFile");
-
- File signingKeyFile;
- if (signingKey == null)
- {
- log.warn("The gadgets signing key is not configured. The default
oauthkey.pem file in /bin will be used");
- signingKeyFile = new File("oauthkey.pem");
- }
- else
- {
- signingKeyFile = new File(signingKey);
- }
-
- boolean isCreated = initializeKeyFile(signingKeyFile);
- if (isCreated)
- {
- signingKey_ = signingKeyFile.getAbsolutePath();
- }
- }
-
- private boolean initializeKeyFile(File file)
- {
- String keyPath = file.getAbsolutePath();
- if (file.exists())
- {
- if (file.isFile())
+ if (tokenKeyFile.isFile())
{
- log.info("Found key file " + keyPath + " for gadgets
security");
+ setTokenKeyPath(keyPath);
+ log.info("Found token key file " + keyPath + " for gadgets
security");
}
else
{
- log.error("Found path file " + keyPath + " but it's not a
key file");
+ log.error("Found token path file " + keyPath + " but it's
not a key file");
}
}
else
{
- log.debug("No key file found at path " + keyPath + ". it's
generating a new key and saving it");
- File fic = file.getAbsoluteFile();
+ log.debug("No token key file found at path " + keyPath + ".
it's generating a new key and saving it");
+ File fic = tokenKeyFile.getAbsoluteFile();
File parentFolder = fic.getParentFile();
if (!parentFolder.exists()) {
if (!parentFolder.mkdirs())
{
- log.error("Coult not create parent folder/s for the key file " +
keyPath);
- return false;
+ log.error("Coult not create parent folder/s for the token key file
" + keyPath);
+ return;
}
}
String key = generateKey();
Writer out = null;
try
{
- out = new FileWriter(file);
+ out = new FileWriter(tokenKeyFile);
out.write(key);
out.write('\n');
- log.debug("Generated key file " + keyPath + " for eXo
Gadgets");
+ setTokenKeyPath(keyPath);
+ log.debug("Generated token key file " + keyPath + " for eXo
Gadgets");
}
catch (IOException e)
{
- log.error("Could not create key file " + keyPath, e);
- return false;
+ log.error("Could not create token key file " + keyPath, e);
}
finally
{
Safe.close(out);
}
}
- return true;
}
+
+ private void initializeSigningKeyFile()
+ {
+ String signingKey =
PropertyManager.getProperty("gatein.gadgets.signingkeyfile");
+
+ File signingKeyFile;
+ if (signingKey == null)
+ {
+ log.warn("The gadgets signing key is not configured. The default signing
key in /bin directory will be used.");
+ signingKeyFile = new File("oauthkey.pem");
+ }
+ else
+ {
+ signingKeyFile = new File(signingKey);
+ }
+
+ if (signingKeyFile.exists())
+ {
+ if (signingKeyFile.isFile())
+ {
+ signingKey_ = signingKeyFile.getAbsolutePath();
+ log.info("Use signing key " + signingKey_ + " for gadget
security");
+ }
+ else
+ {
+ log.error("Found signing path file " +
signingKeyFile.getAbsolutePath() + " but it's not a key file");
+ }
+ }
+ }
private void setTokenKeyPath(String keyPath)
{
Modified:
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ExoOAuthModule.java
===================================================================
---
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ExoOAuthModule.java 2011-10-17
23:09:57 UTC (rev 7759)
+++
portal/trunk/gadgets/core/src/main/java/org/exoplatform/portal/gadget/core/ExoOAuthModule.java 2011-10-18
04:19:04 UTC (rev 7760)
@@ -19,11 +19,11 @@
package org.exoplatform.portal.gadget.core;
+import com.google.inject.Inject;
+import com.google.inject.Provider;
import com.google.inject.Singleton;
+import com.google.inject.name.Names;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.shindig.auth.AnonymousAuthenticationHandler;
@@ -32,16 +32,14 @@
import org.apache.shindig.config.ContainerConfig;
import org.apache.shindig.gadgets.oauth.BasicOAuthStore;
import org.apache.shindig.gadgets.oauth.BasicOAuthStoreConsumerKeyAndSecret;
+import org.apache.shindig.gadgets.oauth.BasicOAuthStoreConsumerKeyAndSecret.KeyType;
import org.apache.shindig.gadgets.oauth.OAuthFetcherConfig;
import org.apache.shindig.gadgets.oauth.OAuthModule;
import org.apache.shindig.gadgets.oauth.OAuthRequest;
import org.apache.shindig.gadgets.oauth.OAuthStore;
-import org.apache.shindig.gadgets.oauth.BasicOAuthStoreConsumerKeyAndSecret.KeyType;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
-import com.google.inject.Inject;
-import com.google.inject.Provider;
-import com.google.inject.name.Names;
-
/**
* Created by IntelliJ IDEA.
* User: jeremi
@@ -59,7 +57,7 @@
private static final String OAUTH_CONFIG = "config/oauth.json";
- private static final Logger logger = Logger.getLogger(OAuthModule.class.getName());
+ private static final Log log = ExoLogger.getLogger(OAuthModule.class);;
@Override
protected void configure()
@@ -103,19 +101,19 @@
BasicOAuthStoreConsumerKeyAndSecret key = null;
if (!StringUtils.isBlank(signingKeyFile)) {
try {
- logger.info("Loading OAuth signing key from " + signingKeyFile);
+ log.info("Loading OAuth signing key from " + signingKeyFile);
String privateKey = IOUtils.toString(ResourceLoader.open(signingKeyFile),
"UTF-8");
privateKey = BasicOAuthStore.convertFromOpenSsl(privateKey);
key = new BasicOAuthStoreConsumerKeyAndSecret(null, privateKey,
KeyType.RSA_PRIVATE,
signingKeyName, null);
} catch (Throwable t) {
- logger.log(Level.WARNING, "Couldn't load key file " +
signingKeyFile, t);
+ log.warn("Couldn't load key file " + signingKeyFile);
}
}
if (key != null) {
store.setDefaultKey(key);
} else {
- logger.log(Level.WARNING, "Couldn't load OAuth signing key. To create
a key, run:\n" +
+ log.warn("Couldn't load OAuth signing key. To create a key,
run:\n" +
" openssl req -newkey rsa:1024 -days 365 -nodes -x509 -keyout
testkey.pem \\\n" +
" -out testkey.pem -subj '/CN=mytestkey'\n" +
" openssl pkcs8 -in testkey.pem -out oauthkey.pem -topk8 -nocrypt
-outform PEM\n" +
@@ -130,7 +128,7 @@
String oauthConfigString = ResourceLoader.getContent(OAUTH_CONFIG);
store.initFromConfigString(oauthConfigString);
} catch (Throwable t) {
- logger.log(Level.WARNING, "Failed to initialize OAuth consumers from
" + OAUTH_CONFIG, t);
+ log.warn("Failed to initialize OAuth consumers from " + OAUTH_CONFIG,
t);
}
}
Modified: portal/trunk/gadgets/server/src/main/webapp/containers/default/container.js
===================================================================
--- portal/trunk/gadgets/server/src/main/webapp/containers/default/container.js 2011-10-17
23:09:57 UTC (rev 7759)
+++ portal/trunk/gadgets/server/src/main/webapp/containers/default/container.js 2011-10-18
04:19:04 UTC (rev 7760)
@@ -97,7 +97,7 @@
"gadgets.osDataUri" : "http://%host%/rpc",
"gadgets.signingKeyFile" : "oauthkey.pem",
-"gadgets.signingKeyName" : "mytestkey",
+"gadgets.signingKeyName" : "exokey",
"gadgets.signedFetchDomain" : "eXo",
@@ -277,4 +277,4 @@
// for a container.
"library": "config/OSML_library.xml"
}
-}}
\ No newline at end of file
+}}
Show replies by date