Commit 4ee59e68 authored by Mathieu Leclaire's avatar Mathieu Leclaire
Browse files

[GUI] Fix authentications

parent 7b76616a
......@@ -31,7 +31,6 @@ import scalatags.JsDom.tags
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@JSExport("org.openmole.gui.plugin.environment.egi.client.EGIP12AuthenticationPanelUI")
class EGIP12AuthenticationPanel(data: EGIP12AuthenticationData) extends PanelUI {
val password = bs.input(data.cypheredPassword, key("spacer5"))(
......
......@@ -29,7 +29,11 @@ package object authentications {
}
def panelWithID(data: AuthenticationData) = new PanelWithID {
val name = data.synthetic
val name = data match {
case e: EGIP12AuthenticationData "EGI P12 certificate"
case lp: LoginPasswordAuthenticationData "SSH login/password"
case _ "SSH key"
}
val panel: PanelUI = authentications.panel(data)
}
......
package org.openmole.gui.ext.data
/*
* Copyright (C) 13/02/15 // mathieu.leclaire@openmole.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import scala.util.Try
trait Factory
trait CoreObjectFactory extends Factory {
def coreObject(): Try[Any]
}
trait AuthenticationFactory extends Factory {
def coreObject(data: AuthenticationData): Option[Any]
def buildAuthentication(data: AuthenticationData): Unit
def allAuthenticationData: Seq[AuthenticationData]
def removeAuthentication(data: AuthenticationData): Unit
}
......@@ -52,13 +52,11 @@ object ApiImpl extends Api {
implicit def authProvider = Workspace.authenticationProvider
//AUTHENTICATIONS
def addAuthentication(data: AuthenticationData): Unit = ServerFactories.authenticationFactories(data.getClass).buildAuthentication(data)
def addAuthentication(data: AuthenticationData): Unit = AuthenticationFactories.addAuthentication(data)
def authentications(): Seq[AuthenticationData] = ServerFactories.authenticationFactories.values.flatMap {
_.allAuthenticationData
}.toSeq
def authentications(): Seq[AuthenticationData] = AuthenticationFactories.allAuthentications
def removeAuthentication(data: AuthenticationData) = ServerFactories.authenticationFactories(data.getClass).removeAuthentication(data)
def removeAuthentication(data: AuthenticationData) = AuthenticationFactories.removeAuthentication(data)
//WORKSPACE
def isPasswordCorrect(pass: String): Boolean = Workspace.passwordIsCorrect(pass)
......
package org.openmole.gui.server.core
/*
* Copyright (C) 24/09/14 // mathieu.leclaire@openmole.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import org.openmole.core.workspace.Workspace
import org.openmole.gui.ext.data._
import org.openmole.gui.server.core.Utils._
import org.openmole.plugin.environment.egi.{ EGIAuthentication, P12Certificate }
import org.openmole.plugin.environment.ssh.{ PrivateKey, SSHAuthentication, LoginPassword }
object AuthenticationFactories {
implicit def dataToFactory(data: AuthenticationData): AuthenticationFactory = data match {
case e: EGIP12AuthenticationData EGIP12Factory
case l: LoginPasswordAuthenticationData SSHLoginPasswordFactory
case _ SSHPrivateKeyFactory
}
def addAuthentication(data: AuthenticationData) = data.buildAuthentication(data)
def allAuthentications(data: AuthenticationData) = data.allAuthenticationData
def allAuthentications = EGIP12Factory.allAuthenticationData ++ SSHLoginPasswordFactory.allAuthenticationData ++ SSHPrivateKeyFactory.allAuthenticationData
def removeAuthentication(data: AuthenticationData) = data.removeAuthentication(data)
trait AuthenticationFactory {
def coreObject(data: AuthenticationData): Option[Any]
def buildAuthentication(data: AuthenticationData): Unit
def allAuthenticationData: Seq[AuthenticationData]
def removeAuthentication(data: AuthenticationData): Unit
}
object EGIP12Factory extends AuthenticationFactory {
implicit def authProvider = Workspace.authenticationProvider
def buildAuthentication(data: AuthenticationData) = {
val auth = coreObject(data)
auth.foreach { a
EGIAuthentication.update(a)
}
}
def allAuthenticationData: Seq[AuthenticationData] = {
EGIAuthentication() match {
case Some(p12: P12Certificate)
Seq(EGIP12AuthenticationData(
Workspace.decrypt(p12.cypheredPassword),
Some(p12.certificate.getName)
))
case x: Any Seq()
}
}
def coreObject(data: AuthenticationData): Option[P12Certificate] = data match {
case p12: EGIP12AuthenticationData
p12.privateKey match {
case Some(pk: String) Some(P12Certificate(
Workspace.encrypt(p12.cypheredPassword),
authenticationFile(pk)
))
case _ None
}
case _ None
}
def removeAuthentication(data: AuthenticationData) = EGIAuthentication.clear
}
object SSHLoginPasswordFactory extends AuthenticationFactory {
implicit def authProvider = Workspace.authenticationProvider
def buildAuthentication(data: AuthenticationData) = {
val auth = coreObject(data)
auth.map { a SSHAuthentication += a }
}
def allAuthenticationData: Seq[AuthenticationData] = SSHAuthentication().flatMap {
_ match {
case lp: LoginPassword Some(LoginPasswordAuthenticationData(
lp.login,
Workspace.decrypt(lp.cypheredPassword),
lp.target
))
case _ None
}
}
def coreObject(data: AuthenticationData): Option[LoginPassword] = data match {
case lp: LoginPasswordAuthenticationData Some(LoginPassword(
lp.login,
Workspace.encrypt(lp.cypheredPassword),
lp.target
))
case _ None
}
def removeAuthentication(data: AuthenticationData) = coreObject(data).map { e
SSHAuthentication -= e
}
}
object SSHPrivateKeyFactory extends AuthenticationFactory {
implicit def authProvider = Workspace.authenticationProvider
def buildAuthentication(data: AuthenticationData) = {
val auth = coreObject(data)
auth.map { a SSHAuthentication += a }
}
def allAuthenticationData: Seq[AuthenticationData] = SSHAuthentication().flatMap {
_ match {
case key: PrivateKey Some(PrivateKeyAuthenticationData(
Some(key.privateKey.getName),
key.login,
Workspace.decrypt(key.cypheredPassword),
key.target
))
case _ None
}
}
def coreObject(data: AuthenticationData): Option[PrivateKey] = data match {
case keyData: PrivateKeyAuthenticationData
keyData.privateKey match {
case Some(pk: String) Some(PrivateKey(
authenticationFile(pk),
keyData.login,
Workspace.encrypt(keyData.cypheredPassword),
keyData.target
))
case _ None
}
case _ None
}
def removeAuthentication(data: AuthenticationData) = coreObject(data).map { e SSHAuthentication -= e }
}
}
package org.openmole.gui.server.core
import org.openmole.gui.ext.data.{ DataBag, ErrorData }
import scala.util.Failure
/*
* Copyright (C) 26/09/14 // mathieu.leclaire@openmole.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
object CoreFactory {
def check(dataBag: Seq[DataBag]): Seq[ErrorData] = {
dataBag.map { d
d -> ServerFactories.coreObject(d)
}.collect { case (data: DataBag, f: Failure[_]) ErrorData(data, f.exception.getMessage, f.exception.getStackTrace.mkString("\n")) }
}
// def prototype(prototypeData: PrototypeData): Prototype[_] =
}
package org.openmole.gui.server.core
/*
* Copyright (C) 24/09/14 // mathieu.leclaire@openmole.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import org.openmole.gui.ext.data._
import org.openmole.gui.ext.dataui.{ FactoryWithPanelUI, FactoryWithDataUI }
import scala.collection.mutable
import scala.util.{ Failure, Try }
object ServerFactories {
lazy private val instance = new ServerFactories
def coreObject(dataBag: DataBag): Try[Any] = instance.factories.synchronized {
instance.factories.get(dataBag.data.getClass()) match {
case Some(f: CoreObjectFactory) f.coreObject()
case _ Failure(new Throwable("The data " + dataBag.name + " cannot be recontructed on the server."))
}
}
def coreObject(className: String): Try[Any] = instance.factories.synchronized {
instance.factories.filterKeys(_ == Class.forName(className)).headOption.map { _._2 } match {
case Some(f: CoreObjectFactory) f.coreObject()
case _ Failure(new Throwable("The data " + className + " cannot be recontructed on the server."))
}
}
def add(dataClass: Class[_], factory: Factory, factoryUI: FactoryWithDataUI) = instance.factories.synchronized {
instance.factories += dataClass -> factory
instance.factoriesUI += dataClass.getName -> factoryUI
}
def addAuthenticationFactory(dataClass: Class[_], factory: AuthenticationFactory, factoryUI: FactoryWithPanelUI) = instance.authenticationFactoriesUI.synchronized {
instance.authenticationFactories += dataClass -> factory
instance.authenticationFactoriesUI += dataClass.getName -> factoryUI
}
def remove(dataClass: Class[_]) = instance.factories.synchronized {
instance.factories -= dataClass
instance.factoriesUI -= dataClass.getName
}
def removeAuthenticationFactory(dataClass: Class[_]) = instance.authenticationFactoriesUI.synchronized {
instance.authenticationFactories -= dataClass
instance.authenticationFactoriesUI -= dataClass.getName
}
def factories = instance.factories.toMap
def factoriesUI = instance.factoriesUI.toMap
def authenticationFactories = instance.authenticationFactories.toMap
def authenticationFactoriesUI = instance.authenticationFactoriesUI.toMap
}
class ServerFactories {
val factories = new mutable.WeakHashMap[Class[_], Factory]
val factoriesUI = new mutable.WeakHashMap[String, FactoryWithDataUI]
val authenticationFactories = new mutable.WeakHashMap[Class[_], AuthenticationFactory]
val authenticationFactoriesUI = new mutable.WeakHashMap[String, FactoryWithPanelUI]
}
......@@ -14,16 +14,16 @@ object Client extends GuiDefaults {
val acePath = s"META-INF/resources/webjars/ace/$aceVersion/src-min/ace.js"
lazy val core = OsgiProject("org.openmole.gui.client.core") enablePlugins (ScalaJSPlugin) dependsOn
(Ext.dataui, Shared.shared, Misc.utils, Misc.js , root.Doc.doc ) settings (
(Ext.dataui, Shared.shared, Misc.utils, Misc.js, root.Doc.doc) settings (
libraryDependencies ++= Seq(autowire, upickle, scalaTags, rx, scalajsDom, scaladget, async),
skip in packageJSDependencies := false,
jsDependencies += jquery / jqueryPath,
jsDependencies += jquery / jqueryPath minified jqueryPath.replace(".js", ".min.js"),
jsDependencies += ace / acePath,
jsDependencies += ace / "src-min/mode-sh.js" dependsOn acePath,
jsDependencies += ace / "src-min/mode-scala.js" dependsOn acePath,
jsDependencies += ace / "src-min/theme-github.js" dependsOn acePath,
jsDependencies += bootstrap / "js/bootstrap.min.js" dependsOn jqueryPath,
jsDependencies += d3 / "d3.min.js" dependsOn jqueryPath,
jsDependencies += tooltipster / "js/jquery.tooltipster.min.js" dependsOn jqueryPath
jsDependencies += bootstrap / "js/bootstrap.js" dependsOn jqueryPath minified "js/bootstrap.min.js",
jsDependencies += d3 / "d3.js" dependsOn jqueryPath minified "d3.min.js",
jsDependencies += tooltipster / "js/jquery.tooltipster.js" dependsOn jqueryPath minified "js/jquery.tooltipster.min.js"
)
}
\ No newline at end of file
......@@ -7,7 +7,6 @@ import sbt._
import root._
import root.Libraries._
import sbt.Keys._
import com.typesafe.sbt.osgi.OsgiKeys._
import ThirdParties._
object Server extends GuiDefaults {
......@@ -28,6 +27,8 @@ object Server extends GuiDefaults {
root.Runtime.console,
Core.dsl,
Core.batch,
_root_.plugin.Environment.egi,
_root_.plugin.Environment.ssh,
Misc.utils,
ThirdParties.openmoleStream,
openmoleCrypto
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment