From: Mathieu Baudier Date: Sun, 27 Feb 2011 11:24:11 +0000 (+0000) Subject: Move to security X-Git-Tag: argeo-commons-2.1.30~1408 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=a7a5f4db586128a9bb2c171ee819eb3eb19f80aa;p=lgpl%2Fargeo-commons.git Move to security git-svn-id: https://svn.argeo.org/commons/trunk@4226 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/security/eclipse/plugins/org.argeo.security.equinox/.classpath b/security/eclipse/plugins/org.argeo.security.equinox/.classpath deleted file mode 100644 index 92f19d2ff..000000000 --- a/security/eclipse/plugins/org.argeo.security.equinox/.classpath +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/security/eclipse/plugins/org.argeo.security.equinox/.project b/security/eclipse/plugins/org.argeo.security.equinox/.project deleted file mode 100644 index e4dd594e8..000000000 --- a/security/eclipse/plugins/org.argeo.security.equinox/.project +++ /dev/null @@ -1,28 +0,0 @@ - - - org.argeo.security.equinox - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - diff --git a/security/eclipse/plugins/org.argeo.security.equinox/.settings/org.eclipse.jdt.core.prefs b/security/eclipse/plugins/org.argeo.security.equinox/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 62fa6bd36..000000000 --- a/security/eclipse/plugins/org.argeo.security.equinox/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,8 +0,0 @@ -#Sun Jan 16 11:20:02 CET 2011 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 diff --git a/security/eclipse/plugins/org.argeo.security.equinox/.settings/org.eclipse.pde.core.prefs b/security/eclipse/plugins/org.argeo.security.equinox/.settings/org.eclipse.pde.core.prefs deleted file mode 100644 index 87ab38102..000000000 --- a/security/eclipse/plugins/org.argeo.security.equinox/.settings/org.eclipse.pde.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -#Sun Jan 16 11:19:07 CET 2011 -eclipse.preferences.version=1 -pluginProject.extensions=false -resolve.requirebundle=false diff --git a/security/eclipse/plugins/org.argeo.security.equinox/META-INF/spring/loginModules.xml b/security/eclipse/plugins/org.argeo.security.equinox/META-INF/spring/loginModules.xml deleted file mode 100644 index f454d7a3a..000000000 --- a/security/eclipse/plugins/org.argeo.security.equinox/META-INF/spring/loginModules.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - diff --git a/security/eclipse/plugins/org.argeo.security.equinox/META-INF/spring/osgi.xml b/security/eclipse/plugins/org.argeo.security.equinox/META-INF/spring/osgi.xml deleted file mode 100644 index 8003fb277..000000000 --- a/security/eclipse/plugins/org.argeo.security.equinox/META-INF/spring/osgi.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - \ No newline at end of file diff --git a/security/eclipse/plugins/org.argeo.security.equinox/build.properties b/security/eclipse/plugins/org.argeo.security.equinox/build.properties deleted file mode 100644 index 3e2615fae..000000000 --- a/security/eclipse/plugins/org.argeo.security.equinox/build.properties +++ /dev/null @@ -1,4 +0,0 @@ -bin.includes = META-INF/,\ - plugin.xml -source.. = src/main/java/ -output.. = target/classes/ diff --git a/security/eclipse/plugins/org.argeo.security.equinox/plugin.xml b/security/eclipse/plugins/org.argeo.security.equinox/plugin.xml deleted file mode 100644 index b407360ac..000000000 --- a/security/eclipse/plugins/org.argeo.security.equinox/plugin.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - name="Spring Login Module" - - - - - diff --git a/security/eclipse/plugins/org.argeo.security.equinox/pom.xml b/security/eclipse/plugins/org.argeo.security.equinox/pom.xml deleted file mode 100644 index 944a6e0df..000000000 --- a/security/eclipse/plugins/org.argeo.security.equinox/pom.xml +++ /dev/null @@ -1,79 +0,0 @@ - - 4.0.0 - - org.argeo.commons.security - 0.2.3-SNAPSHOT - plugins - .. - - org.argeo.security.equinox - Commons Security Equinox - jar - - - - org.apache.maven.plugins - maven-compiler-plugin - - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-jar-plugin - - - org.apache.felix - maven-bundle-plugin - ${version.maven-bundle-plugin} - - - - - - - - - - - - - - - *, - org.springframework.core, - org.argeo.eclipse.spring - - - - - - - - - - - org.eclipse.osgi - org.eclipse.osgi - - - org.eclipse.equinox - org.eclipse.equinox.security - - - - - org.argeo.commons.basic - org.argeo.basic.nodeps - 0.2.3-SNAPSHOT - - - - - org.springframework.security - org.springframework.security.core - - - diff --git a/security/eclipse/plugins/org.argeo.security.equinox/src/main/java/org/argeo/security/equinox/SpringLoginModule.java b/security/eclipse/plugins/org.argeo.security.equinox/src/main/java/org/argeo/security/equinox/SpringLoginModule.java deleted file mode 100644 index 2222faecc..000000000 --- a/security/eclipse/plugins/org.argeo.security.equinox/src/main/java/org/argeo/security/equinox/SpringLoginModule.java +++ /dev/null @@ -1,126 +0,0 @@ -package org.argeo.security.equinox; - -import java.util.Map; - -import javax.security.auth.Subject; -import javax.security.auth.callback.Callback; -import javax.security.auth.callback.CallbackHandler; -import javax.security.auth.callback.NameCallback; -import javax.security.auth.callback.PasswordCallback; -import javax.security.auth.callback.TextOutputCallback; -import javax.security.auth.login.LoginException; - -import org.springframework.security.Authentication; -import org.springframework.security.AuthenticationManager; -import org.springframework.security.BadCredentialsException; -import org.springframework.security.context.SecurityContextHolder; -import org.springframework.security.providers.UsernamePasswordAuthenticationToken; -import org.springframework.security.providers.jaas.SecurityContextLoginModule; - -/** Login module which caches one subject per thread. */ -public class SpringLoginModule extends SecurityContextLoginModule { - private AuthenticationManager authenticationManager; - - private CallbackHandler callbackHandler; - - public SpringLoginModule() { - - } - - @SuppressWarnings("rawtypes") - public void initialize(Subject subject, CallbackHandler callbackHandler, - Map sharedState, Map options) { - super.initialize(subject, callbackHandler, sharedState, options); - // this.subject.set(subject); - this.callbackHandler = callbackHandler; - } - - public boolean login() throws LoginException { - // thread already logged in - if (SecurityContextHolder.getContext().getAuthentication() != null) - return super.login(); - - // if (getSubject().getPrincipals(Authentication.class).size() == 1) { - // registerAuthentication(getSubject() - // .getPrincipals(Authentication.class).iterator().next()); - // return super.login(); - // } else if (getSubject().getPrincipals(Authentication.class).size() > - // 1) { - // throw new LoginException( - // "Multiple Authentication principals not supported: " - // + getSubject().getPrincipals(Authentication.class)); - // } else { - // ask for username and password - Callback label = new TextOutputCallback(TextOutputCallback.INFORMATION, - "Required login"); - NameCallback nameCallback = new NameCallback("User"); - PasswordCallback passwordCallback = new PasswordCallback("Password", - false); - - if (callbackHandler == null) { - throw new LoginException("No call back handler available"); - // return false; - } - try { - callbackHandler.handle(new Callback[] { label, nameCallback, - passwordCallback }); - } catch (Exception e) { - LoginException le = new LoginException("Callback handling failed"); - le.initCause(e); - throw le; - } - - // Set user name and password - String username = nameCallback.getName(); - String password = ""; - if (passwordCallback.getPassword() != null) { - password = String.valueOf(passwordCallback.getPassword()); - } - UsernamePasswordAuthenticationToken credentials = new UsernamePasswordAuthenticationToken( - username, password); - - try { - Authentication authentication = authenticationManager - .authenticate(credentials); - registerAuthentication(authentication); - boolean res = super.login(); - // if (log.isDebugEnabled()) - // log.debug("User " + username + " logged in"); - return res; - } catch (BadCredentialsException bce) { - throw bce; - } catch (Exception e) { - LoginException loginException = new LoginException( - "Bad credentials"); - loginException.initCause(e); - throw loginException; - } - // } - } - - @Override - public boolean logout() throws LoginException { - return super.logout(); - } - - /** - * Register an {@link Authentication} in the security context. - * - * @param authentication - * has to implement {@link Authentication}. - */ - protected void registerAuthentication(Object authentication) { - SecurityContextHolder.getContext().setAuthentication( - (Authentication) authentication); - } - - public void setAuthenticationManager( - AuthenticationManager authenticationManager) { - this.authenticationManager = authenticationManager; - } - - // protected Subject getSubject() { - // return subject.get(); - // } - -} diff --git a/security/eclipse/plugins/org.argeo.security.ui.application/.classpath b/security/eclipse/plugins/org.argeo.security.ui.application/.classpath deleted file mode 100644 index 92f19d2ff..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui.application/.classpath +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/security/eclipse/plugins/org.argeo.security.ui.application/.project b/security/eclipse/plugins/org.argeo.security.ui.application/.project deleted file mode 100644 index e83b5d5d9..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui.application/.project +++ /dev/null @@ -1,28 +0,0 @@ - - - org.argeo.security.ui.application - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - diff --git a/security/eclipse/plugins/org.argeo.security.ui.application/.settings/org.eclipse.jdt.core.prefs b/security/eclipse/plugins/org.argeo.security.ui.application/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 1f382cb9d..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui.application/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,8 +0,0 @@ -#Sat Jan 15 17:51:30 CET 2011 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 diff --git a/security/eclipse/plugins/org.argeo.security.ui.application/META-INF/jaas_default.txt b/security/eclipse/plugins/org.argeo.security.ui.application/META-INF/jaas_default.txt deleted file mode 100644 index b6cbaa655..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui.application/META-INF/jaas_default.txt +++ /dev/null @@ -1,14 +0,0 @@ -UNIX { - org.eclipse.equinox.security.auth.module.ExtensionLoginModule sufficient - extensionId="org.argeo.security.equinox.unixLoginModule"; -}; - -SPRING { - org.eclipse.equinox.security.auth.module.ExtensionLoginModule sufficient - extensionId="org.argeo.security.equinox.springLoginModule"; -}; - -SPRING_SECURITY_CONTEXT { - org.eclipse.equinox.security.auth.module.ExtensionLoginModule sufficient - extensionId="org.argeo.security.equinox.springSecurityContextLoginModule"; -}; \ No newline at end of file diff --git a/security/eclipse/plugins/org.argeo.security.ui.application/argeo_security_rap.properties b/security/eclipse/plugins/org.argeo.security.ui.application/argeo_security_rap.properties deleted file mode 100644 index 355774942..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui.application/argeo_security_rap.properties +++ /dev/null @@ -1,24 +0,0 @@ -argeo.osgi.start=\ -com.springsource.javax.servlet,\ -org.eclipse.core.runtime,\ -org.eclipse.equinox.common,\ -org.eclipse.equinox.http.jetty,\ -org.eclipse.equinox.http.registry,\ -org.eclipse.equinox.launcher,\ -org.eclipse.rap.demo,\ -org.mortbay.jetty.server,\ -org.springframework.osgi.extender,\ -org.argeo.server.ads.server,\ -org.argeo.security.manager.ldap,\ -org.argeo.security.services,\ -org.argeo.security.equinox,\ -org.argeo.security.ui,\ -org.argeo.security.ui.rcp,\ - -eclipse.ignoreApp=true -osgi.noShutdown=true - -log4j.configuration=file:../../log4j.properties - -org.eclipse.equinox.http.jetty.log.stderr.threshold=debug -org.osgi.service.http.port=9090 diff --git a/security/eclipse/plugins/org.argeo.security.ui.application/build.properties b/security/eclipse/plugins/org.argeo.security.ui.application/build.properties deleted file mode 100644 index ac478ab24..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui.application/build.properties +++ /dev/null @@ -1,7 +0,0 @@ -source.. = src/main/java/ -output.. = target/classes/ -bin.includes = plugin.xml,\ - META-INF/,\ - .,\ - log4j.properties,\ - jaas_config.txt diff --git a/security/eclipse/plugins/org.argeo.security.ui.application/icons/alt_about.gif b/security/eclipse/plugins/org.argeo.security.ui.application/icons/alt_about.gif deleted file mode 100644 index 20d9ad2d9..000000000 Binary files a/security/eclipse/plugins/org.argeo.security.ui.application/icons/alt_about.gif and /dev/null differ diff --git a/security/eclipse/plugins/org.argeo.security.ui.application/icons/alt_launcher.icns b/security/eclipse/plugins/org.argeo.security.ui.application/icons/alt_launcher.icns deleted file mode 100644 index b77a6a639..000000000 Binary files a/security/eclipse/plugins/org.argeo.security.ui.application/icons/alt_launcher.icns and /dev/null differ diff --git a/security/eclipse/plugins/org.argeo.security.ui.application/icons/alt_launcher.ico b/security/eclipse/plugins/org.argeo.security.ui.application/icons/alt_launcher.ico deleted file mode 100644 index d548f7109..000000000 Binary files a/security/eclipse/plugins/org.argeo.security.ui.application/icons/alt_launcher.ico and /dev/null differ diff --git a/security/eclipse/plugins/org.argeo.security.ui.application/icons/alt_launcher.xpm b/security/eclipse/plugins/org.argeo.security.ui.application/icons/alt_launcher.xpm deleted file mode 100644 index b0c139e06..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui.application/icons/alt_launcher.xpm +++ /dev/null @@ -1,307 +0,0 @@ -/* XPM */ -static char * icon48_xpm[] = { -"48 48 256 2", -" c #4B4B3B3B9090", -". c #0D0D0E0E5454", -"X c #11110E0E5B5B", -"o c #17170F0F6363", -"O c #1D1D13136969", -"+ c #212114146C6C", -"@ c #252514147171", -"# c #282811116C6C", -"$ c #26260D0D6363", -"% c #22220B0B5E5E", -"& c #1C1C0B0B5A5A", -"* c #1C1C0B0B5252", -"= c #1B1B05055353", -"- c #161606064D4D", -"; c #161605054949", -": c #111104044848", -"> c #131304044545", -", c #131305054242", -"< c #141410105E5E", -"1 c #2C2C15157373", -"2 c #2B2B1B1B7575", -"3 c #343416167272", -"4 c #313113136E6E", -"5 c #222209095757", -"6 c #1B1B06064D4D", -"7 c #15150B0B4242", -"8 c #13130C0C5555", -"9 c #2E2E1B1B7878", -"0 c #33331F1F7C7C", -"q c #343418187878", -"w c #3B3B1C1C7575", -"e c #2E2E10106767", -"r c #1B1B07074747", -"t c #18180B0B4646", -"y c #151513136262", -"u c #1A1A15156464", -"i c #34341F1F7777", -"p c #40401E1E8080", -"a c #42421B1B7A7A", -"s c #3B3B15157474", -"d c #2B2B0B0B5B5B", -"f c #222207075252", -"g c #373727277A7A", -"h c #474724248484", -"j c #393915156E6E", -"k c #373711116A6A", -"l c #343413136363", -"z c #232319196E6E", -"x c #292919197070", -"c c #3C3C2C2C8282", -"v c #444431318585", -"b c #494934348A8A", -"n c #505026268A8A", -"m c #3D3D1B1B6E6E", -"M c #31310E0E5C5C", -"N c #2B2B0D0D5353", -"B c #222207074A4A", -"V c #52523C3C9292", -"C c #58583C3C9494", -"Z c #5D5D44449797", -"A c #5C5C2E2E9292", -"S c #676733339595", -"D c #424228287575", -"F c #29290A0A4F4F", -"G c #6C6C4A4A9E9E", -"H c #72725454A7A7", -"J c #8C8C6D6DB2B2", -"K c #343424246E6E", -"L c #3A3A23236A6A", -"P c #3A3A1C1C6767", -"I c #24240A0A4B4B", -"U c #151518186161", -"Y c #76766F6FA5A5", -"T c #ADAD9191CCCC", -"R c #98988989D3D3", -"E c #45453B3B8686", -"W c #3C3C35357979", -"Q c #363631317575", -"! c #32322D2D6B6B", -"~ c #323229296363", -"^ c #30301F1F6262", -"/ c #323218185E5E", -"( c #272707074B4B", -") c #202028286C6C", -"_ c #1E1E1D1D6868", -"` c #9A9A8282BBBB", -"' c #C8C8B3B3D3D3", -"] c #B3B3AFAFE7E7", -"[ c #84847272C6C6", -"{ c #58585757A3A3", -"} c #3F3F3C3C8A8A", -"| c #3B3B3A3A8484", -" . c #414139397D7D", -".. c #3D3D39397A7A", -"X. c #37372E2E6E6E", -"o. c #2C2C21215A5A", -"O. c #2E2E1B1B5B5B", -"+. c #F5F5EFEFF5F5", -"@. c #656566669A9A", -"#. c #47474B4B8E8E", -"$. c #3C3C44447B7B", -"%. c #444442428080", -"&. c #45453E3E8181", -"*. c #40403C3C8181", -"=. c #3D3D33337474", -"-. c #3B3B30306E6E", -";. c #38382D2D6969", -":. c #303026265D5D", -">. c #2C2C15155A5A", -",. c #1F1F1C1C7070", -"<. c #25251E1E7171", -"1. c #59595C5C9191", -"2. c #4D4D53538989", -"3. c #4C4C49498484", -"4. c #484845458585", -"5. c #494941418585", -"6. c #494940408181", -"7. c #2F2F1C1C5353", -"8. c #2B2B28287676", -"9. c #323231317F7F", -"0. c #545452528B8B", -"q. c #51514E4E8989", -"w. c #4E4E4B4B8C8C", -"e. c #4C4C47478686", -"r. c #46463D3D7E7E", -"t. c #434336367A7A", -"y. c #2B2B13135555", -"u. c #47473D3D8D8D", -"i. c #575757578E8E", -"p. c #48483E3E7F7F", -"a. c #46463A3A7D7D", -"s. c #424235357575", -"d. c #404034347171", -"f. c #BFBFCBCBFAFA", -"g. c #B8B8A8A8DDDD", -"h. c #5E5E60609292", -"j. c #565655558C8C", -"k. c #4B4B44448282", -"l. c #454539397B7B", -"z. c #434338387878", -"x. c #3F3F32326D6D", -"c. c #3D3D30306969", -"v. c #3A3A2E2E6363", -"b. c #36362A2A5C5C", -"n. c #343424245555", -"m. c #30301E1E4D4D", -"M. c #49493C3C8282", -"N. c #5E5E4F4F8C8C", -"B. c #56563B3B8B8B", -"V. c #545407078585", -"C. c #424234347272", -"Z. c #9797A4A4F7F7", -"A. c #444436367676", -"S. c #7D7D7979D5D5", -"D. c #464640408A8A", -"F. c #44444B4B8282", -"G. c #414107077777", -"H. c #71716161C1C1", -"J. c #303039397979", -"K. c #8E8E8E8EE6E6", -"L. c #404033338B8B", -"P. c #4A4A45458C8C", -"I. c #46463A3A8080", -"U. c #363629295454", -"Y. c #303022224848", -"T. c #424237377575", -"R. c #2E2E1D1D6363", -"E. c #79798383EAEA", -"W. c #74747B7BE4E4", -"Q. c #6D6D7676D6D6", -"!. c #6A6A7171CECE", -"~. c #66666969C6C6", -"^. c #62626565BCBC", -"/. c #5F5F6060B5B5", -"(. c #5B5B5B5BACAC", -"). c #535353539898", -"_. c #4F4F4F4FA4A4", -"`. c #54544D4DA4A4", -"'. c #323204046B6B", -"]. c #303035357979", -"[. c #313122224343", -"{. c #5A5A5B5BB7B7", -"}. c #484846468080", -"|. c #454541417575", -" X c #4B4B31318282", -".X c #47473C3C8484", -"XX c #3E3E35356E6E", -"oX c #2F2F26264040", -"OX c #2B2B23233A3A", -"+X c #262619195C5C", -"@X c #252515155A5A", -"#X c #55555151B3B3", -"$X c #3C3C2D2D5D5D", -"%X c #39392F2F5656", -"&X c #37372D2D5050", -"*X c #25251F1F3030", -"=X c #24241D1D4343", -"-X c #202013135656", -";X c #41413B3B6C6C", -":X c #444442429696", -">X c #212100005E5E", -",X c #444436367272", -" > , , , ", -" . . X X < < o o O O + @ 1 2 2 1 1 1 1 1 1 1 1 3 4 # # $ $ $ % % % 5 = = 6 6 - ; ; > > , , 7 ", -" . 8 < < < o O O + @ @ 2 9 9 0 0 q q q q q q q w 3 4 4 e e $ $ $ $ % 5 = = 6 6 6 ; ; > > r t ", -" . X < y u O O + @ 1 2 i 0 0 p p p p p p p a a p a s 3 4 4 e e e e d 5 5 f f 6 6 6 ; ; r r t ", -" X < y u O + + @ 2 9 0 g p p h h h h h h h p h h a a s s j k k j l d d 5 5 f f 6 6 r r r r r ", -" X < y O z x x 9 0 g c v b n n n n n n n n n n n h a a s s j j m l M d d N f f B B B B r r r ", -" < y u + z 2 0 c c b V C Z C C A A A A A S S S n h D w w m m m m k l M d d N f F F F B r r r ", -" < y O z z 9 c b V Z G H H H G S G G J J H V v c g g K K K K L P l l l M M N N N N I B B r r ", -" U u + z x i v C H Y J J J J H J T R H V E W W Q Q Q Q ! ! ! ~ ^ ^ / / M M M M M N ( B B r r ", -" ) _ z x 9 g b Z Y ` ' ' ' T T ] [ { } | .........W W Q Q X.! ~ ~ o.O./ / / / N F ( B B B r ", -" ) ) z x i c V G J ' +.+.+.+.] [ @.#.$.%.%.%.&.*. . .....W =.-.X.;.~ :.o.O.^ >.N F ( B B B B ", -" ) ,.<.2 g v C H J ' +.+.+.+.T Y 1.2.3.4.4.4.5.6.&.&. . ...W =.=.-.;.~ :.o.7.>.N F F ( B I I ", -" ) ,.<.8.9.b C H J T +.+.+.' J @.1.0.q.q.w.e.4.5.6.&.r. . .t.W =.=.-.;.~ :.o.7.y.N F ( ( I I ", -" 8.8.8.9.| u.C G J T +.+.' ` Y @.1.i.0.q.q.e.e.5.6.p.r.a. .t.t.s.d.d.-.;.~ :.7.7.y.F F ( I I ", -" 9.c c c v b A S H ' f.g.` Y @.h.1.i.j.0.q.q.e.k.6.p.r.a.l.t.z.s.s.d.x.c.v.b.n.m.7.N F F F I ", -" <.g M.N.B.B.n V.J f.R J @.h.h.1.i.i.j.j.0.q.3.k.6.p.r.a.l.l.z.s.C.d.x.x.c.v.b.n.m.y.N F F F ", -" + x i v B.Z Z G g.Z.[ @.2.i.i.j.j.j.j.j.0.q.3.k.6.p.p.a.l.l.A.s.C.C.d.x.c.v.b.n.m.7.y.N N y. ", -" O # 3 w p n Z ` f.S.H D.F.q.0.0.0.0.j.0.q.q.3.k.6.p.r.a.a.l.A.s.s.C.d.x.x.c.v.b.n.m.y.y.y.y. ", -" O # 4 s a G.V.T Z.H.V J.%.e.w.q.0.0.0.0.q.q.e.k.6.p.r.a.a.l.z.A.s.C.d.d.x.c.v.b.n.m.7.>.y.y. ", -" O # 4 s w G.A f.K.H L...4.P.w.w.w.q.q.q.q.e.e.5.6.M.I.I.a.a.l.z.A.s.d.d.x.c.v.v.U.Y.7.O.>.y. ", -" $ # 4 3 s G.G f.S.Z 9.*.D.P.P.w.w.w.w.w.e.e.5.5.M.M.I.I.a.a.l.z.T.s.d.d.x.x.c.v.U.Y.m.R.>.>. ", -" E.E.W.W.W.W.E.Z.E.W.Q.Q.Q.Q.Q.Q.Q.Q.Q.Q.!.!.!.!.!.~.~.~.~.~.~.^.^.^.^.^./././.(.{ { )._.`._. ", -" + # 3 w s '.` f.H.V ].*.D.P.P.P.P.P.P.P.5.5.5.M.M.M.I.I.a.l.z.z.T.T.s.d.d.x.c.v.U.Y.[.^ O.>. ", -" ~.~.~.~.~.~.K.Z.S.~.{.^.^.^.^.^.^.^.^././././././.(.(.(.(.(.(.{ { { { { ).).).w.w.}.|.P.u.} ", -" .I.6. X X XT f.H.b ].*.E D.D.D.D.5.5..X.XM.M.I.I.a.a.l.l.z.z.T.T.T.d.XXx.c.v.b.U.oXOXR.+X@X ", -" E.E.E.W.W.W.K.Z.E.W.Q.Q.Q.Q.Q.Q.Q.Q.!.!.!.!.!.!.~.~.~.~.~.~.^.^.^.^.^./././.(.{ { ).).#X_._. ", -" & % $ e '.= H f.H.b 8.W *.E E E .X.X.XI.I.I.I.a.a.l.l.z.z.T.T.T.C.XXXXc.v.$X%X&XY.*X=X2 @X-X ", -" {.{.{.{.{.#X~.Z.W.~.{.{./././././././././.(.(.(.(.(.(.(.{ { { { { { ).).).w.w.3.}.;X%.:X} } ", -" & & % $ e >XV.f.S.C K X.W t. . .l.l.t.t.t.t.A.A.A.,X,X,X,X,XX7X` Z.Z D ! =.=.s.t.t.t.A.A.s.A.,X,X,X,X > > t t t cX ", -" nXbXbXzXzXlXaXXXY +Xf = f = 7XtXR R mXn.Y.[.[.[.[.OX*X*X8X5X*X=X,.u vXvX; > > MXMX, 7 t t ", -" nXnXnXbXzXvX-.Y +XcX6 6 = = = d L B.G H `.X.:.7.m.=X=X=X=X=X6X,.u cXvXNX: BX> MXVXCXVX7 7 7 ", -" ZXZXnXbXAXgX@.+XvX; - - - - * @XR.>.sX>.R.i 0 x eXeXeXeXO hXaXcXvXNX: BXMXMXMXVXCXCXCXVX7 7 ", -" SXZXZXAXgXN.aXNX: : NXNXNX- * +X+X* 6 6 6 * * * * * * * vXvX- NX: DXBXMXMXFXCXCXCXCXGXVXVX7 ", -" SXSXHXgX0.JXKXLXKXKXDX: : NX* @X-X- - - - - - - - - - - NX: DXDXDXMXMXFXFXCXCXCXCXGXGXGXVXVX ", -" SXHXPX3.JXnXnXnXnXbXLXKXKXNXaX-XvX: : NX: : : : : : : BXDXDXLXMXMXFXFXCXCXCXCXGXGXGXGXGXGXGX ", -" IXUX$.AXZXZXZXZXnXnXnXLXLXNXJXvXBXDXBXBXBXBXDXDXDXDXLXDXLXLXFXFXFXFXCXCXCXCXGXGXGXGXGXGXGXGX ", -" "}; diff --git a/security/eclipse/plugins/org.argeo.security.ui.application/icons/alt_window_16.gif b/security/eclipse/plugins/org.argeo.security.ui.application/icons/alt_window_16.gif deleted file mode 100644 index 05626b17d..000000000 Binary files a/security/eclipse/plugins/org.argeo.security.ui.application/icons/alt_window_16.gif and /dev/null differ diff --git a/security/eclipse/plugins/org.argeo.security.ui.application/icons/alt_window_32.gif b/security/eclipse/plugins/org.argeo.security.ui.application/icons/alt_window_32.gif deleted file mode 100644 index b432f8833..000000000 Binary files a/security/eclipse/plugins/org.argeo.security.ui.application/icons/alt_window_32.gif and /dev/null differ diff --git a/security/eclipse/plugins/org.argeo.security.ui.application/log4j.properties b/security/eclipse/plugins/org.argeo.security.ui.application/log4j.properties deleted file mode 100644 index 8a89a4aa3..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui.application/log4j.properties +++ /dev/null @@ -1,24 +0,0 @@ -log4j.rootLogger=WARN, console - -## Levels -log4j.logger.org.argeo=DEBUG -log4j.logger.org.springframework.security=DEBUG - -log4j.logger.org.apache.catalina=INFO -log4j.logger.org.apache.coyote=INFO -log4j.logger.org.apache.tomcat=INFO - -log4j.logger.org.apache.directory.server=INFO -log4j.logger.org.apache.directory.server.core.partition=ERROR -log4j.logger.org.apache.directory.server.core.schema.bootstrap.BootstrapAttributeTypeRegistry=ERROR - -log4j.logger.org.apache.jackrabbit=WARN -log4j.logger.org.apache.jackrabbit.core.query.lucene=ERROR - -## Appenders -# console is set to be a ConsoleAppender. -log4j.appender.console=org.apache.log4j.ConsoleAppender - -# console uses PatternLayout. -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern= %-5p %d{ISO8601} %m - %c - [%t]%n diff --git a/security/eclipse/plugins/org.argeo.security.ui.application/org.argeo.security.ui.application.product b/security/eclipse/plugins/org.argeo.security.ui.application/org.argeo.security.ui.application.product deleted file mode 100644 index be468c8ae..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui.application/org.argeo.security.ui.application.product +++ /dev/null @@ -1,119 +0,0 @@ - - - - - - - - - - -console -clean - -Dlog4j.configuration=file:${system_property:user.home}/dev/src/commons/security/eclipse/plugins/org.argeo.security.ui.application/log4j.properties - -XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/security/eclipse/plugins/org.argeo.security.ui.application/plugin.xml b/security/eclipse/plugins/org.argeo.security.ui.application/plugin.xml deleted file mode 100644 index 654141626..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui.application/plugin.xml +++ /dev/null @@ -1,63 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/security/eclipse/plugins/org.argeo.security.ui.application/plugin_customization.ini b/security/eclipse/plugins/org.argeo.security.ui.application/plugin_customization.ini deleted file mode 100644 index baf9cefe7..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui.application/plugin_customization.ini +++ /dev/null @@ -1,5 +0,0 @@ -org.eclipse.ui/DOCK_PERSPECTIVE_BAR=topRight -org.eclipse.ui/SHOW_TEXT_ON_PERSPECTIVE_BAR=true -org.eclipse.ui/PERSPECTIVE_BAR_SIZE=100 -org.eclipse.ui/SHOW_TRADITIONAL_STYLE_TABS=true -org.eclipse.ui/SHOW_PROGRESS_ON_STARTUP = false diff --git a/security/eclipse/plugins/org.argeo.security.ui.application/pom.xml b/security/eclipse/plugins/org.argeo.security.ui.application/pom.xml deleted file mode 100644 index e66484841..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui.application/pom.xml +++ /dev/null @@ -1,120 +0,0 @@ - - 4.0.0 - - org.argeo.commons.security - 0.2.3-SNAPSHOT - plugins - .. - - org.argeo.security.ui.application - Commons Security UI Application - jar - - - - org.apache.maven.plugins - maven-compiler-plugin - - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-jar-plugin - - - org.apache.felix - maven-bundle-plugin - ${version.maven-bundle-plugin} - - - org.argeo.security.ui.application.SecureApplicationActivator - lazy - org.eclipse.ui;resolution:=optional,org.eclipse.rap.ui;resolution:=optional,org.eclipse.core.runtime - * - - - - - org.argeo.maven.plugins - maven-argeo-osgi-plugin - - - resolve-pde-sources - - pde-sources - - generate-resources - - - generate-descriptors - - descriptors - - generate-resources - - - check-osgi - test - - equinox - - - true - - -clean - - - - - - - - - - - org.argeo.commons.security - org.argeo.security.ui - 0.2.3-SNAPSHOT - - - org.argeo.commons.security - org.argeo.security.equinox - 0.2.3-SNAPSHOT - - - - - org.argeo.commons.eclipse - org.argeo.eclipse.dep.rcp - 0.2.3-SNAPSHOT - provided - - - - - org.argeo.commons.basic - org.argeo.basic.nodeps - 0.2.3-SNAPSHOT - - - - - - org.slf4j - com.springsource.slf4j.org.apache.commons.logging - - - - - - org.argeo.commons.security - org.argeo.security.dep.ads - ${version.argeo-commons} - pom - test - - - diff --git a/security/eclipse/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/AbstractSecureApplication.java b/security/eclipse/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/AbstractSecureApplication.java deleted file mode 100644 index a0a2f922b..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/AbstractSecureApplication.java +++ /dev/null @@ -1,117 +0,0 @@ -package org.argeo.security.ui.application; - -import java.security.PrivilegedAction; - -import javax.security.auth.Subject; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.equinox.app.IApplication; -import org.eclipse.equinox.app.IApplicationContext; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.application.WorkbenchAdvisor; - -public abstract class AbstractSecureApplication implements IApplication { - private static final Log log = LogFactory - .getLog(AbstractSecureApplication.class); - - protected abstract WorkbenchAdvisor createWorkbenchAdvisor(); - - @SuppressWarnings("unchecked") - public Object start(IApplicationContext context) throws Exception { - - Integer returnCode = null; - Display display = PlatformUI.createDisplay(); - - // Force login - - try { - String username = null; - Exception loginException = null; - Subject subject = null; - try { - SecureApplicationActivator.getLoginContext().login(); - subject = SecureApplicationActivator.getLoginContext() - .getSubject(); - - // username = CurrentUser.getUsername(); - } catch (Exception e) { - loginException = e; - e.printStackTrace(); - } - if (subject == null) { - IStatus status = new Status(IStatus.ERROR, - "org.argeo.security.application", "Login is mandatory", - loginException); - ErrorDialog.openError(null, "Error", "Shutdown...", status); - return status.getSeverity(); - } - if (log.isDebugEnabled()) - log.debug("Logged in as " + username); - returnCode = (Integer) Subject.doAs(subject, getRunAction(display)); - SecureApplicationActivator.getLoginContext().logout(); - return processReturnCode(returnCode); - } catch (Exception e) { - // e.printStackTrace(); - IStatus status = new Status(IStatus.ERROR, - "org.argeo.security.rcp", "Login failed", e); - ErrorDialog.openError(null, "Error", "Shutdown...", status); - return returnCode; - } finally { - display.dispose(); - } - } - - protected Integer processReturnCode(Integer returnCode) { - return returnCode; - } - - @SuppressWarnings("rawtypes") - private PrivilegedAction getRunAction(final Display display) { - return new PrivilegedAction() { - - public Object run() { - int result = createAndRunWorkbench(display); - return new Integer(result); - } - }; - } - - protected Integer createAndRunWorkbench(Display display) { - return PlatformUI.createAndRunWorkbench(display, - createWorkbenchAdvisor()); - } - - public void stop() { - final IWorkbench workbench; - try { - workbench = PlatformUI.getWorkbench(); - } catch (Exception e) { - return; - } - if (workbench == null) - return; - final Display display = workbench.getDisplay(); - if (display != null && !display.isDisposed()) - display.syncExec(new Runnable() { - - public void run() { - if (!display.isDisposed()) - workbench.close(); - } - }); - - if (log.isDebugEnabled()) - log.debug("workbench stopped"); - // String username = CurrentUser.getUsername(); - // if (log.isDebugEnabled()) - // log.debug("workbench stopped, logged in as " + username); - - } - -} diff --git a/security/eclipse/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/RapSecureWorkbenchWindowAdvisor.java b/security/eclipse/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/RapSecureWorkbenchWindowAdvisor.java deleted file mode 100644 index fb4911a08..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/RapSecureWorkbenchWindowAdvisor.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.argeo.security.ui.application; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.application.ActionBarAdvisor; -import org.eclipse.ui.application.IActionBarConfigurer; -import org.eclipse.ui.application.IWorkbenchWindowConfigurer; - -public class RapSecureWorkbenchWindowAdvisor extends - SecureWorkbenchWindowAdvisor { - public RapSecureWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) { - super(configurer); - } - - @Override - public ActionBarAdvisor createActionBarAdvisor( - IActionBarConfigurer configurer) { - return new SecureActionBarAdvisor(configurer, false); - } - - public void preWindowOpen() { - IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); - configurer.setShowCoolBar(true); - configurer.setShowMenuBar(true); - configurer.setShowStatusLine(false); - configurer.setShowPerspectiveBar(true); - configurer.setTitle("Argeo Secure UI"); //$NON-NLS-1$ - // Full screen, see - // http://dev.eclipse.org/newslists/news.eclipse.technology.rap/msg02697.html - configurer.setShellStyle(SWT.NONE); - Rectangle bounds = Display.getDefault().getBounds(); - configurer.setInitialSize(new Point(bounds.width, bounds.height)); - } - -} diff --git a/security/eclipse/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureActionBarAdvisor.java b/security/eclipse/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureActionBarAdvisor.java deleted file mode 100644 index 61a3c0407..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureActionBarAdvisor.java +++ /dev/null @@ -1,94 +0,0 @@ -package org.argeo.security.ui.application; - -import org.eclipse.jface.action.GroupMarker; -import org.eclipse.jface.action.ICoolBarManager; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.action.ToolBarManager; -import org.eclipse.swt.SWT; -import org.eclipse.ui.IWorkbenchActionConstants; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.actions.ActionFactory; -import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction; -import org.eclipse.ui.application.ActionBarAdvisor; -import org.eclipse.ui.application.IActionBarConfigurer; - -public class SecureActionBarAdvisor extends ActionBarAdvisor { - private IWorkbenchAction exitAction; - private IWorkbenchAction openPerspectiveDialogAction; - private IWorkbenchAction showViewMenuAction; - private IWorkbenchAction preferences; - private IWorkbenchAction saveAction; - private IWorkbenchAction saveAllAction; - private IWorkbenchAction closeAllAction; - - // private final Boolean isRcp; - - public SecureActionBarAdvisor(IActionBarConfigurer configurer, Boolean isRcp) { - super(configurer); - // this.isRcp = isRcp; - } - - protected void makeActions(IWorkbenchWindow window) { - preferences = ActionFactory.PREFERENCES.create(window); - register(preferences); - openPerspectiveDialogAction = ActionFactory.OPEN_PERSPECTIVE_DIALOG - .create(window); - register(openPerspectiveDialogAction); - showViewMenuAction = ActionFactory.SHOW_VIEW_MENU.create(window); - register(showViewMenuAction); - - exitAction = ActionFactory.QUIT.create(window); - register(exitAction); - - // Save semantiocs - saveAction = ActionFactory.SAVE.create(window); - register(saveAction); - saveAllAction = ActionFactory.SAVE_ALL.create(window); - register(saveAllAction); - closeAllAction = ActionFactory.CLOSE_ALL.create(window); - register(closeAllAction); - - } - - protected void fillMenuBar(IMenuManager menuBar) { - MenuManager fileMenu = new MenuManager("&File", - IWorkbenchActionConstants.M_FILE); - MenuManager editMenu = new MenuManager("&Edit", - IWorkbenchActionConstants.M_EDIT); - MenuManager windowMenu = new MenuManager("&Window", - IWorkbenchActionConstants.M_WINDOW); - - menuBar.add(fileMenu); - menuBar.add(editMenu); - menuBar.add(windowMenu); - // Add a group marker indicating where action set menus will appear. - menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); - - // File - fileMenu.add(saveAction); - fileMenu.add(saveAllAction); - fileMenu.add(closeAllAction); - fileMenu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); - fileMenu.add(new Separator()); - fileMenu.add(exitAction); - - // Edit - editMenu.add(preferences); - - // Window - windowMenu.add(openPerspectiveDialogAction); - windowMenu.add(showViewMenuAction); - } - - @Override - protected void fillCoolBar(ICoolBarManager coolBar) { - IToolBarManager saveToolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT); - saveToolbar.add(saveAction); - saveToolbar.add(saveAllAction); - coolBar.add(saveToolbar); - } - -} diff --git a/security/eclipse/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureApplicationActivator.java b/security/eclipse/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureApplicationActivator.java deleted file mode 100644 index ec5d625de..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureApplicationActivator.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.argeo.security.ui.application; - -import java.net.URL; - -import org.eclipse.equinox.security.auth.ILoginContext; -import org.eclipse.equinox.security.auth.LoginContextFactory; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; - -public class SecureApplicationActivator implements BundleActivator { - - public final static String CONTEXT_SPRING = "SPRING"; - private static final String JAAS_CONFIG_FILE = "/META-INF/jaas_default.txt"; - - private static ILoginContext loginContext = null; - - public void start(BundleContext bundleContext) throws Exception { - URL configUrl = bundleContext.getBundle().getEntry(JAAS_CONFIG_FILE); - loginContext = LoginContextFactory.createContext(CONTEXT_SPRING, - configUrl); - } - - public void stop(BundleContext context) throws Exception { - } - - static ILoginContext getLoginContext() { - return loginContext; - } -} diff --git a/security/eclipse/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureRap.java b/security/eclipse/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureRap.java deleted file mode 100644 index 5f2ea3edc..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureRap.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.argeo.security.ui.application; - -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.application.IWorkbenchWindowConfigurer; -import org.eclipse.ui.application.WorkbenchAdvisor; -import org.eclipse.ui.application.WorkbenchWindowAdvisor; - -/** Generic secure application for RAP. */ -public class SecureRap extends AbstractSecureApplication { - - @Override - protected WorkbenchAdvisor createWorkbenchAdvisor() { - return new SecureWorkbenchAdvisor() { - public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor( - IWorkbenchWindowConfigurer configurer) { - return new RapSecureWorkbenchWindowAdvisor(configurer); - } - - }; - } - - public void stop() { - final IWorkbench workbench = PlatformUI.getWorkbench(); - if (workbench == null) - return; - final Display display = workbench.getDisplay(); - display.syncExec(new Runnable() { - - public void run() { - if (!display.isDisposed()) - workbench.close(); - } - }); - } - -} diff --git a/security/eclipse/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureRcp.java b/security/eclipse/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureRcp.java deleted file mode 100644 index b8576c4b9..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureRcp.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.argeo.security.ui.application; - -import org.eclipse.equinox.app.IApplication; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.application.WorkbenchAdvisor; - -public class SecureRcp extends AbstractSecureApplication { - - @Override - protected WorkbenchAdvisor createWorkbenchAdvisor() { - return new SecureWorkbenchAdvisor(); - } - - protected Integer processReturnCode(Integer returnCode) { - if (returnCode == PlatformUI.RETURN_RESTART) - return IApplication.EXIT_RESTART; - else - return IApplication.EXIT_OK; - } - -} diff --git a/security/eclipse/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureWorkbenchAdvisor.java b/security/eclipse/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureWorkbenchAdvisor.java deleted file mode 100644 index 417981664..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureWorkbenchAdvisor.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.argeo.security.ui.application; - -import org.eclipse.ui.application.IWorkbenchWindowConfigurer; -import org.eclipse.ui.application.WorkbenchAdvisor; -import org.eclipse.ui.application.WorkbenchWindowAdvisor; - -public class SecureWorkbenchAdvisor extends WorkbenchAdvisor { - - static final String DEFAULT_PERSPECTIVE_ID = "org.argeo.security.ui.securityPerspective"; //$NON-NLS-1$ - - public final static String INITIAL_PERSPECTIVE_PROPERTY = "org.argeo.security.ui.initialPerspective"; - private String initialPerspective = System.getProperty( - INITIAL_PERSPECTIVE_PROPERTY, DEFAULT_PERSPECTIVE_ID); - - public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor( - IWorkbenchWindowConfigurer configurer) { - return new SecureWorkbenchWindowAdvisor(configurer); - } - - public String getInitialWindowPerspectiveId() { - return initialPerspective; - } -} diff --git a/security/eclipse/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureWorkbenchWindowAdvisor.java b/security/eclipse/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureWorkbenchWindowAdvisor.java deleted file mode 100644 index 1eb5c6787..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureWorkbenchWindowAdvisor.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.argeo.security.ui.application; - -import org.eclipse.swt.graphics.Point; -import org.eclipse.ui.application.ActionBarAdvisor; -import org.eclipse.ui.application.IActionBarConfigurer; -import org.eclipse.ui.application.IWorkbenchWindowConfigurer; -import org.eclipse.ui.application.WorkbenchWindowAdvisor; - -public class SecureWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { - - public SecureWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) { - super(configurer); - } - - public ActionBarAdvisor createActionBarAdvisor( - IActionBarConfigurer configurer) { - return new SecureActionBarAdvisor(configurer, true); - } - - public void preWindowOpen() { - IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); - configurer.setInitialSize(new Point(1200, 900)); - configurer.setShowCoolBar(true); - configurer.setShowMenuBar(true); - configurer.setShowStatusLine(false); - - configurer.setShowPerspectiveBar(true); - configurer.setTitle("Argeo Secure UI"); //$NON-NLS-1$ - - } - -} diff --git a/security/eclipse/plugins/org.argeo.security.ui.rap/pom.xml b/security/eclipse/plugins/org.argeo.security.ui.rap/pom.xml deleted file mode 100644 index 764c63f1c..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui.rap/pom.xml +++ /dev/null @@ -1,132 +0,0 @@ - - 4.0.0 - - org.argeo.commons.security - 0.2.3-SNAPSHOT - plugins - .. - - org.argeo.security.ui.rap - Commons Security UI RAP - jar - - - - org.apache.maven.plugins - maven-compiler-plugin - - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-jar-plugin - - - org.argeo.maven.plugins - maven-argeo-osgi-plugin - - - resolve-pde-sources - - pde-sources - - generate-resources - - - generate-descriptors - - descriptors - - generate-resources - - - check-osgi - test - - equinox - - - true - - -clean - - - - - - - - - - org.argeo.commons.security - org.argeo.security.ui.application - 0.2.3-SNAPSHOT - - - org.argeo.commons.eclipse - org.argeo.eclipse.dep.rcp - - - - - - org.argeo.commons.eclipse - org.argeo.eclipse.dep.rap - 0.2.3-SNAPSHOT - - - - - - - org.argeo.commons.server - org.argeo.server.ads.server - ${version.argeo-commons} - test - - - org.argeo.commons.security - org.argeo.security.services - ${version.argeo-commons} - test - - - org.argeo.commons.security - org.argeo.security.ldap - ${version.argeo-commons} - test - - - org.argeo.commons.security - org.argeo.security.manager.ldap - ${version.argeo-commons} - test - - - org.argeo.commons.server - org.argeo.server.ads - 0.2.3-SNAPSHOT - test - - - org.argeo.dep.osgi - org.argeo.dep.osgi.springframework.ldap - test - - - org.argeo.commons.basic - org.argeo.basic.dep.log4j - 0.2.3-SNAPSHOT - pom - test - - - net.sourceforge.jdbm - com.springsource.jdbm - test - - - diff --git a/security/eclipse/plugins/org.argeo.security.ui/.classpath b/security/eclipse/plugins/org.argeo.security.ui/.classpath deleted file mode 100644 index 92f19d2ff..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/.classpath +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/security/eclipse/plugins/org.argeo.security.ui/.project b/security/eclipse/plugins/org.argeo.security.ui/.project deleted file mode 100644 index a052e9a57..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/.project +++ /dev/null @@ -1,28 +0,0 @@ - - - org.argeo.security.ui - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - - diff --git a/security/eclipse/plugins/org.argeo.security.ui/.settings/org.eclipse.jdt.core.prefs b/security/eclipse/plugins/org.argeo.security.ui/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index aef0f5291..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,8 +0,0 @@ -#Sat Jan 15 13:25:02 CET 2011 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.5 diff --git a/security/eclipse/plugins/org.argeo.security.ui/.settings/org.eclipse.pde.core.prefs b/security/eclipse/plugins/org.argeo.security.ui/.settings/org.eclipse.pde.core.prefs deleted file mode 100644 index dfa507d81..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/.settings/org.eclipse.pde.core.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Sat Jan 15 18:15:48 CET 2011 -eclipse.preferences.version=1 -resolve.requirebundle=false diff --git a/security/eclipse/plugins/org.argeo.security.ui/META-INF/spring/commands.xml b/security/eclipse/plugins/org.argeo.security.ui/META-INF/spring/commands.xml deleted file mode 100644 index a89876ad1..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/META-INF/spring/commands.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - diff --git a/security/eclipse/plugins/org.argeo.security.ui/META-INF/spring/editors.xml b/security/eclipse/plugins/org.argeo.security.ui/META-INF/spring/editors.xml deleted file mode 100644 index 747c2b7b6..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/META-INF/spring/editors.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - diff --git a/security/eclipse/plugins/org.argeo.security.ui/META-INF/spring/osgi.xml b/security/eclipse/plugins/org.argeo.security.ui/META-INF/spring/osgi.xml deleted file mode 100644 index 6574cf125..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/META-INF/spring/osgi.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - \ No newline at end of file diff --git a/security/eclipse/plugins/org.argeo.security.ui/META-INF/spring/views.xml b/security/eclipse/plugins/org.argeo.security.ui/META-INF/spring/views.xml deleted file mode 100644 index 7ae3b62e3..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/META-INF/spring/views.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - diff --git a/security/eclipse/plugins/org.argeo.security.ui/build.properties b/security/eclipse/plugins/org.argeo.security.ui/build.properties deleted file mode 100644 index 3868784bf..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/build.properties +++ /dev/null @@ -1,6 +0,0 @@ -source.. = src/main/java/ -output.. = target/classes/ -bin.includes = META-INF/,\ - .,\ - plugin.xml,\ - icons/ diff --git a/security/eclipse/plugins/org.argeo.security.ui/icons/add.gif b/security/eclipse/plugins/org.argeo.security.ui/icons/add.gif deleted file mode 100644 index 252d7ebcb..000000000 Binary files a/security/eclipse/plugins/org.argeo.security.ui/icons/add.gif and /dev/null differ diff --git a/security/eclipse/plugins/org.argeo.security.ui/icons/password.gif b/security/eclipse/plugins/org.argeo.security.ui/icons/password.gif deleted file mode 100644 index a6b251fc8..000000000 Binary files a/security/eclipse/plugins/org.argeo.security.ui/icons/password.gif and /dev/null differ diff --git a/security/eclipse/plugins/org.argeo.security.ui/icons/refresh.png b/security/eclipse/plugins/org.argeo.security.ui/icons/refresh.png deleted file mode 100644 index a3884fb48..000000000 Binary files a/security/eclipse/plugins/org.argeo.security.ui/icons/refresh.png and /dev/null differ diff --git a/security/eclipse/plugins/org.argeo.security.ui/icons/remove.gif b/security/eclipse/plugins/org.argeo.security.ui/icons/remove.gif deleted file mode 100644 index 0ae6decd0..000000000 Binary files a/security/eclipse/plugins/org.argeo.security.ui/icons/remove.gif and /dev/null differ diff --git a/security/eclipse/plugins/org.argeo.security.ui/icons/role.gif b/security/eclipse/plugins/org.argeo.security.ui/icons/role.gif deleted file mode 100644 index 274a850e4..000000000 Binary files a/security/eclipse/plugins/org.argeo.security.ui/icons/role.gif and /dev/null differ diff --git a/security/eclipse/plugins/org.argeo.security.ui/icons/save.gif b/security/eclipse/plugins/org.argeo.security.ui/icons/save.gif deleted file mode 100644 index 654ad7b42..000000000 Binary files a/security/eclipse/plugins/org.argeo.security.ui/icons/save.gif and /dev/null differ diff --git a/security/eclipse/plugins/org.argeo.security.ui/icons/save_security.png b/security/eclipse/plugins/org.argeo.security.ui/icons/save_security.png deleted file mode 100644 index ca41dc92b..000000000 Binary files a/security/eclipse/plugins/org.argeo.security.ui/icons/save_security.png and /dev/null differ diff --git a/security/eclipse/plugins/org.argeo.security.ui/icons/save_security_disabled.png b/security/eclipse/plugins/org.argeo.security.ui/icons/save_security_disabled.png deleted file mode 100644 index fb7d08d9a..000000000 Binary files a/security/eclipse/plugins/org.argeo.security.ui/icons/save_security_disabled.png and /dev/null differ diff --git a/security/eclipse/plugins/org.argeo.security.ui/icons/security.gif b/security/eclipse/plugins/org.argeo.security.ui/icons/security.gif deleted file mode 100644 index 57fb95edc..000000000 Binary files a/security/eclipse/plugins/org.argeo.security.ui/icons/security.gif and /dev/null differ diff --git a/security/eclipse/plugins/org.argeo.security.ui/icons/user.gif b/security/eclipse/plugins/org.argeo.security.ui/icons/user.gif deleted file mode 100644 index 90a00147b..000000000 Binary files a/security/eclipse/plugins/org.argeo.security.ui/icons/user.gif and /dev/null differ diff --git a/security/eclipse/plugins/org.argeo.security.ui/icons/users.gif b/security/eclipse/plugins/org.argeo.security.ui/icons/users.gif deleted file mode 100644 index 2de7edd64..000000000 Binary files a/security/eclipse/plugins/org.argeo.security.ui/icons/users.gif and /dev/null differ diff --git a/security/eclipse/plugins/org.argeo.security.ui/plugin.xml b/security/eclipse/plugins/org.argeo.security.ui/plugin.xml deleted file mode 100644 index 3a741cb09..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/plugin.xml +++ /dev/null @@ -1,160 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/security/eclipse/plugins/org.argeo.security.ui/pom.xml b/security/eclipse/plugins/org.argeo.security.ui/pom.xml deleted file mode 100644 index 0d9ed3165..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/pom.xml +++ /dev/null @@ -1,113 +0,0 @@ - - 4.0.0 - - org.argeo.commons.security - 0.2.3-SNAPSHOT - plugins - .. - - org.argeo.security.ui - Commons Security UI - jar - - - - org.apache.maven.plugins - maven-compiler-plugin - - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-jar-plugin - - - org.apache.felix - maven-bundle-plugin - ${version.maven-bundle-plugin} - - - - - - - - - - - - - - - - - - - - - - lazy - org.argeo.security.ui.SecurityUiPlugin - org.eclipse.ui;resolution:=optional,org.eclipse.rap.ui;resolution:=optional,org.eclipse.core.runtime - - org.argeo.eclipse.spring, - * - - - - - - - - - - org.argeo.commons.security - org.argeo.security.core - 0.2.3-SNAPSHOT - - - - - org.argeo.commons.eclipse - org.argeo.eclipse.ui - 0.2.3-SNAPSHOT - - - - - org.argeo.commons.eclipse - org.argeo.eclipse.dep.common - 0.2.3-SNAPSHOT - - - - - org.argeo.commons.eclipse - org.argeo.eclipse.dep.rcp - 0.2.3-SNAPSHOT - provided - - - - - org.argeo.commons.basic - org.argeo.basic.nodeps - 0.2.3-SNAPSHOT - - - - - org.springframework.security - org.springframework.security.core - - - - - org.slf4j - com.springsource.slf4j.org.apache.commons.logging - - - diff --git a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/CurrentUser.java b/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/CurrentUser.java deleted file mode 100644 index a864c3a10..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/CurrentUser.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.argeo.security.ui; - -import java.security.AccessController; -import java.security.Principal; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - -import javax.security.auth.Subject; - -import org.argeo.ArgeoException; -import org.springframework.security.Authentication; -import org.springframework.security.GrantedAuthority; - -public class CurrentUser { - public final static String getUsername() { - Subject subject = getSubject(); - if (subject == null) - return null; - Principal principal = subject.getPrincipals().iterator().next(); - return principal.getName(); - - } - - public final static Set roles() { - Principal principal = getSubject().getPrincipals().iterator().next(); - Authentication authentication = (Authentication) principal; - Set roles = Collections.synchronizedSet(new HashSet()); - for (GrantedAuthority ga : authentication.getAuthorities()) { - roles.add(ga.getAuthority()); - } - return Collections.unmodifiableSet(roles); - } - - public final static Subject getSubject() { - - Subject subject = Subject.getSubject(AccessController.getContext()); - if (subject == null) - throw new ArgeoException("Not authenticated."); - return subject; - - } -} diff --git a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/SecurityPerspective.java b/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/SecurityPerspective.java deleted file mode 100644 index 3b3b9b840..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/SecurityPerspective.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.argeo.security.ui; - -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IFolderLayout; -import org.eclipse.ui.IPageLayout; -import org.eclipse.ui.IPerspectiveFactory; - -public class SecurityPerspective implements IPerspectiveFactory { - private String adminRole = "ROLE_ADMIN"; - - public void createInitialLayout(IPageLayout layout) { - if (!CurrentUser.roles().contains(adminRole)) { - MessageDialog - .openError(Display.getCurrent().getActiveShell(), - "Forbidden", - "You are not allowed to access this resource."); - return; - } - - String editorArea = layout.getEditorArea(); - layout.setEditorAreaVisible(true); - layout.setFixed(false); - - IFolderLayout left = layout.createFolder("left", IPageLayout.LEFT, - 0.4f, editorArea); - - left.addView("org.argeo.security.ui.usersView"); - left.addView("org.argeo.security.ui.rolesView"); - // left.addView("org.argeo.security.ui.currentUserView"); - } - - public void setAdminRole(String adminRole) { - this.adminRole = adminRole; - } - -} diff --git a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/SecurityUiPlugin.java b/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/SecurityUiPlugin.java deleted file mode 100644 index bc05495b4..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/SecurityUiPlugin.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.argeo.security.ui; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.osgi.framework.BundleContext; - -/** - * The activator class controls the plug-in life cycle - */ -public class SecurityUiPlugin extends AbstractUIPlugin { - - // The plug-in ID - public static final String PLUGIN_ID = "org.argeo.security.ui"; //$NON-NLS-1$ - - // The shared instance - private static SecurityUiPlugin plugin; - - /** - * The constructor - */ - public SecurityUiPlugin() { - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext - * ) - */ - public void start(BundleContext context) throws Exception { - super.start(context); - plugin = this; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext - * ) - */ - public void stop(BundleContext context) throws Exception { - plugin = null; - super.stop(context); - } - - /** - * Returns the shared instance - * - * @return the shared instance - */ - public static SecurityUiPlugin getDefault() { - return plugin; - } - - public static ImageDescriptor getImageDescriptor(String path) { - return imageDescriptorFromPlugin(PLUGIN_ID, path); - } -} diff --git a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/AddRole.java b/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/AddRole.java deleted file mode 100644 index 1873a1391..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/AddRole.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.argeo.security.ui.commands; - -import org.argeo.ArgeoException; -import org.argeo.security.ArgeoSecurityService; -import org.argeo.security.ui.views.RolesView; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.ui.handlers.HandlerUtil; - -/** Add a new role. */ -public class AddRole extends AbstractHandler { - public final static String COMMAND_ID = "org.argeo.security.ui.addRole"; - private ArgeoSecurityService securityService; - private String rolePrefix = "ROLE_"; - - public Object execute(ExecutionEvent event) throws ExecutionException { - RolesView rolesView = (RolesView) HandlerUtil - .getActiveWorkbenchWindow(event).getActivePage() - .findView(RolesView.ID); - String role = rolesView.getNewRole(); - if (role.trim().equals("")) - return null; - if (role.equals(rolesView.getAddNewRoleText())) - return null; - role = role.trim().toUpperCase(); - if (!role.startsWith(rolePrefix)) - role = rolePrefix + role; - if (securityService.listEditableRoles().contains(role)) - throw new ArgeoException("Role " + role + " already exists"); - securityService.newRole(role); - rolesView.refresh(); - return null; - } - - public void setSecurityService(ArgeoSecurityService securityService) { - this.securityService = securityService; - } - -} diff --git a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/OpenArgeoUserEditor.java b/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/OpenArgeoUserEditor.java deleted file mode 100644 index c9bd25f54..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/OpenArgeoUserEditor.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.argeo.security.ui.commands; - -import org.argeo.security.ui.editors.ArgeoUserEditor; -import org.argeo.security.ui.editors.ArgeoUserEditorInput; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.handlers.HandlerUtil; - -/** Command handler to set visible or open a Argeo user. */ -public class OpenArgeoUserEditor extends AbstractHandler { - public final static String COMMAND_ID = "org.argeo.security.ui.openArgeoUserEditor"; - public final static String PARAM_USERNAME = "org.argeo.security.ui.username"; - - public Object execute(ExecutionEvent event) throws ExecutionException { - try { - ArgeoUserEditorInput editorInput = new ArgeoUserEditorInput( - event.getParameter(PARAM_USERNAME)); - IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow( - event).getActivePage(); - activePage.openEditor(editorInput, ArgeoUserEditor.ID); - } catch (Exception e) { - throw new ExecutionException("Cannot open editor", e); - } - return null; - } -} diff --git a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/OpenChangePasswordDialog.java b/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/OpenChangePasswordDialog.java deleted file mode 100644 index 70471159d..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/OpenChangePasswordDialog.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.argeo.security.ui.commands; - -import org.argeo.security.ArgeoSecurityService; -import org.argeo.security.ui.dialogs.ChangePasswordDialog; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.ui.handlers.HandlerUtil; - -/** Opens the change password dialog. */ -public class OpenChangePasswordDialog extends AbstractHandler { - private ArgeoSecurityService securityService; - - public Object execute(ExecutionEvent event) throws ExecutionException { - ChangePasswordDialog dialog = new ChangePasswordDialog( - HandlerUtil.getActiveShell(event), securityService); - dialog.open(); - return null; - } - - public void setSecurityService(ArgeoSecurityService securityService) { - this.securityService = securityService; - } - -} diff --git a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/RefreshUsersList.java b/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/RefreshUsersList.java deleted file mode 100644 index a385eb995..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/RefreshUsersList.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.argeo.security.ui.commands; - -import org.argeo.security.ui.views.UsersView; -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.ui.handlers.HandlerUtil; - -/** Refresh the main EBI list. */ -public class RefreshUsersList extends AbstractHandler { - - public Object execute(ExecutionEvent event) throws ExecutionException { - UsersView view = (UsersView) HandlerUtil - .getActiveWorkbenchWindow(event).getActivePage() - .findView(UsersView.ID); - view.refresh(); - return null; - } - -} \ No newline at end of file diff --git a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/SaveArgeoUser.java b/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/SaveArgeoUser.java deleted file mode 100644 index 7d817435e..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/SaveArgeoUser.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.argeo.security.ui.commands; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.handlers.HandlerUtil; - -/** Save the currently edited Argeo user. */ -public class SaveArgeoUser extends AbstractHandler { - public final static String COMMAND_ID = "org.argeo.security.ui.saveArgeoUser"; - - public Object execute(ExecutionEvent event) throws ExecutionException { - try { - IWorkbenchPart iwp = HandlerUtil.getActiveWorkbenchWindow(event) - .getActivePage().getActivePart(); - - if (!(iwp instanceof IEditorPart)) - return null; - IEditorPart editor = (IEditorPart) iwp; - editor.doSave(null); - } catch (Exception e) { - MessageDialog.openError(Display.getDefault().getActiveShell(), - "Error", "Cannot save user: " + e.getMessage()); - } - return null; - } - -} diff --git a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/dialogs/AbstractLoginDialog.java b/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/dialogs/AbstractLoginDialog.java deleted file mode 100644 index d3d1be38b..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/dialogs/AbstractLoginDialog.java +++ /dev/null @@ -1,127 +0,0 @@ -package org.argeo.security.ui.dialogs; - -import java.io.IOException; - -import javax.security.auth.callback.Callback; -import javax.security.auth.callback.CallbackHandler; -import javax.security.auth.callback.NameCallback; -import javax.security.auth.callback.PasswordCallback; - -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.TitleAreaDialog; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.operation.ModalContext; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -public abstract class AbstractLoginDialog extends TitleAreaDialog implements - CallbackHandler { - - boolean processCallbacks = false; - boolean isCancelled = false; - Callback[] callbackArray; - - protected final Callback[] getCallbacks() { - return this.callbackArray; - } - - public abstract void internalHandle(); - - public boolean isCancelled() { - return isCancelled; - } - - protected AbstractLoginDialog(Shell parentShell) { - super(parentShell); - } - - /* - * (non-Javadoc) - * - * @see - * javax.security.auth.callback.CallbackHandler#handle(javax.security.auth - * .callback.Callback[]) - */ - public void handle(final Callback[] callbacks) throws IOException { - this.callbackArray = callbacks; - final Display display = Display.getDefault(); - display.syncExec(new Runnable() { - - public void run() { - isCancelled = false; - setBlockOnOpen(false); - open(); - final Button okButton = getButton(IDialogConstants.OK_ID); - okButton.setText("Login"); - okButton.addSelectionListener(new SelectionListener() { - - public void widgetSelected(final SelectionEvent event) { - processCallbacks = true; - } - - public void widgetDefaultSelected(final SelectionEvent event) { - // nothing to do - } - }); - final Button cancel = getButton(IDialogConstants.CANCEL_ID); - cancel.addSelectionListener(new SelectionListener() { - - public void widgetSelected(final SelectionEvent event) { - isCancelled = true; - processCallbacks = true; - } - - public void widgetDefaultSelected(final SelectionEvent event) { - // nothing to do - } - }); - } - }); - try { - ModalContext.setAllowReadAndDispatch(true); // Works for now. - ModalContext.run(new IRunnableWithProgress() { - - public void run(final IProgressMonitor monitor) { - // Wait here until OK or cancel is pressed, then let it rip. - // The event - // listener - // is responsible for closing the dialog (in the - // loginSucceeded - // event). - while (!processCallbacks) { - try { - Thread.sleep(100); - } catch (final Exception e) { - // do nothing - } - } - processCallbacks = false; - // Call the adapter to handle the callbacks - if (!isCancelled()) - internalHandle(); - else - // clear callbacks are when cancelling - for (Callback callback : callbacks) - if (callback instanceof PasswordCallback) - ((PasswordCallback) callback).setPassword(null); - else if (callback instanceof NameCallback) - ((NameCallback) callback).setName(null); - } - }, true, new NullProgressMonitor(), Display.getDefault()); - } catch (final Exception e) { - final IOException ioe = new IOException(); - ioe.initCause(e); - throw ioe; - } - } - - protected void configureShell(Shell shell) { - super.configureShell(shell); - shell.setText("Login"); - } -} diff --git a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/dialogs/ChangePasswordDialog.java b/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/dialogs/ChangePasswordDialog.java deleted file mode 100644 index e2e78e814..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/dialogs/ChangePasswordDialog.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.argeo.security.ui.dialogs; - -import org.argeo.ArgeoException; -import org.argeo.security.ArgeoSecurityService; -import org.eclipse.jface.dialogs.IMessageProvider; -import org.eclipse.jface.dialogs.TitleAreaDialog; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** Dialog to change the current user password */ -public class ChangePasswordDialog extends TitleAreaDialog { - private Text currentPassword, newPassword1, newPassword2; - private ArgeoSecurityService securityService; - - public ChangePasswordDialog(Shell parentShell, - ArgeoSecurityService securityService) { - super(parentShell); - this.securityService = securityService; - } - - protected Point getInitialSize() { - return new Point(300, 250); - } - - protected Control createDialogArea(Composite parent) { - Composite dialogarea = (Composite) super.createDialogArea(parent); - dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - Composite composite = new Composite(dialogarea, SWT.NONE); - composite.setLayout(new GridLayout(2, false)); - composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - currentPassword = createLP(composite, "Current password"); - newPassword1 = createLP(composite, "New password"); - newPassword2 = createLP(composite, "Repeat new password"); - - setMessage("Change password", IMessageProvider.INFORMATION); - parent.pack(); - return composite; - } - - @Override - protected void okPressed() { - if (!newPassword1.getText().equals(newPassword2.getText())) - throw new ArgeoException("Passwords are different"); - securityService.updateCurrentUserPassword(currentPassword.getText(), - newPassword1.getText()); - close(); - } - - /** Creates label and password. */ - protected Text createLP(Composite parent, String label) { - new Label(parent, SWT.NONE).setText(label); - Text text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.PASSWORD - | SWT.BORDER); - text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - return text; - } - - protected void configureShell(Shell shell) { - super.configureShell(shell); - shell.setText("Change password"); - } - -} diff --git a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/dialogs/DefaultLoginDialog.java b/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/dialogs/DefaultLoginDialog.java deleted file mode 100644 index d00e961fb..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/dialogs/DefaultLoginDialog.java +++ /dev/null @@ -1,114 +0,0 @@ -package org.argeo.security.ui.dialogs; - -import javax.security.auth.callback.Callback; -import javax.security.auth.callback.NameCallback; -import javax.security.auth.callback.PasswordCallback; -import javax.security.auth.callback.TextOutputCallback; - -import org.eclipse.jface.dialogs.IMessageProvider; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -public class DefaultLoginDialog extends AbstractLoginDialog { - - public DefaultLoginDialog() { - this(Display.getDefault().getActiveShell()); - } - - protected DefaultLoginDialog(Shell parentShell) { - super(parentShell); - } - - protected Point getInitialSize() { - return new Point(300, 250); - } - - protected Control createDialogArea(Composite parent) { - Composite dialogarea = (Composite) super.createDialogArea(parent); - // dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, - // true)); - Composite composite = new Composite(dialogarea, SWT.NONE); - composite.setLayout(new GridLayout(2, false)); - composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - createCallbackHandlers(composite); - parent.pack(); - return composite; - } - - private void createCallbackHandlers(Composite composite) { - Callback[] callbacks = getCallbacks(); - for (int i = 0; i < callbacks.length; i++) { - Callback callback = callbacks[i]; - if (callback instanceof TextOutputCallback) { - createTextoutputHandler(composite, - (TextOutputCallback) callback); - } else if (callback instanceof NameCallback) { - createNameHandler(composite, (NameCallback) callback); - } else if (callback instanceof PasswordCallback) { - createPasswordHandler(composite, (PasswordCallback) callback); - } - } - } - - private void createPasswordHandler(Composite composite, - final PasswordCallback callback) { - Label label = new Label(composite, SWT.NONE); - label.setText(callback.getPrompt()); - final Text passwordText = new Text(composite, SWT.SINGLE | SWT.LEAD - | SWT.PASSWORD | SWT.BORDER); - passwordText - .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - passwordText.addModifyListener(new ModifyListener() { - - public void modifyText(ModifyEvent event) { - callback.setPassword(passwordText.getText().toCharArray()); - } - }); - } - - private void createNameHandler(Composite composite, - final NameCallback callback) { - Label label = new Label(composite, SWT.NONE); - label.setText(callback.getPrompt()); - final Text text = new Text(composite, SWT.SINGLE | SWT.LEAD - | SWT.BORDER); - text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - text.addModifyListener(new ModifyListener() { - - public void modifyText(ModifyEvent event) { - callback.setName(text.getText()); - } - }); - } - - private void createTextoutputHandler(Composite composite, - TextOutputCallback callback) { - int messageType = callback.getMessageType(); - int dialogMessageType = IMessageProvider.NONE; - switch (messageType) { - case TextOutputCallback.INFORMATION: - dialogMessageType = IMessageProvider.INFORMATION; - break; - case TextOutputCallback.WARNING: - dialogMessageType = IMessageProvider.WARNING; - break; - case TextOutputCallback.ERROR: - dialogMessageType = IMessageProvider.ERROR; - break; - } - setMessage(callback.getMessage(), dialogMessageType); - } - - public void internalHandle() { - } -} diff --git a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/ArgeoUserEditor.java b/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/ArgeoUserEditor.java deleted file mode 100644 index 99a4652a9..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/ArgeoUserEditor.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.argeo.security.ui.editors; - -import org.argeo.ArgeoException; -import org.argeo.security.ArgeoSecurityService; -import org.argeo.security.ArgeoUser; -import org.argeo.security.SimpleArgeoUser; -import org.argeo.security.nature.SimpleUserNature; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorSite; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.forms.editor.FormEditor; - -/** Editor for an Argeo user. */ -public class ArgeoUserEditor extends FormEditor { - public final static String ID = "org.argeo.security.ui.argeoUserEditor"; - - private ArgeoUser user; - private ArgeoSecurityService securityService; - - public void init(IEditorSite site, IEditorInput input) - throws PartInitException { - super.init(site, input); - String username = ((ArgeoUserEditorInput) getEditorInput()) - .getUsername(); - if (username == null) {// new - user = new SimpleArgeoUser(); - user.getUserNatures().put(SimpleUserNature.TYPE, - new SimpleUserNature()); - } else - user = securityService.getUser(username); - this.setPartProperty("name", username != null ? username : ""); - setPartName(username != null ? username : ""); - } - - protected void addPages() { - try { - addPage(new DefaultUserMainPage(this, securityService, user)); - - } catch (PartInitException e) { - throw new ArgeoException("Not able to add page ", e); - } - } - - @Override - public void doSave(IProgressMonitor monitor) { - // list pages - // TODO: make it more generic - findPage(DefaultUserMainPage.ID).doSave(monitor); - - if (securityService.userExists(user.getUsername())) - securityService.updateUser(user); - else { - securityService.newUser(user); - setPartName(user.getUsername()); - } - firePropertyChange(PROP_DIRTY); - } - - @Override - public void doSaveAs() { - } - - @Override - public boolean isSaveAsAllowed() { - return false; - } - - public void setSecurityService(ArgeoSecurityService securityService) { - this.securityService = securityService; - } -} diff --git a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/ArgeoUserEditorInput.java b/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/ArgeoUserEditorInput.java deleted file mode 100644 index 9d61e9fab..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/ArgeoUserEditorInput.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.argeo.security.ui.editors; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IPersistableElement; - -/** Editor input for an Argeo user. */ -public class ArgeoUserEditorInput implements IEditorInput { - private final String username; - - public ArgeoUserEditorInput(String username) { - this.username = username; - } - - public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) { - return null; - } - - public boolean exists() { - return username != null; - } - - public ImageDescriptor getImageDescriptor() { - return null; - } - - public String getName() { - return username != null ? username : ""; - } - - public IPersistableElement getPersistable() { - return null; - } - - public String getToolTipText() { - return username != null ? username : ""; - } - - public boolean equals(Object obj) { - if (!(obj instanceof ArgeoUserEditorInput)) - return false; - if (((ArgeoUserEditorInput) obj).getUsername() == null) - return false; - return ((ArgeoUserEditorInput) obj).getUsername().equals(username); - } - - public String getUsername() { - return username; - } - -} diff --git a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/DefaultUserMainPage.java b/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/DefaultUserMainPage.java deleted file mode 100644 index 6180de49a..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/DefaultUserMainPage.java +++ /dev/null @@ -1,337 +0,0 @@ -package org.argeo.security.ui.editors; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.argeo.security.ArgeoSecurityService; -import org.argeo.security.ArgeoUser; -import org.argeo.security.SimpleArgeoUser; -import org.argeo.security.nature.SimpleUserNature; -import org.argeo.security.ui.SecurityUiPlugin; -import org.eclipse.jface.viewers.CellEditor; -import org.eclipse.jface.viewers.CheckboxCellEditor; -import org.eclipse.jface.viewers.ColumnLabelProvider; -import org.eclipse.jface.viewers.EditingSupport; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TableViewerColumn; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.forms.AbstractFormPart; -import org.eclipse.ui.forms.IManagedForm; -import org.eclipse.ui.forms.SectionPart; -import org.eclipse.ui.forms.editor.FormEditor; -import org.eclipse.ui.forms.editor.FormPage; -import org.eclipse.ui.forms.widgets.ColumnLayout; -import org.eclipse.ui.forms.widgets.FormToolkit; -import org.eclipse.ui.forms.widgets.ScrolledForm; -import org.eclipse.ui.forms.widgets.Section; - -/** - * Display/edit the properties common to all {@link ArgeoUser} (username and - * roles) as well as the properties of the {@link SimpleUserNature}. - */ -public class DefaultUserMainPage extends FormPage { - final static String ID = "argeoUserEditor.mainPage"; - - private final static Log log = LogFactory.getLog(DefaultUserMainPage.class); - private final static Image ROLE_CHECKED = SecurityUiPlugin - .getImageDescriptor("icons/security.gif").createImage(); - - private ArgeoUser user; - private SimpleUserNature simpleNature; - private String simpleNatureType; - private ArgeoSecurityService securityService; - - public DefaultUserMainPage(FormEditor editor, - ArgeoSecurityService securityService, ArgeoUser user) { - super(editor, ID, "Main"); - this.securityService = securityService; - this.user = user; - this.simpleNature = SimpleUserNature.findSimpleUserNature(user, - simpleNatureType); - } - - protected void createFormContent(final IManagedForm mf) { - ScrolledForm form = mf.getForm(); - form.setText(simpleNature.getFirstName() + " " - + simpleNature.getLastName()); - ColumnLayout mainLayout = new ColumnLayout(); - mainLayout.minNumColumns = 1; - mainLayout.maxNumColumns = 4; - mainLayout.topMargin = 0; - mainLayout.bottomMargin = 5; - mainLayout.leftMargin = mainLayout.rightMargin = mainLayout.horizontalSpacing = mainLayout.verticalSpacing = 10; - form.getBody().setLayout(mainLayout); - - createGeneralPart(form.getBody()); - createRolesPart(form.getBody()); - createPassworPart(form.getBody()); - } - - /** Creates the general section */ - protected void createGeneralPart(Composite parent) { - FormToolkit tk = getManagedForm().getToolkit(); - Section section = tk.createSection(parent, Section.TITLE_BAR); - section.setText("General"); - - Composite body = tk.createComposite(section, SWT.WRAP); - section.setClient(body); - GridLayout layout = new GridLayout(); - layout.marginWidth = layout.marginHeight = 0; - layout.numColumns = 2; - body.setLayout(layout); - - // add widgets (view) - final Text username; - if (user.getUsername() != null) { - tk.createLabel(body, "Username"); - tk.createLabel(body, user.getUsername()); - username = null; - } else { - username = createLT(body, "Username", ""); - } - final Text firstName = createLT(body, "First name", - simpleNature.getFirstName()); - final Text lastName = createLT(body, "Last name", - simpleNature.getLastName()); - final Text email = createLT(body, "Email", simpleNature.getEmail()); - final Text description = createLT(body, "Description", - simpleNature.getDescription()); - - // create form part (controller) - AbstractFormPart part = new SectionPart(section) { - public void commit(boolean onSave) { - if (username != null) { - ((SimpleArgeoUser) user).setUsername(username.getText()); - username.setEditable(false); - username.setEnabled(false); - } - simpleNature.setFirstName(firstName.getText()); - simpleNature.setLastName(lastName.getText()); - simpleNature.setEmail(email.getText()); - simpleNature.setDescription(description.getText()); - super.commit(onSave); - if (log.isTraceEnabled()) - log.trace("General part committed"); - } - }; - if (username != null) - username.addModifyListener(new FormPartML(part)); - firstName.addModifyListener(new FormPartML(part)); - lastName.addModifyListener(new FormPartML(part)); - email.addModifyListener(new FormPartML(part)); - description.addModifyListener(new FormPartML(part)); - getManagedForm().addPart(part); - } - - /** Creates the password section */ - protected void createPassworPart(Composite parent) { - FormToolkit tk = getManagedForm().getToolkit(); - Section section = tk.createSection(parent, Section.TITLE_BAR); - section.setText("Password"); - - Composite body = tk.createComposite(section, SWT.WRAP); - section.setClient(body); - GridLayout layout = new GridLayout(); - layout.marginWidth = layout.marginHeight = 0; - layout.numColumns = 2; - body.setLayout(layout); - - // add widgets (view) - final Text password1 = createLP(body, "New password", ""); - final Text password2 = createLP(body, "Repeat password", ""); - // create form part (controller) - AbstractFormPart part = new SectionPart(section) { - public void commit(boolean onSave) { - if (!password1.getText().equals("") - && password1.getText().equals(password2.getText())) { - ((SimpleArgeoUser) user).setPassword(password1.getText()); - } - super.commit(onSave); - if (log.isTraceEnabled()) - log.trace("Password part committed"); - } - }; - password1.addModifyListener(new FormPartML(part)); - password2.addModifyListener(new FormPartML(part)); - getManagedForm().addPart(part); - } - - /** Creates the role section */ - protected void createRolesPart(Composite parent) { - FormToolkit tk = getManagedForm().getToolkit(); - Section section = tk.createSection(parent, Section.DESCRIPTION - | Section.TITLE_BAR); - section.setText("Roles"); - section.setDescription("Roles define " - + "the authorizations for this user."); - Table table = new Table(section, SWT.MULTI | SWT.H_SCROLL - | SWT.V_SCROLL); - section.setClient(table); - - AbstractFormPart part = new SectionPart(section) { - public void commit(boolean onSave) { - // roles have already been modified in editing - super.commit(onSave); - if (log.isTraceEnabled()) - log.trace("Role part committed"); - } - }; - getManagedForm().addPart(part); - - GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); - gridData.verticalSpan = 20; - table.setLayoutData(gridData); - table.setLinesVisible(true); - table.setHeaderVisible(false); - TableViewer viewer = new TableViewer(table); - - // check column - TableViewerColumn column = createTableViewerColumn(viewer, "checked", - 20); - column.setLabelProvider(new ColumnLabelProvider() { - public String getText(Object element) { - return null; - } - - public Image getImage(Object element) { - String role = element.toString(); - if (user.getRoles().contains(role)) { - return ROLE_CHECKED; - } else { - return null; - } - } - }); - column.setEditingSupport(new RoleEditingSupport(viewer, part)); - - // role column - column = createTableViewerColumn(viewer, "Role", 200); - column.setLabelProvider(new ColumnLabelProvider() { - public String getText(Object element) { - return element.toString(); - } - - public Image getImage(Object element) { - return null; - } - }); - viewer.setContentProvider(new RolesContentProvider()); - viewer.setInput(getEditorSite()); - } - - protected TableViewerColumn createTableViewerColumn(TableViewer viewer, - String title, int bound) { - final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, - SWT.NONE); - final TableColumn column = viewerColumn.getColumn(); - column.setText(title); - column.setWidth(bound); - column.setResizable(true); - column.setMoveable(true); - return viewerColumn; - - } - - /** Creates label and text. */ - protected Text createLT(Composite body, String label, String value) { - FormToolkit toolkit = getManagedForm().getToolkit(); - toolkit.createLabel(body, label); - Text text = toolkit.createText(body, value, SWT.BORDER); - text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - return text; - } - - /** Creates label and password. */ - protected Text createLP(Composite body, String label, String value) { - FormToolkit toolkit = getManagedForm().getToolkit(); - toolkit.createLabel(body, label); - Text text = toolkit.createText(body, value, SWT.BORDER | SWT.PASSWORD); - text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - return text; - } - - public void setSimpleNatureType(String simpleNatureType) { - this.simpleNatureType = simpleNatureType; - } - - private class FormPartML implements ModifyListener { - private AbstractFormPart formPart; - - public FormPartML(AbstractFormPart generalPart) { - this.formPart = generalPart; - } - - public void modifyText(ModifyEvent e) { - formPart.markDirty(); - } - - } - - private class RolesContentProvider implements IStructuredContentProvider { - public Object[] getElements(Object inputElement) { - return securityService.listEditableRoles().toArray(); - } - - public void dispose() { - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - } - - /** Select the columns by editing the checkbox in the first column */ - class RoleEditingSupport extends EditingSupport { - - private final TableViewer viewer; - private final AbstractFormPart formPart; - - public RoleEditingSupport(TableViewer viewer, AbstractFormPart formPart) { - super(viewer); - this.viewer = viewer; - this.formPart = formPart; - } - - @Override - protected CellEditor getCellEditor(Object element) { - return new CheckboxCellEditor(null, SWT.CHECK | SWT.READ_ONLY); - - } - - @Override - protected boolean canEdit(Object element) { - return true; - } - - @Override - protected Object getValue(Object element) { - String role = element.toString(); - return user.getRoles().contains(role); - - } - - @Override - protected void setValue(Object element, Object value) { - Boolean inRole = (Boolean) value; - String role = element.toString(); - if (inRole && !user.getRoles().contains(role)) { - user.getRoles().add(role); - formPart.markDirty(); - } else if (!inRole && user.getRoles().contains(role)) { - user.getRoles().remove(role); - formPart.markDirty(); - } - viewer.refresh(); - } - } - -} diff --git a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/CurrentUserView.java b/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/CurrentUserView.java deleted file mode 100644 index 5b0492828..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/CurrentUserView.java +++ /dev/null @@ -1,129 +0,0 @@ -package org.argeo.security.ui.views; - -import org.argeo.security.ui.CurrentUser; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.ui.part.ViewPart; - -public class CurrentUserView extends ViewPart { - private TableViewer viewer; - - @Override - public void createPartControl(Composite parent) { - - // viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL - // | SWT.V_SCROLL); - viewer = new TableViewer(createTable(parent)); - viewer.setContentProvider(new UsersContentProvider()); - viewer.setLabelProvider(new UsersLabelProvider()); - viewer.setInput(getViewSite()); - // viewer.setInput(SecurityContextHolder.getContext()); - } - - protected Table createTable(Composite parent) { - int style = SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL; - - Table table = new Table(parent, style); - - // GridData gridData = new GridData(GridData.FILL_BOTH); - // gridData.grabExcessVerticalSpace = true; - // gridData.grabExcessHorizontalSpace = true; - // gridData.horizontalSpan = 3; - // table.setLayoutData(gridData); - - table.setLinesVisible(true); - table.setHeaderVisible(true); - - TableColumn column = new TableColumn(table, SWT.LEFT, 0); - column.setText("ID"); - column.setWidth(100); - - // column = new TableColumn(table, SWT.LEFT, 1); - // column.setText("Password"); - // column.setWidth(200); - - // column = new TableColumn(table, SWT.LEFT, 2); - // column.setText("Roles"); - // column.setWidth(300); - - return table; - } - - @Override - public void setFocus() { - viewer.getTable().setFocus(); - } - - private class UsersContentProvider implements IStructuredContentProvider { - - public Object[] getElements(Object inputElement) { - return getChildren(inputElement); - } - - public Object[] getChildren(Object parentElement) { - // ILoginContext secureContext = LoginContextFactory - // .createContext("SPRING"); - // try { - // secureContext.login(); - // } catch (LoginException e) { - // // login failed - // } - // - // Subject subject = null; - // // subject = Subject.getSubject(AccessController.getContext()); - // try { - // subject = secureContext.getSubject(); - // } catch (Exception e) { - // e.printStackTrace(); - // throw new ArgeoException("Cannot retrieve subject", e); - // } - // - // if (subject == null) - // throw new ArgeoException("No subject found"); - // return subject.getPrincipals().toArray(); - return CurrentUser.roles().toArray(); - } - - public void dispose() { - // TODO Auto-generated method stub - - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - // TODO Auto-generated method stub - - } - - } - - private class UsersLabelProvider extends LabelProvider implements - ITableLabelProvider { - public String getColumnText(Object element, int columnIndex) { - // Principal argeoUser = (Principal) element; - // switch (columnIndex) { - // case 0: - // return argeoUser.getName(); - // case 1: - // return argeoUser.toString(); - // default: - // throw new ArgeoException("Unmanaged column " + columnIndex); - // } - return element.toString(); - } - - public Image getColumnImage(Object element, int columnIndex) { - // TODO Auto-generated method stub - return null; - } - - } - -} diff --git a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/RolesView.java b/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/RolesView.java deleted file mode 100644 index a58675e4b..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/RolesView.java +++ /dev/null @@ -1,177 +0,0 @@ -package org.argeo.security.ui.views; - -import java.util.ArrayList; - -import org.argeo.ArgeoException; -import org.argeo.security.ArgeoSecurityService; -import org.argeo.security.ArgeoUser; -import org.argeo.security.ui.SecurityUiPlugin; -import org.argeo.security.ui.commands.AddRole; -import org.argeo.security.ui.commands.OpenArgeoUserEditor; -import org.eclipse.core.commands.Command; -import org.eclipse.core.commands.IParameter; -import org.eclipse.core.commands.Parameterization; -import org.eclipse.core.commands.ParameterizedCommand; -import org.eclipse.jface.viewers.DoubleClickEvent; -import org.eclipse.jface.viewers.IDoubleClickListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.commands.ICommandService; -import org.eclipse.ui.handlers.IHandlerService; -import org.eclipse.ui.part.ViewPart; - -/** List all roles. */ -public class RolesView extends ViewPart { - public final static String ID = "org.argeo.security.ui.rolesView"; - - private Text newRole; - - private TableViewer viewer; - private ArgeoSecurityService securityService; - - private String addNewRoleText = ""; - - @Override - public void createPartControl(Composite parent) { - parent.setLayout(new GridLayout(1, false)); - - // new role text field - newRole = new Text(parent, SWT.BORDER); - newRole.setText(addNewRoleText); - newRole.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); - // default action is add role - newRole.addListener(SWT.DefaultSelection, new Listener() { - public void handleEvent(Event evt) { - IWorkbench iw = SecurityUiPlugin.getDefault().getWorkbench(); - IHandlerService handlerService = (IHandlerService) iw - .getService(IHandlerService.class); - try { - handlerService.executeCommand(AddRole.COMMAND_ID, evt); - } catch (Exception e) { - throw new ArgeoException("Cannot execute add role command", - e); - } - } - }); - // select all on focus - newRole.addListener(SWT.FocusIn, new Listener() { - public void handleEvent(Event e) { - newRole.selectAll(); - } - }); - - // roles table - Table table = new Table(parent, SWT.V_SCROLL | SWT.BORDER); - table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - table.setLinesVisible(false); - table.setHeaderVisible(false); - viewer = new TableViewer(table); - viewer.setContentProvider(new RolesContentProvider()); - viewer.setLabelProvider(new UsersLabelProvider()); - viewer.setInput(getViewSite()); - viewer.addDoubleClickListener(new ViewDoubleClickListener()); - } - - @Override - public void setFocus() { - viewer.getTable().setFocus(); - } - - public void setSecurityService(ArgeoSecurityService securityService) { - this.securityService = securityService; - } - - public String getAddNewRoleText() { - return addNewRoleText; - } - - private class RolesContentProvider implements IStructuredContentProvider { - - public Object[] getElements(Object inputElement) { - return securityService.listEditableRoles().toArray(); - } - - public void dispose() { - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - - } - - private class UsersLabelProvider extends LabelProvider implements - ITableLabelProvider { - public String getColumnText(Object element, int columnIndex) { - return element.toString(); - } - - public Image getColumnImage(Object element, int columnIndex) { - return null; - } - - } - - class ViewDoubleClickListener implements IDoubleClickListener { - public void doubleClick(DoubleClickEvent evt) { - Object obj = ((IStructuredSelection) evt.getSelection()) - .getFirstElement(); - - if (obj instanceof ArgeoUser) { - ArgeoUser argeoUser = (ArgeoUser) obj; - - IWorkbench iw = SecurityUiPlugin.getDefault().getWorkbench(); - IHandlerService handlerService = (IHandlerService) iw - .getService(IHandlerService.class); - try { - String commandId = OpenArgeoUserEditor.COMMAND_ID; - String paramName = OpenArgeoUserEditor.PARAM_USERNAME; - - // TODO: factorize this - // execute related command - IWorkbenchWindow window = iw.getActiveWorkbenchWindow(); - ICommandService cmdService = (ICommandService) window - .getService(ICommandService.class); - Command cmd = cmdService.getCommand(commandId); - ArrayList parameters = new ArrayList(); - IParameter iparam = cmd.getParameter(paramName); - Parameterization param = new Parameterization(iparam, - argeoUser.getUsername()); - parameters.add(param); - ParameterizedCommand pc = new ParameterizedCommand(cmd, - parameters.toArray(new Parameterization[parameters - .size()])); - handlerService = (IHandlerService) window - .getService(IHandlerService.class); - handlerService.executeCommand(pc, null); - } catch (Exception e) { - throw new ArgeoException("Cannot open editor", e); - } - - } - } - } - - public String getNewRole() { - return newRole.getText(); - } - - public void refresh() { - viewer.refresh(); - newRole.setText(addNewRoleText); - } -} diff --git a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/UsersView.java b/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/UsersView.java deleted file mode 100644 index 5d7817827..000000000 --- a/security/eclipse/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/UsersView.java +++ /dev/null @@ -1,174 +0,0 @@ -package org.argeo.security.ui.views; - -import java.util.ArrayList; - -import org.argeo.ArgeoException; -import org.argeo.security.ArgeoSecurityService; -import org.argeo.security.ArgeoUser; -import org.argeo.security.nature.SimpleUserNature; -import org.argeo.security.ui.CurrentUser; -import org.argeo.security.ui.SecurityUiPlugin; -import org.argeo.security.ui.commands.OpenArgeoUserEditor; -import org.eclipse.core.commands.Command; -import org.eclipse.core.commands.IParameter; -import org.eclipse.core.commands.Parameterization; -import org.eclipse.core.commands.ParameterizedCommand; -import org.eclipse.jface.viewers.DoubleClickEvent; -import org.eclipse.jface.viewers.IDoubleClickListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.commands.ICommandService; -import org.eclipse.ui.handlers.IHandlerService; -import org.eclipse.ui.part.ViewPart; - -/** List all users. */ -public class UsersView extends ViewPart { - public final static String ID = "org.argeo.security.ui.usersView"; - - private TableViewer viewer; - private ArgeoSecurityService securityService; - - private String simpleNatureType = null; - - @Override - public void createPartControl(Composite parent) { - viewer = new TableViewer(createTable(parent)); - viewer.setContentProvider(new UsersContentProvider()); - viewer.setLabelProvider(new UsersLabelProvider()); - viewer.addDoubleClickListener(new ViewDoubleClickListener()); - viewer.setInput(getViewSite()); - } - - protected Table createTable(Composite parent) { - Table table = new Table(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); - table.setLinesVisible(true); - table.setHeaderVisible(true); - TableColumn column = new TableColumn(table, SWT.LEFT, 0); - column.setText("User"); - column.setWidth(50); - column = new TableColumn(table, SWT.LEFT, 1); - column.setText("First Name"); - column.setWidth(100); - column = new TableColumn(table, SWT.LEFT, 2); - column.setText("Last Name"); - column.setWidth(100); - column = new TableColumn(table, SWT.LEFT, 3); - column.setText("E-mail"); - column.setWidth(100); - return table; - } - - @Override - public void setFocus() { - viewer.getTable().setFocus(); - } - - public void setSecurityService(ArgeoSecurityService securityService) { - this.securityService = securityService; - } - - public void setSimpleNatureType(String simpleNatureType) { - this.simpleNatureType = simpleNatureType; - } - - public void refresh() { - viewer.refresh(); - } - - private class UsersContentProvider implements IStructuredContentProvider { - - public Object[] getElements(Object inputElement) { - return securityService.listUsers().toArray(); - } - - public void dispose() { - } - - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - - } - - private class UsersLabelProvider extends LabelProvider implements - ITableLabelProvider { - public String getColumnText(Object element, int columnIndex) { - String currentUsername = CurrentUser.getUsername(); - ArgeoUser user = (ArgeoUser) element; - SimpleUserNature simpleNature = SimpleUserNature - .findSimpleUserNature(user, simpleNatureType); - switch (columnIndex) { - case 0: - String userName = user.getUsername(); - if (userName.equals(currentUsername)) - userName = userName + "*"; - return userName; - case 1: - return simpleNature.getFirstName(); - case 2: - return simpleNature.getLastName(); - case 3: - return simpleNature.getEmail(); - default: - throw new ArgeoException("Unmanaged column " + columnIndex); - } - } - - public Image getColumnImage(Object element, int columnIndex) { - // TODO Auto-generated method stub - return null; - } - - } - - class ViewDoubleClickListener implements IDoubleClickListener { - public void doubleClick(DoubleClickEvent evt) { - Object obj = ((IStructuredSelection) evt.getSelection()) - .getFirstElement(); - - if (obj instanceof ArgeoUser) { - ArgeoUser argeoUser = (ArgeoUser) obj; - - IWorkbench iw = SecurityUiPlugin.getDefault().getWorkbench(); - IHandlerService handlerService = (IHandlerService) iw - .getService(IHandlerService.class); - try { - String commandId = OpenArgeoUserEditor.COMMAND_ID; - String paramName = OpenArgeoUserEditor.PARAM_USERNAME; - - // TODO: factorize this - // execute related command - IWorkbenchWindow window = iw.getActiveWorkbenchWindow(); - ICommandService cmdService = (ICommandService) window - .getService(ICommandService.class); - Command cmd = cmdService.getCommand(commandId); - ArrayList parameters = new ArrayList(); - IParameter iparam = cmd.getParameter(paramName); - Parameterization param = new Parameterization(iparam, - argeoUser.getUsername()); - parameters.add(param); - ParameterizedCommand pc = new ParameterizedCommand(cmd, - parameters.toArray(new Parameterization[parameters - .size()])); - handlerService = (IHandlerService) window - .getService(IHandlerService.class); - handlerService.executeCommand(pc, null); - } catch (Exception e) { - throw new ArgeoException("Cannot open editor", e); - } - - } - } - } - -} diff --git a/security/eclipse/plugins/pom.xml b/security/eclipse/plugins/pom.xml deleted file mode 100644 index ab837feb5..000000000 --- a/security/eclipse/plugins/pom.xml +++ /dev/null @@ -1,89 +0,0 @@ - - 4.0.0 - - org.argeo.commons.security - 0.2.3-SNAPSHOT - eclipse - .. - - plugins - Commons Security Eclipse plugins - pom - - org.argeo.security.equinox - org.argeo.security.ui - org.argeo.security.ui.application - org.argeo.security.ui.rap - - - - - src/main/resources - - - . - - plugin.xml - META-INF/** - jaas/** - icons/** - - - - - - maven-clean-plugin - - - - META-INF - - MANIFEST.MF - - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - META-INF/MANIFEST.MF - - - - - org.apache.maven.plugins - maven-source-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - - - org.apache.felix - maven-bundle-plugin - - META-INF - - ${pom.artifactId};singleton:=true - - - - - - - - org.argeo.commons.osgi - org.argeo.osgi.boot - 0.2.3-SNAPSHOT - test - - - javax.xml.stream - com.springsource.javax.xml.stream - test - - - diff --git a/security/plugins/org.argeo.security.equinox/.classpath b/security/plugins/org.argeo.security.equinox/.classpath new file mode 100644 index 000000000..92f19d2ff --- /dev/null +++ b/security/plugins/org.argeo.security.equinox/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/security/plugins/org.argeo.security.equinox/.project b/security/plugins/org.argeo.security.equinox/.project new file mode 100644 index 000000000..e4dd594e8 --- /dev/null +++ b/security/plugins/org.argeo.security.equinox/.project @@ -0,0 +1,28 @@ + + + org.argeo.security.equinox + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/security/plugins/org.argeo.security.equinox/.settings/org.eclipse.jdt.core.prefs b/security/plugins/org.argeo.security.equinox/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..62fa6bd36 --- /dev/null +++ b/security/plugins/org.argeo.security.equinox/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Sun Jan 16 11:20:02 CET 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/security/plugins/org.argeo.security.equinox/.settings/org.eclipse.pde.core.prefs b/security/plugins/org.argeo.security.equinox/.settings/org.eclipse.pde.core.prefs new file mode 100644 index 000000000..87ab38102 --- /dev/null +++ b/security/plugins/org.argeo.security.equinox/.settings/org.eclipse.pde.core.prefs @@ -0,0 +1,4 @@ +#Sun Jan 16 11:19:07 CET 2011 +eclipse.preferences.version=1 +pluginProject.extensions=false +resolve.requirebundle=false diff --git a/security/plugins/org.argeo.security.equinox/META-INF/spring/loginModules.xml b/security/plugins/org.argeo.security.equinox/META-INF/spring/loginModules.xml new file mode 100644 index 000000000..f454d7a3a --- /dev/null +++ b/security/plugins/org.argeo.security.equinox/META-INF/spring/loginModules.xml @@ -0,0 +1,11 @@ + + + + + + + diff --git a/security/plugins/org.argeo.security.equinox/META-INF/spring/osgi.xml b/security/plugins/org.argeo.security.equinox/META-INF/spring/osgi.xml new file mode 100644 index 000000000..8003fb277 --- /dev/null +++ b/security/plugins/org.argeo.security.equinox/META-INF/spring/osgi.xml @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/security/plugins/org.argeo.security.equinox/build.properties b/security/plugins/org.argeo.security.equinox/build.properties new file mode 100644 index 000000000..3e2615fae --- /dev/null +++ b/security/plugins/org.argeo.security.equinox/build.properties @@ -0,0 +1,4 @@ +bin.includes = META-INF/,\ + plugin.xml +source.. = src/main/java/ +output.. = target/classes/ diff --git a/security/plugins/org.argeo.security.equinox/plugin.xml b/security/plugins/org.argeo.security.equinox/plugin.xml new file mode 100644 index 000000000..b407360ac --- /dev/null +++ b/security/plugins/org.argeo.security.equinox/plugin.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + name="Spring Login Module" + + + + + diff --git a/security/plugins/org.argeo.security.equinox/pom.xml b/security/plugins/org.argeo.security.equinox/pom.xml new file mode 100644 index 000000000..944a6e0df --- /dev/null +++ b/security/plugins/org.argeo.security.equinox/pom.xml @@ -0,0 +1,79 @@ + + 4.0.0 + + org.argeo.commons.security + 0.2.3-SNAPSHOT + plugins + .. + + org.argeo.security.equinox + Commons Security Equinox + jar + + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + org.apache.felix + maven-bundle-plugin + ${version.maven-bundle-plugin} + + + + + + + + + + + + + + + *, + org.springframework.core, + org.argeo.eclipse.spring + + + + + + + + + + + org.eclipse.osgi + org.eclipse.osgi + + + org.eclipse.equinox + org.eclipse.equinox.security + + + + + org.argeo.commons.basic + org.argeo.basic.nodeps + 0.2.3-SNAPSHOT + + + + + org.springframework.security + org.springframework.security.core + + + diff --git a/security/plugins/org.argeo.security.equinox/src/main/java/org/argeo/security/equinox/SpringLoginModule.java b/security/plugins/org.argeo.security.equinox/src/main/java/org/argeo/security/equinox/SpringLoginModule.java new file mode 100644 index 000000000..2222faecc --- /dev/null +++ b/security/plugins/org.argeo.security.equinox/src/main/java/org/argeo/security/equinox/SpringLoginModule.java @@ -0,0 +1,126 @@ +package org.argeo.security.equinox; + +import java.util.Map; + +import javax.security.auth.Subject; +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.NameCallback; +import javax.security.auth.callback.PasswordCallback; +import javax.security.auth.callback.TextOutputCallback; +import javax.security.auth.login.LoginException; + +import org.springframework.security.Authentication; +import org.springframework.security.AuthenticationManager; +import org.springframework.security.BadCredentialsException; +import org.springframework.security.context.SecurityContextHolder; +import org.springframework.security.providers.UsernamePasswordAuthenticationToken; +import org.springframework.security.providers.jaas.SecurityContextLoginModule; + +/** Login module which caches one subject per thread. */ +public class SpringLoginModule extends SecurityContextLoginModule { + private AuthenticationManager authenticationManager; + + private CallbackHandler callbackHandler; + + public SpringLoginModule() { + + } + + @SuppressWarnings("rawtypes") + public void initialize(Subject subject, CallbackHandler callbackHandler, + Map sharedState, Map options) { + super.initialize(subject, callbackHandler, sharedState, options); + // this.subject.set(subject); + this.callbackHandler = callbackHandler; + } + + public boolean login() throws LoginException { + // thread already logged in + if (SecurityContextHolder.getContext().getAuthentication() != null) + return super.login(); + + // if (getSubject().getPrincipals(Authentication.class).size() == 1) { + // registerAuthentication(getSubject() + // .getPrincipals(Authentication.class).iterator().next()); + // return super.login(); + // } else if (getSubject().getPrincipals(Authentication.class).size() > + // 1) { + // throw new LoginException( + // "Multiple Authentication principals not supported: " + // + getSubject().getPrincipals(Authentication.class)); + // } else { + // ask for username and password + Callback label = new TextOutputCallback(TextOutputCallback.INFORMATION, + "Required login"); + NameCallback nameCallback = new NameCallback("User"); + PasswordCallback passwordCallback = new PasswordCallback("Password", + false); + + if (callbackHandler == null) { + throw new LoginException("No call back handler available"); + // return false; + } + try { + callbackHandler.handle(new Callback[] { label, nameCallback, + passwordCallback }); + } catch (Exception e) { + LoginException le = new LoginException("Callback handling failed"); + le.initCause(e); + throw le; + } + + // Set user name and password + String username = nameCallback.getName(); + String password = ""; + if (passwordCallback.getPassword() != null) { + password = String.valueOf(passwordCallback.getPassword()); + } + UsernamePasswordAuthenticationToken credentials = new UsernamePasswordAuthenticationToken( + username, password); + + try { + Authentication authentication = authenticationManager + .authenticate(credentials); + registerAuthentication(authentication); + boolean res = super.login(); + // if (log.isDebugEnabled()) + // log.debug("User " + username + " logged in"); + return res; + } catch (BadCredentialsException bce) { + throw bce; + } catch (Exception e) { + LoginException loginException = new LoginException( + "Bad credentials"); + loginException.initCause(e); + throw loginException; + } + // } + } + + @Override + public boolean logout() throws LoginException { + return super.logout(); + } + + /** + * Register an {@link Authentication} in the security context. + * + * @param authentication + * has to implement {@link Authentication}. + */ + protected void registerAuthentication(Object authentication) { + SecurityContextHolder.getContext().setAuthentication( + (Authentication) authentication); + } + + public void setAuthenticationManager( + AuthenticationManager authenticationManager) { + this.authenticationManager = authenticationManager; + } + + // protected Subject getSubject() { + // return subject.get(); + // } + +} diff --git a/security/plugins/org.argeo.security.ui.application/.classpath b/security/plugins/org.argeo.security.ui.application/.classpath new file mode 100644 index 000000000..92f19d2ff --- /dev/null +++ b/security/plugins/org.argeo.security.ui.application/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/security/plugins/org.argeo.security.ui.application/.project b/security/plugins/org.argeo.security.ui.application/.project new file mode 100644 index 000000000..e83b5d5d9 --- /dev/null +++ b/security/plugins/org.argeo.security.ui.application/.project @@ -0,0 +1,28 @@ + + + org.argeo.security.ui.application + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/security/plugins/org.argeo.security.ui.application/.settings/org.eclipse.jdt.core.prefs b/security/plugins/org.argeo.security.ui.application/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..1f382cb9d --- /dev/null +++ b/security/plugins/org.argeo.security.ui.application/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Sat Jan 15 17:51:30 CET 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/security/plugins/org.argeo.security.ui.application/META-INF/jaas_default.txt b/security/plugins/org.argeo.security.ui.application/META-INF/jaas_default.txt new file mode 100644 index 000000000..b6cbaa655 --- /dev/null +++ b/security/plugins/org.argeo.security.ui.application/META-INF/jaas_default.txt @@ -0,0 +1,14 @@ +UNIX { + org.eclipse.equinox.security.auth.module.ExtensionLoginModule sufficient + extensionId="org.argeo.security.equinox.unixLoginModule"; +}; + +SPRING { + org.eclipse.equinox.security.auth.module.ExtensionLoginModule sufficient + extensionId="org.argeo.security.equinox.springLoginModule"; +}; + +SPRING_SECURITY_CONTEXT { + org.eclipse.equinox.security.auth.module.ExtensionLoginModule sufficient + extensionId="org.argeo.security.equinox.springSecurityContextLoginModule"; +}; \ No newline at end of file diff --git a/security/plugins/org.argeo.security.ui.application/argeo_security_rap.properties b/security/plugins/org.argeo.security.ui.application/argeo_security_rap.properties new file mode 100644 index 000000000..355774942 --- /dev/null +++ b/security/plugins/org.argeo.security.ui.application/argeo_security_rap.properties @@ -0,0 +1,24 @@ +argeo.osgi.start=\ +com.springsource.javax.servlet,\ +org.eclipse.core.runtime,\ +org.eclipse.equinox.common,\ +org.eclipse.equinox.http.jetty,\ +org.eclipse.equinox.http.registry,\ +org.eclipse.equinox.launcher,\ +org.eclipse.rap.demo,\ +org.mortbay.jetty.server,\ +org.springframework.osgi.extender,\ +org.argeo.server.ads.server,\ +org.argeo.security.manager.ldap,\ +org.argeo.security.services,\ +org.argeo.security.equinox,\ +org.argeo.security.ui,\ +org.argeo.security.ui.rcp,\ + +eclipse.ignoreApp=true +osgi.noShutdown=true + +log4j.configuration=file:../../log4j.properties + +org.eclipse.equinox.http.jetty.log.stderr.threshold=debug +org.osgi.service.http.port=9090 diff --git a/security/plugins/org.argeo.security.ui.application/build.properties b/security/plugins/org.argeo.security.ui.application/build.properties new file mode 100644 index 000000000..ac478ab24 --- /dev/null +++ b/security/plugins/org.argeo.security.ui.application/build.properties @@ -0,0 +1,7 @@ +source.. = src/main/java/ +output.. = target/classes/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + log4j.properties,\ + jaas_config.txt diff --git a/security/plugins/org.argeo.security.ui.application/icons/alt_about.gif b/security/plugins/org.argeo.security.ui.application/icons/alt_about.gif new file mode 100644 index 000000000..20d9ad2d9 Binary files /dev/null and b/security/plugins/org.argeo.security.ui.application/icons/alt_about.gif differ diff --git a/security/plugins/org.argeo.security.ui.application/icons/alt_launcher.icns b/security/plugins/org.argeo.security.ui.application/icons/alt_launcher.icns new file mode 100644 index 000000000..b77a6a639 Binary files /dev/null and b/security/plugins/org.argeo.security.ui.application/icons/alt_launcher.icns differ diff --git a/security/plugins/org.argeo.security.ui.application/icons/alt_launcher.ico b/security/plugins/org.argeo.security.ui.application/icons/alt_launcher.ico new file mode 100644 index 000000000..d548f7109 Binary files /dev/null and b/security/plugins/org.argeo.security.ui.application/icons/alt_launcher.ico differ diff --git a/security/plugins/org.argeo.security.ui.application/icons/alt_launcher.xpm b/security/plugins/org.argeo.security.ui.application/icons/alt_launcher.xpm new file mode 100644 index 000000000..b0c139e06 --- /dev/null +++ b/security/plugins/org.argeo.security.ui.application/icons/alt_launcher.xpm @@ -0,0 +1,307 @@ +/* XPM */ +static char * icon48_xpm[] = { +"48 48 256 2", +" c #4B4B3B3B9090", +". c #0D0D0E0E5454", +"X c #11110E0E5B5B", +"o c #17170F0F6363", +"O c #1D1D13136969", +"+ c #212114146C6C", +"@ c #252514147171", +"# c #282811116C6C", +"$ c #26260D0D6363", +"% c #22220B0B5E5E", +"& c #1C1C0B0B5A5A", +"* c #1C1C0B0B5252", +"= c #1B1B05055353", +"- c #161606064D4D", +"; c #161605054949", +": c #111104044848", +"> c #131304044545", +", c #131305054242", +"< c #141410105E5E", +"1 c #2C2C15157373", +"2 c #2B2B1B1B7575", +"3 c #343416167272", +"4 c #313113136E6E", +"5 c #222209095757", +"6 c #1B1B06064D4D", +"7 c #15150B0B4242", +"8 c #13130C0C5555", +"9 c #2E2E1B1B7878", +"0 c #33331F1F7C7C", +"q c #343418187878", +"w c #3B3B1C1C7575", +"e c #2E2E10106767", +"r c #1B1B07074747", +"t c #18180B0B4646", +"y c #151513136262", +"u c #1A1A15156464", +"i c #34341F1F7777", +"p c #40401E1E8080", +"a c #42421B1B7A7A", +"s c #3B3B15157474", +"d c #2B2B0B0B5B5B", +"f c #222207075252", +"g c #373727277A7A", +"h c #474724248484", +"j c #393915156E6E", +"k c #373711116A6A", +"l c #343413136363", +"z c #232319196E6E", +"x c #292919197070", +"c c #3C3C2C2C8282", +"v c #444431318585", +"b c #494934348A8A", +"n c #505026268A8A", +"m c #3D3D1B1B6E6E", +"M c #31310E0E5C5C", +"N c #2B2B0D0D5353", +"B c #222207074A4A", +"V c #52523C3C9292", +"C c #58583C3C9494", +"Z c #5D5D44449797", +"A c #5C5C2E2E9292", +"S c #676733339595", +"D c #424228287575", +"F c #29290A0A4F4F", +"G c #6C6C4A4A9E9E", +"H c #72725454A7A7", +"J c #8C8C6D6DB2B2", +"K c #343424246E6E", +"L c #3A3A23236A6A", +"P c #3A3A1C1C6767", +"I c #24240A0A4B4B", +"U c #151518186161", +"Y c #76766F6FA5A5", +"T c #ADAD9191CCCC", +"R c #98988989D3D3", +"E c #45453B3B8686", +"W c #3C3C35357979", +"Q c #363631317575", +"! c #32322D2D6B6B", +"~ c #323229296363", +"^ c #30301F1F6262", +"/ c #323218185E5E", +"( c #272707074B4B", +") c #202028286C6C", +"_ c #1E1E1D1D6868", +"` c #9A9A8282BBBB", +"' c #C8C8B3B3D3D3", +"] c #B3B3AFAFE7E7", +"[ c #84847272C6C6", +"{ c #58585757A3A3", +"} c #3F3F3C3C8A8A", +"| c #3B3B3A3A8484", +" . c #414139397D7D", +".. c #3D3D39397A7A", +"X. c #37372E2E6E6E", +"o. c #2C2C21215A5A", +"O. c #2E2E1B1B5B5B", +"+. c #F5F5EFEFF5F5", +"@. c #656566669A9A", +"#. c #47474B4B8E8E", +"$. c #3C3C44447B7B", +"%. c #444442428080", +"&. c #45453E3E8181", +"*. c #40403C3C8181", +"=. c #3D3D33337474", +"-. c #3B3B30306E6E", +";. c #38382D2D6969", +":. c #303026265D5D", +">. c #2C2C15155A5A", +",. c #1F1F1C1C7070", +"<. c #25251E1E7171", +"1. c #59595C5C9191", +"2. c #4D4D53538989", +"3. c #4C4C49498484", +"4. c #484845458585", +"5. c #494941418585", +"6. c #494940408181", +"7. c #2F2F1C1C5353", +"8. c #2B2B28287676", +"9. c #323231317F7F", +"0. c #545452528B8B", +"q. c #51514E4E8989", +"w. c #4E4E4B4B8C8C", +"e. c #4C4C47478686", +"r. c #46463D3D7E7E", +"t. c #434336367A7A", +"y. c #2B2B13135555", +"u. c #47473D3D8D8D", +"i. c #575757578E8E", +"p. c #48483E3E7F7F", +"a. c #46463A3A7D7D", +"s. c #424235357575", +"d. c #404034347171", +"f. c #BFBFCBCBFAFA", +"g. c #B8B8A8A8DDDD", +"h. c #5E5E60609292", +"j. c #565655558C8C", +"k. c #4B4B44448282", +"l. c #454539397B7B", +"z. c #434338387878", +"x. c #3F3F32326D6D", +"c. c #3D3D30306969", +"v. c #3A3A2E2E6363", +"b. c #36362A2A5C5C", +"n. c #343424245555", +"m. c #30301E1E4D4D", +"M. c #49493C3C8282", +"N. c #5E5E4F4F8C8C", +"B. c #56563B3B8B8B", +"V. c #545407078585", +"C. c #424234347272", +"Z. c #9797A4A4F7F7", +"A. c #444436367676", +"S. c #7D7D7979D5D5", +"D. c #464640408A8A", +"F. c #44444B4B8282", +"G. c #414107077777", +"H. c #71716161C1C1", +"J. c #303039397979", +"K. c #8E8E8E8EE6E6", +"L. c #404033338B8B", +"P. c #4A4A45458C8C", +"I. c #46463A3A8080", +"U. c #363629295454", +"Y. c #303022224848", +"T. c #424237377575", +"R. c #2E2E1D1D6363", +"E. c #79798383EAEA", +"W. c #74747B7BE4E4", +"Q. c #6D6D7676D6D6", +"!. c #6A6A7171CECE", +"~. c #66666969C6C6", +"^. c #62626565BCBC", +"/. c #5F5F6060B5B5", +"(. c #5B5B5B5BACAC", +"). c #535353539898", +"_. c #4F4F4F4FA4A4", +"`. c #54544D4DA4A4", +"'. c #323204046B6B", +"]. c #303035357979", +"[. c #313122224343", +"{. c #5A5A5B5BB7B7", +"}. c #484846468080", +"|. c #454541417575", +" X c #4B4B31318282", +".X c #47473C3C8484", +"XX c #3E3E35356E6E", +"oX c #2F2F26264040", +"OX c #2B2B23233A3A", +"+X c #262619195C5C", +"@X c #252515155A5A", +"#X c #55555151B3B3", +"$X c #3C3C2D2D5D5D", +"%X c #39392F2F5656", +"&X c #37372D2D5050", +"*X c #25251F1F3030", +"=X c #24241D1D4343", +"-X c #202013135656", +";X c #41413B3B6C6C", +":X c #444442429696", +">X c #212100005E5E", +",X c #444436367272", +" > , , , ", +" . . X X < < o o O O + @ 1 2 2 1 1 1 1 1 1 1 1 3 4 # # $ $ $ % % % 5 = = 6 6 - ; ; > > , , 7 ", +" . 8 < < < o O O + @ @ 2 9 9 0 0 q q q q q q q w 3 4 4 e e $ $ $ $ % 5 = = 6 6 6 ; ; > > r t ", +" . X < y u O O + @ 1 2 i 0 0 p p p p p p p a a p a s 3 4 4 e e e e d 5 5 f f 6 6 6 ; ; r r t ", +" X < y u O + + @ 2 9 0 g p p h h h h h h h p h h a a s s j k k j l d d 5 5 f f 6 6 r r r r r ", +" X < y O z x x 9 0 g c v b n n n n n n n n n n n h a a s s j j m l M d d N f f B B B B r r r ", +" < y u + z 2 0 c c b V C Z C C A A A A A S S S n h D w w m m m m k l M d d N f F F F B r r r ", +" < y O z z 9 c b V Z G H H H G S G G J J H V v c g g K K K K L P l l l M M N N N N I B B r r ", +" U u + z x i v C H Y J J J J H J T R H V E W W Q Q Q Q ! ! ! ~ ^ ^ / / M M M M M N ( B B r r ", +" ) _ z x 9 g b Z Y ` ' ' ' T T ] [ { } | .........W W Q Q X.! ~ ~ o.O./ / / / N F ( B B B r ", +" ) ) z x i c V G J ' +.+.+.+.] [ @.#.$.%.%.%.&.*. . .....W =.-.X.;.~ :.o.O.^ >.N F ( B B B B ", +" ) ,.<.2 g v C H J ' +.+.+.+.T Y 1.2.3.4.4.4.5.6.&.&. . ...W =.=.-.;.~ :.o.7.>.N F F ( B I I ", +" ) ,.<.8.9.b C H J T +.+.+.' J @.1.0.q.q.w.e.4.5.6.&.r. . .t.W =.=.-.;.~ :.o.7.y.N F ( ( I I ", +" 8.8.8.9.| u.C G J T +.+.' ` Y @.1.i.0.q.q.e.e.5.6.p.r.a. .t.t.s.d.d.-.;.~ :.7.7.y.F F ( I I ", +" 9.c c c v b A S H ' f.g.` Y @.h.1.i.j.0.q.q.e.k.6.p.r.a.l.t.z.s.s.d.x.c.v.b.n.m.7.N F F F I ", +" <.g M.N.B.B.n V.J f.R J @.h.h.1.i.i.j.j.0.q.3.k.6.p.r.a.l.l.z.s.C.d.x.x.c.v.b.n.m.y.N F F F ", +" + x i v B.Z Z G g.Z.[ @.2.i.i.j.j.j.j.j.0.q.3.k.6.p.p.a.l.l.A.s.C.C.d.x.c.v.b.n.m.7.y.N N y. ", +" O # 3 w p n Z ` f.S.H D.F.q.0.0.0.0.j.0.q.q.3.k.6.p.r.a.a.l.A.s.s.C.d.x.x.c.v.b.n.m.y.y.y.y. ", +" O # 4 s a G.V.T Z.H.V J.%.e.w.q.0.0.0.0.q.q.e.k.6.p.r.a.a.l.z.A.s.C.d.d.x.c.v.b.n.m.7.>.y.y. ", +" O # 4 s w G.A f.K.H L...4.P.w.w.w.q.q.q.q.e.e.5.6.M.I.I.a.a.l.z.A.s.d.d.x.c.v.v.U.Y.7.O.>.y. ", +" $ # 4 3 s G.G f.S.Z 9.*.D.P.P.w.w.w.w.w.e.e.5.5.M.M.I.I.a.a.l.z.T.s.d.d.x.x.c.v.U.Y.m.R.>.>. ", +" E.E.W.W.W.W.E.Z.E.W.Q.Q.Q.Q.Q.Q.Q.Q.Q.Q.!.!.!.!.!.~.~.~.~.~.~.^.^.^.^.^./././.(.{ { )._.`._. ", +" + # 3 w s '.` f.H.V ].*.D.P.P.P.P.P.P.P.5.5.5.M.M.M.I.I.a.l.z.z.T.T.s.d.d.x.c.v.U.Y.[.^ O.>. ", +" ~.~.~.~.~.~.K.Z.S.~.{.^.^.^.^.^.^.^.^././././././.(.(.(.(.(.(.{ { { { { ).).).w.w.}.|.P.u.} ", +" .I.6. X X XT f.H.b ].*.E D.D.D.D.5.5..X.XM.M.I.I.a.a.l.l.z.z.T.T.T.d.XXx.c.v.b.U.oXOXR.+X@X ", +" E.E.E.W.W.W.K.Z.E.W.Q.Q.Q.Q.Q.Q.Q.Q.!.!.!.!.!.!.~.~.~.~.~.~.^.^.^.^.^./././.(.{ { ).).#X_._. ", +" & % $ e '.= H f.H.b 8.W *.E E E .X.X.XI.I.I.I.a.a.l.l.z.z.T.T.T.C.XXXXc.v.$X%X&XY.*X=X2 @X-X ", +" {.{.{.{.{.#X~.Z.W.~.{.{./././././././././.(.(.(.(.(.(.(.{ { { { { { ).).).w.w.3.}.;X%.:X} } ", +" & & % $ e >XV.f.S.C K X.W t. . .l.l.t.t.t.t.A.A.A.,X,X,X,X,XX7X` Z.Z D ! =.=.s.t.t.t.A.A.s.A.,X,X,X,X > > t t t cX ", +" nXbXbXzXzXlXaXXXY +Xf = f = 7XtXR R mXn.Y.[.[.[.[.OX*X*X8X5X*X=X,.u vXvX; > > MXMX, 7 t t ", +" nXnXnXbXzXvX-.Y +XcX6 6 = = = d L B.G H `.X.:.7.m.=X=X=X=X=X6X,.u cXvXNX: BX> MXVXCXVX7 7 7 ", +" ZXZXnXbXAXgX@.+XvX; - - - - * @XR.>.sX>.R.i 0 x eXeXeXeXO hXaXcXvXNX: BXMXMXMXVXCXCXCXVX7 7 ", +" SXZXZXAXgXN.aXNX: : NXNXNX- * +X+X* 6 6 6 * * * * * * * vXvX- NX: DXBXMXMXFXCXCXCXCXGXVXVX7 ", +" SXSXHXgX0.JXKXLXKXKXDX: : NX* @X-X- - - - - - - - - - - NX: DXDXDXMXMXFXFXCXCXCXCXGXGXGXVXVX ", +" SXHXPX3.JXnXnXnXnXbXLXKXKXNXaX-XvX: : NX: : : : : : : BXDXDXLXMXMXFXFXCXCXCXCXGXGXGXGXGXGXGX ", +" IXUX$.AXZXZXZXZXnXnXnXLXLXNXJXvXBXDXBXBXBXBXDXDXDXDXLXDXLXLXFXFXFXFXCXCXCXCXGXGXGXGXGXGXGXGX ", +" "}; diff --git a/security/plugins/org.argeo.security.ui.application/icons/alt_window_16.gif b/security/plugins/org.argeo.security.ui.application/icons/alt_window_16.gif new file mode 100644 index 000000000..05626b17d Binary files /dev/null and b/security/plugins/org.argeo.security.ui.application/icons/alt_window_16.gif differ diff --git a/security/plugins/org.argeo.security.ui.application/icons/alt_window_32.gif b/security/plugins/org.argeo.security.ui.application/icons/alt_window_32.gif new file mode 100644 index 000000000..b432f8833 Binary files /dev/null and b/security/plugins/org.argeo.security.ui.application/icons/alt_window_32.gif differ diff --git a/security/plugins/org.argeo.security.ui.application/log4j.properties b/security/plugins/org.argeo.security.ui.application/log4j.properties new file mode 100644 index 000000000..8a89a4aa3 --- /dev/null +++ b/security/plugins/org.argeo.security.ui.application/log4j.properties @@ -0,0 +1,24 @@ +log4j.rootLogger=WARN, console + +## Levels +log4j.logger.org.argeo=DEBUG +log4j.logger.org.springframework.security=DEBUG + +log4j.logger.org.apache.catalina=INFO +log4j.logger.org.apache.coyote=INFO +log4j.logger.org.apache.tomcat=INFO + +log4j.logger.org.apache.directory.server=INFO +log4j.logger.org.apache.directory.server.core.partition=ERROR +log4j.logger.org.apache.directory.server.core.schema.bootstrap.BootstrapAttributeTypeRegistry=ERROR + +log4j.logger.org.apache.jackrabbit=WARN +log4j.logger.org.apache.jackrabbit.core.query.lucene=ERROR + +## Appenders +# console is set to be a ConsoleAppender. +log4j.appender.console=org.apache.log4j.ConsoleAppender + +# console uses PatternLayout. +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern= %-5p %d{ISO8601} %m - %c - [%t]%n diff --git a/security/plugins/org.argeo.security.ui.application/org.argeo.security.ui.application.product b/security/plugins/org.argeo.security.ui.application/org.argeo.security.ui.application.product new file mode 100644 index 000000000..be468c8ae --- /dev/null +++ b/security/plugins/org.argeo.security.ui.application/org.argeo.security.ui.application.product @@ -0,0 +1,119 @@ + + + + + + + + + + -console -clean + -Dlog4j.configuration=file:${system_property:user.home}/dev/src/commons/security/eclipse/plugins/org.argeo.security.ui.application/log4j.properties + -XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/security/plugins/org.argeo.security.ui.application/plugin.xml b/security/plugins/org.argeo.security.ui.application/plugin.xml new file mode 100644 index 000000000..654141626 --- /dev/null +++ b/security/plugins/org.argeo.security.ui.application/plugin.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/security/plugins/org.argeo.security.ui.application/plugin_customization.ini b/security/plugins/org.argeo.security.ui.application/plugin_customization.ini new file mode 100644 index 000000000..baf9cefe7 --- /dev/null +++ b/security/plugins/org.argeo.security.ui.application/plugin_customization.ini @@ -0,0 +1,5 @@ +org.eclipse.ui/DOCK_PERSPECTIVE_BAR=topRight +org.eclipse.ui/SHOW_TEXT_ON_PERSPECTIVE_BAR=true +org.eclipse.ui/PERSPECTIVE_BAR_SIZE=100 +org.eclipse.ui/SHOW_TRADITIONAL_STYLE_TABS=true +org.eclipse.ui/SHOW_PROGRESS_ON_STARTUP = false diff --git a/security/plugins/org.argeo.security.ui.application/pom.xml b/security/plugins/org.argeo.security.ui.application/pom.xml new file mode 100644 index 000000000..e66484841 --- /dev/null +++ b/security/plugins/org.argeo.security.ui.application/pom.xml @@ -0,0 +1,120 @@ + + 4.0.0 + + org.argeo.commons.security + 0.2.3-SNAPSHOT + plugins + .. + + org.argeo.security.ui.application + Commons Security UI Application + jar + + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + org.apache.felix + maven-bundle-plugin + ${version.maven-bundle-plugin} + + + org.argeo.security.ui.application.SecureApplicationActivator + lazy + org.eclipse.ui;resolution:=optional,org.eclipse.rap.ui;resolution:=optional,org.eclipse.core.runtime + * + + + + + org.argeo.maven.plugins + maven-argeo-osgi-plugin + + + resolve-pde-sources + + pde-sources + + generate-resources + + + generate-descriptors + + descriptors + + generate-resources + + + check-osgi + test + + equinox + + + true + + -clean + + + + + + + + + + + org.argeo.commons.security + org.argeo.security.ui + 0.2.3-SNAPSHOT + + + org.argeo.commons.security + org.argeo.security.equinox + 0.2.3-SNAPSHOT + + + + + org.argeo.commons.eclipse + org.argeo.eclipse.dep.rcp + 0.2.3-SNAPSHOT + provided + + + + + org.argeo.commons.basic + org.argeo.basic.nodeps + 0.2.3-SNAPSHOT + + + + + + org.slf4j + com.springsource.slf4j.org.apache.commons.logging + + + + + + org.argeo.commons.security + org.argeo.security.dep.ads + ${version.argeo-commons} + pom + test + + + diff --git a/security/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/AbstractSecureApplication.java b/security/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/AbstractSecureApplication.java new file mode 100644 index 000000000..a0a2f922b --- /dev/null +++ b/security/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/AbstractSecureApplication.java @@ -0,0 +1,117 @@ +package org.argeo.security.ui.application; + +import java.security.PrivilegedAction; + +import javax.security.auth.Subject; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.equinox.app.IApplication; +import org.eclipse.equinox.app.IApplicationContext; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.application.WorkbenchAdvisor; + +public abstract class AbstractSecureApplication implements IApplication { + private static final Log log = LogFactory + .getLog(AbstractSecureApplication.class); + + protected abstract WorkbenchAdvisor createWorkbenchAdvisor(); + + @SuppressWarnings("unchecked") + public Object start(IApplicationContext context) throws Exception { + + Integer returnCode = null; + Display display = PlatformUI.createDisplay(); + + // Force login + + try { + String username = null; + Exception loginException = null; + Subject subject = null; + try { + SecureApplicationActivator.getLoginContext().login(); + subject = SecureApplicationActivator.getLoginContext() + .getSubject(); + + // username = CurrentUser.getUsername(); + } catch (Exception e) { + loginException = e; + e.printStackTrace(); + } + if (subject == null) { + IStatus status = new Status(IStatus.ERROR, + "org.argeo.security.application", "Login is mandatory", + loginException); + ErrorDialog.openError(null, "Error", "Shutdown...", status); + return status.getSeverity(); + } + if (log.isDebugEnabled()) + log.debug("Logged in as " + username); + returnCode = (Integer) Subject.doAs(subject, getRunAction(display)); + SecureApplicationActivator.getLoginContext().logout(); + return processReturnCode(returnCode); + } catch (Exception e) { + // e.printStackTrace(); + IStatus status = new Status(IStatus.ERROR, + "org.argeo.security.rcp", "Login failed", e); + ErrorDialog.openError(null, "Error", "Shutdown...", status); + return returnCode; + } finally { + display.dispose(); + } + } + + protected Integer processReturnCode(Integer returnCode) { + return returnCode; + } + + @SuppressWarnings("rawtypes") + private PrivilegedAction getRunAction(final Display display) { + return new PrivilegedAction() { + + public Object run() { + int result = createAndRunWorkbench(display); + return new Integer(result); + } + }; + } + + protected Integer createAndRunWorkbench(Display display) { + return PlatformUI.createAndRunWorkbench(display, + createWorkbenchAdvisor()); + } + + public void stop() { + final IWorkbench workbench; + try { + workbench = PlatformUI.getWorkbench(); + } catch (Exception e) { + return; + } + if (workbench == null) + return; + final Display display = workbench.getDisplay(); + if (display != null && !display.isDisposed()) + display.syncExec(new Runnable() { + + public void run() { + if (!display.isDisposed()) + workbench.close(); + } + }); + + if (log.isDebugEnabled()) + log.debug("workbench stopped"); + // String username = CurrentUser.getUsername(); + // if (log.isDebugEnabled()) + // log.debug("workbench stopped, logged in as " + username); + + } + +} diff --git a/security/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/RapSecureWorkbenchWindowAdvisor.java b/security/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/RapSecureWorkbenchWindowAdvisor.java new file mode 100644 index 000000000..fb4911a08 --- /dev/null +++ b/security/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/RapSecureWorkbenchWindowAdvisor.java @@ -0,0 +1,37 @@ +package org.argeo.security.ui.application; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.application.ActionBarAdvisor; +import org.eclipse.ui.application.IActionBarConfigurer; +import org.eclipse.ui.application.IWorkbenchWindowConfigurer; + +public class RapSecureWorkbenchWindowAdvisor extends + SecureWorkbenchWindowAdvisor { + public RapSecureWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) { + super(configurer); + } + + @Override + public ActionBarAdvisor createActionBarAdvisor( + IActionBarConfigurer configurer) { + return new SecureActionBarAdvisor(configurer, false); + } + + public void preWindowOpen() { + IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); + configurer.setShowCoolBar(true); + configurer.setShowMenuBar(true); + configurer.setShowStatusLine(false); + configurer.setShowPerspectiveBar(true); + configurer.setTitle("Argeo Secure UI"); //$NON-NLS-1$ + // Full screen, see + // http://dev.eclipse.org/newslists/news.eclipse.technology.rap/msg02697.html + configurer.setShellStyle(SWT.NONE); + Rectangle bounds = Display.getDefault().getBounds(); + configurer.setInitialSize(new Point(bounds.width, bounds.height)); + } + +} diff --git a/security/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureActionBarAdvisor.java b/security/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureActionBarAdvisor.java new file mode 100644 index 000000000..61a3c0407 --- /dev/null +++ b/security/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureActionBarAdvisor.java @@ -0,0 +1,94 @@ +package org.argeo.security.ui.application; + +import org.eclipse.jface.action.GroupMarker; +import org.eclipse.jface.action.ICoolBarManager; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.action.ToolBarManager; +import org.eclipse.swt.SWT; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.actions.ActionFactory; +import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction; +import org.eclipse.ui.application.ActionBarAdvisor; +import org.eclipse.ui.application.IActionBarConfigurer; + +public class SecureActionBarAdvisor extends ActionBarAdvisor { + private IWorkbenchAction exitAction; + private IWorkbenchAction openPerspectiveDialogAction; + private IWorkbenchAction showViewMenuAction; + private IWorkbenchAction preferences; + private IWorkbenchAction saveAction; + private IWorkbenchAction saveAllAction; + private IWorkbenchAction closeAllAction; + + // private final Boolean isRcp; + + public SecureActionBarAdvisor(IActionBarConfigurer configurer, Boolean isRcp) { + super(configurer); + // this.isRcp = isRcp; + } + + protected void makeActions(IWorkbenchWindow window) { + preferences = ActionFactory.PREFERENCES.create(window); + register(preferences); + openPerspectiveDialogAction = ActionFactory.OPEN_PERSPECTIVE_DIALOG + .create(window); + register(openPerspectiveDialogAction); + showViewMenuAction = ActionFactory.SHOW_VIEW_MENU.create(window); + register(showViewMenuAction); + + exitAction = ActionFactory.QUIT.create(window); + register(exitAction); + + // Save semantiocs + saveAction = ActionFactory.SAVE.create(window); + register(saveAction); + saveAllAction = ActionFactory.SAVE_ALL.create(window); + register(saveAllAction); + closeAllAction = ActionFactory.CLOSE_ALL.create(window); + register(closeAllAction); + + } + + protected void fillMenuBar(IMenuManager menuBar) { + MenuManager fileMenu = new MenuManager("&File", + IWorkbenchActionConstants.M_FILE); + MenuManager editMenu = new MenuManager("&Edit", + IWorkbenchActionConstants.M_EDIT); + MenuManager windowMenu = new MenuManager("&Window", + IWorkbenchActionConstants.M_WINDOW); + + menuBar.add(fileMenu); + menuBar.add(editMenu); + menuBar.add(windowMenu); + // Add a group marker indicating where action set menus will appear. + menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); + + // File + fileMenu.add(saveAction); + fileMenu.add(saveAllAction); + fileMenu.add(closeAllAction); + fileMenu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); + fileMenu.add(new Separator()); + fileMenu.add(exitAction); + + // Edit + editMenu.add(preferences); + + // Window + windowMenu.add(openPerspectiveDialogAction); + windowMenu.add(showViewMenuAction); + } + + @Override + protected void fillCoolBar(ICoolBarManager coolBar) { + IToolBarManager saveToolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT); + saveToolbar.add(saveAction); + saveToolbar.add(saveAllAction); + coolBar.add(saveToolbar); + } + +} diff --git a/security/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureApplicationActivator.java b/security/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureApplicationActivator.java new file mode 100644 index 000000000..ec5d625de --- /dev/null +++ b/security/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureApplicationActivator.java @@ -0,0 +1,29 @@ +package org.argeo.security.ui.application; + +import java.net.URL; + +import org.eclipse.equinox.security.auth.ILoginContext; +import org.eclipse.equinox.security.auth.LoginContextFactory; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class SecureApplicationActivator implements BundleActivator { + + public final static String CONTEXT_SPRING = "SPRING"; + private static final String JAAS_CONFIG_FILE = "/META-INF/jaas_default.txt"; + + private static ILoginContext loginContext = null; + + public void start(BundleContext bundleContext) throws Exception { + URL configUrl = bundleContext.getBundle().getEntry(JAAS_CONFIG_FILE); + loginContext = LoginContextFactory.createContext(CONTEXT_SPRING, + configUrl); + } + + public void stop(BundleContext context) throws Exception { + } + + static ILoginContext getLoginContext() { + return loginContext; + } +} diff --git a/security/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureRap.java b/security/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureRap.java new file mode 100644 index 000000000..5f2ea3edc --- /dev/null +++ b/security/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureRap.java @@ -0,0 +1,38 @@ +package org.argeo.security.ui.application; + +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.application.IWorkbenchWindowConfigurer; +import org.eclipse.ui.application.WorkbenchAdvisor; +import org.eclipse.ui.application.WorkbenchWindowAdvisor; + +/** Generic secure application for RAP. */ +public class SecureRap extends AbstractSecureApplication { + + @Override + protected WorkbenchAdvisor createWorkbenchAdvisor() { + return new SecureWorkbenchAdvisor() { + public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor( + IWorkbenchWindowConfigurer configurer) { + return new RapSecureWorkbenchWindowAdvisor(configurer); + } + + }; + } + + public void stop() { + final IWorkbench workbench = PlatformUI.getWorkbench(); + if (workbench == null) + return; + final Display display = workbench.getDisplay(); + display.syncExec(new Runnable() { + + public void run() { + if (!display.isDisposed()) + workbench.close(); + } + }); + } + +} diff --git a/security/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureRcp.java b/security/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureRcp.java new file mode 100644 index 000000000..b8576c4b9 --- /dev/null +++ b/security/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureRcp.java @@ -0,0 +1,21 @@ +package org.argeo.security.ui.application; + +import org.eclipse.equinox.app.IApplication; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.application.WorkbenchAdvisor; + +public class SecureRcp extends AbstractSecureApplication { + + @Override + protected WorkbenchAdvisor createWorkbenchAdvisor() { + return new SecureWorkbenchAdvisor(); + } + + protected Integer processReturnCode(Integer returnCode) { + if (returnCode == PlatformUI.RETURN_RESTART) + return IApplication.EXIT_RESTART; + else + return IApplication.EXIT_OK; + } + +} diff --git a/security/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureWorkbenchAdvisor.java b/security/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureWorkbenchAdvisor.java new file mode 100644 index 000000000..417981664 --- /dev/null +++ b/security/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureWorkbenchAdvisor.java @@ -0,0 +1,23 @@ +package org.argeo.security.ui.application; + +import org.eclipse.ui.application.IWorkbenchWindowConfigurer; +import org.eclipse.ui.application.WorkbenchAdvisor; +import org.eclipse.ui.application.WorkbenchWindowAdvisor; + +public class SecureWorkbenchAdvisor extends WorkbenchAdvisor { + + static final String DEFAULT_PERSPECTIVE_ID = "org.argeo.security.ui.securityPerspective"; //$NON-NLS-1$ + + public final static String INITIAL_PERSPECTIVE_PROPERTY = "org.argeo.security.ui.initialPerspective"; + private String initialPerspective = System.getProperty( + INITIAL_PERSPECTIVE_PROPERTY, DEFAULT_PERSPECTIVE_ID); + + public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor( + IWorkbenchWindowConfigurer configurer) { + return new SecureWorkbenchWindowAdvisor(configurer); + } + + public String getInitialWindowPerspectiveId() { + return initialPerspective; + } +} diff --git a/security/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureWorkbenchWindowAdvisor.java b/security/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureWorkbenchWindowAdvisor.java new file mode 100644 index 000000000..1eb5c6787 --- /dev/null +++ b/security/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/SecureWorkbenchWindowAdvisor.java @@ -0,0 +1,32 @@ +package org.argeo.security.ui.application; + +import org.eclipse.swt.graphics.Point; +import org.eclipse.ui.application.ActionBarAdvisor; +import org.eclipse.ui.application.IActionBarConfigurer; +import org.eclipse.ui.application.IWorkbenchWindowConfigurer; +import org.eclipse.ui.application.WorkbenchWindowAdvisor; + +public class SecureWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { + + public SecureWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) { + super(configurer); + } + + public ActionBarAdvisor createActionBarAdvisor( + IActionBarConfigurer configurer) { + return new SecureActionBarAdvisor(configurer, true); + } + + public void preWindowOpen() { + IWorkbenchWindowConfigurer configurer = getWindowConfigurer(); + configurer.setInitialSize(new Point(1200, 900)); + configurer.setShowCoolBar(true); + configurer.setShowMenuBar(true); + configurer.setShowStatusLine(false); + + configurer.setShowPerspectiveBar(true); + configurer.setTitle("Argeo Secure UI"); //$NON-NLS-1$ + + } + +} diff --git a/security/plugins/org.argeo.security.ui.rap/pom.xml b/security/plugins/org.argeo.security.ui.rap/pom.xml new file mode 100644 index 000000000..764c63f1c --- /dev/null +++ b/security/plugins/org.argeo.security.ui.rap/pom.xml @@ -0,0 +1,132 @@ + + 4.0.0 + + org.argeo.commons.security + 0.2.3-SNAPSHOT + plugins + .. + + org.argeo.security.ui.rap + Commons Security UI RAP + jar + + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + org.argeo.maven.plugins + maven-argeo-osgi-plugin + + + resolve-pde-sources + + pde-sources + + generate-resources + + + generate-descriptors + + descriptors + + generate-resources + + + check-osgi + test + + equinox + + + true + + -clean + + + + + + + + + + org.argeo.commons.security + org.argeo.security.ui.application + 0.2.3-SNAPSHOT + + + org.argeo.commons.eclipse + org.argeo.eclipse.dep.rcp + + + + + + org.argeo.commons.eclipse + org.argeo.eclipse.dep.rap + 0.2.3-SNAPSHOT + + + + + + + org.argeo.commons.server + org.argeo.server.ads.server + ${version.argeo-commons} + test + + + org.argeo.commons.security + org.argeo.security.services + ${version.argeo-commons} + test + + + org.argeo.commons.security + org.argeo.security.ldap + ${version.argeo-commons} + test + + + org.argeo.commons.security + org.argeo.security.manager.ldap + ${version.argeo-commons} + test + + + org.argeo.commons.server + org.argeo.server.ads + 0.2.3-SNAPSHOT + test + + + org.argeo.dep.osgi + org.argeo.dep.osgi.springframework.ldap + test + + + org.argeo.commons.basic + org.argeo.basic.dep.log4j + 0.2.3-SNAPSHOT + pom + test + + + net.sourceforge.jdbm + com.springsource.jdbm + test + + + diff --git a/security/plugins/org.argeo.security.ui/.classpath b/security/plugins/org.argeo.security.ui/.classpath new file mode 100644 index 000000000..92f19d2ff --- /dev/null +++ b/security/plugins/org.argeo.security.ui/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/security/plugins/org.argeo.security.ui/.project b/security/plugins/org.argeo.security.ui/.project new file mode 100644 index 000000000..a052e9a57 --- /dev/null +++ b/security/plugins/org.argeo.security.ui/.project @@ -0,0 +1,28 @@ + + + org.argeo.security.ui + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/security/plugins/org.argeo.security.ui/.settings/org.eclipse.jdt.core.prefs b/security/plugins/org.argeo.security.ui/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..aef0f5291 --- /dev/null +++ b/security/plugins/org.argeo.security.ui/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Sat Jan 15 13:25:02 CET 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/security/plugins/org.argeo.security.ui/.settings/org.eclipse.pde.core.prefs b/security/plugins/org.argeo.security.ui/.settings/org.eclipse.pde.core.prefs new file mode 100644 index 000000000..dfa507d81 --- /dev/null +++ b/security/plugins/org.argeo.security.ui/.settings/org.eclipse.pde.core.prefs @@ -0,0 +1,3 @@ +#Sat Jan 15 18:15:48 CET 2011 +eclipse.preferences.version=1 +resolve.requirebundle=false diff --git a/security/plugins/org.argeo.security.ui/META-INF/spring/commands.xml b/security/plugins/org.argeo.security.ui/META-INF/spring/commands.xml new file mode 100644 index 000000000..a89876ad1 --- /dev/null +++ b/security/plugins/org.argeo.security.ui/META-INF/spring/commands.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + diff --git a/security/plugins/org.argeo.security.ui/META-INF/spring/editors.xml b/security/plugins/org.argeo.security.ui/META-INF/spring/editors.xml new file mode 100644 index 000000000..747c2b7b6 --- /dev/null +++ b/security/plugins/org.argeo.security.ui/META-INF/spring/editors.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/security/plugins/org.argeo.security.ui/META-INF/spring/osgi.xml b/security/plugins/org.argeo.security.ui/META-INF/spring/osgi.xml new file mode 100644 index 000000000..6574cf125 --- /dev/null +++ b/security/plugins/org.argeo.security.ui/META-INF/spring/osgi.xml @@ -0,0 +1,12 @@ + + + + + \ No newline at end of file diff --git a/security/plugins/org.argeo.security.ui/META-INF/spring/views.xml b/security/plugins/org.argeo.security.ui/META-INF/spring/views.xml new file mode 100644 index 000000000..7ae3b62e3 --- /dev/null +++ b/security/plugins/org.argeo.security.ui/META-INF/spring/views.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + diff --git a/security/plugins/org.argeo.security.ui/build.properties b/security/plugins/org.argeo.security.ui/build.properties new file mode 100644 index 000000000..3868784bf --- /dev/null +++ b/security/plugins/org.argeo.security.ui/build.properties @@ -0,0 +1,6 @@ +source.. = src/main/java/ +output.. = target/classes/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + icons/ diff --git a/security/plugins/org.argeo.security.ui/icons/add.gif b/security/plugins/org.argeo.security.ui/icons/add.gif new file mode 100644 index 000000000..252d7ebcb Binary files /dev/null and b/security/plugins/org.argeo.security.ui/icons/add.gif differ diff --git a/security/plugins/org.argeo.security.ui/icons/password.gif b/security/plugins/org.argeo.security.ui/icons/password.gif new file mode 100644 index 000000000..a6b251fc8 Binary files /dev/null and b/security/plugins/org.argeo.security.ui/icons/password.gif differ diff --git a/security/plugins/org.argeo.security.ui/icons/refresh.png b/security/plugins/org.argeo.security.ui/icons/refresh.png new file mode 100644 index 000000000..a3884fb48 Binary files /dev/null and b/security/plugins/org.argeo.security.ui/icons/refresh.png differ diff --git a/security/plugins/org.argeo.security.ui/icons/remove.gif b/security/plugins/org.argeo.security.ui/icons/remove.gif new file mode 100644 index 000000000..0ae6decd0 Binary files /dev/null and b/security/plugins/org.argeo.security.ui/icons/remove.gif differ diff --git a/security/plugins/org.argeo.security.ui/icons/role.gif b/security/plugins/org.argeo.security.ui/icons/role.gif new file mode 100644 index 000000000..274a850e4 Binary files /dev/null and b/security/plugins/org.argeo.security.ui/icons/role.gif differ diff --git a/security/plugins/org.argeo.security.ui/icons/save.gif b/security/plugins/org.argeo.security.ui/icons/save.gif new file mode 100644 index 000000000..654ad7b42 Binary files /dev/null and b/security/plugins/org.argeo.security.ui/icons/save.gif differ diff --git a/security/plugins/org.argeo.security.ui/icons/save_security.png b/security/plugins/org.argeo.security.ui/icons/save_security.png new file mode 100644 index 000000000..ca41dc92b Binary files /dev/null and b/security/plugins/org.argeo.security.ui/icons/save_security.png differ diff --git a/security/plugins/org.argeo.security.ui/icons/save_security_disabled.png b/security/plugins/org.argeo.security.ui/icons/save_security_disabled.png new file mode 100644 index 000000000..fb7d08d9a Binary files /dev/null and b/security/plugins/org.argeo.security.ui/icons/save_security_disabled.png differ diff --git a/security/plugins/org.argeo.security.ui/icons/security.gif b/security/plugins/org.argeo.security.ui/icons/security.gif new file mode 100644 index 000000000..57fb95edc Binary files /dev/null and b/security/plugins/org.argeo.security.ui/icons/security.gif differ diff --git a/security/plugins/org.argeo.security.ui/icons/user.gif b/security/plugins/org.argeo.security.ui/icons/user.gif new file mode 100644 index 000000000..90a00147b Binary files /dev/null and b/security/plugins/org.argeo.security.ui/icons/user.gif differ diff --git a/security/plugins/org.argeo.security.ui/icons/users.gif b/security/plugins/org.argeo.security.ui/icons/users.gif new file mode 100644 index 000000000..2de7edd64 Binary files /dev/null and b/security/plugins/org.argeo.security.ui/icons/users.gif differ diff --git a/security/plugins/org.argeo.security.ui/plugin.xml b/security/plugins/org.argeo.security.ui/plugin.xml new file mode 100644 index 000000000..3a741cb09 --- /dev/null +++ b/security/plugins/org.argeo.security.ui/plugin.xml @@ -0,0 +1,160 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/security/plugins/org.argeo.security.ui/pom.xml b/security/plugins/org.argeo.security.ui/pom.xml new file mode 100644 index 000000000..0d9ed3165 --- /dev/null +++ b/security/plugins/org.argeo.security.ui/pom.xml @@ -0,0 +1,113 @@ + + 4.0.0 + + org.argeo.commons.security + 0.2.3-SNAPSHOT + plugins + .. + + org.argeo.security.ui + Commons Security UI + jar + + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + org.apache.felix + maven-bundle-plugin + ${version.maven-bundle-plugin} + + + + + + + + + + + + + + + + + + + + + + lazy + org.argeo.security.ui.SecurityUiPlugin + org.eclipse.ui;resolution:=optional,org.eclipse.rap.ui;resolution:=optional,org.eclipse.core.runtime + + org.argeo.eclipse.spring, + * + + + + + + + + + + org.argeo.commons.security + org.argeo.security.core + 0.2.3-SNAPSHOT + + + + + org.argeo.commons.eclipse + org.argeo.eclipse.ui + 0.2.3-SNAPSHOT + + + + + org.argeo.commons.eclipse + org.argeo.eclipse.dep.common + 0.2.3-SNAPSHOT + + + + + org.argeo.commons.eclipse + org.argeo.eclipse.dep.rcp + 0.2.3-SNAPSHOT + provided + + + + + org.argeo.commons.basic + org.argeo.basic.nodeps + 0.2.3-SNAPSHOT + + + + + org.springframework.security + org.springframework.security.core + + + + + org.slf4j + com.springsource.slf4j.org.apache.commons.logging + + + diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/CurrentUser.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/CurrentUser.java new file mode 100644 index 000000000..a864c3a10 --- /dev/null +++ b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/CurrentUser.java @@ -0,0 +1,43 @@ +package org.argeo.security.ui; + +import java.security.AccessController; +import java.security.Principal; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import javax.security.auth.Subject; + +import org.argeo.ArgeoException; +import org.springframework.security.Authentication; +import org.springframework.security.GrantedAuthority; + +public class CurrentUser { + public final static String getUsername() { + Subject subject = getSubject(); + if (subject == null) + return null; + Principal principal = subject.getPrincipals().iterator().next(); + return principal.getName(); + + } + + public final static Set roles() { + Principal principal = getSubject().getPrincipals().iterator().next(); + Authentication authentication = (Authentication) principal; + Set roles = Collections.synchronizedSet(new HashSet()); + for (GrantedAuthority ga : authentication.getAuthorities()) { + roles.add(ga.getAuthority()); + } + return Collections.unmodifiableSet(roles); + } + + public final static Subject getSubject() { + + Subject subject = Subject.getSubject(AccessController.getContext()); + if (subject == null) + throw new ArgeoException("Not authenticated."); + return subject; + + } +} diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/SecurityPerspective.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/SecurityPerspective.java new file mode 100644 index 000000000..3b3b9b840 --- /dev/null +++ b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/SecurityPerspective.java @@ -0,0 +1,37 @@ +package org.argeo.security.ui; + +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IFolderLayout; +import org.eclipse.ui.IPageLayout; +import org.eclipse.ui.IPerspectiveFactory; + +public class SecurityPerspective implements IPerspectiveFactory { + private String adminRole = "ROLE_ADMIN"; + + public void createInitialLayout(IPageLayout layout) { + if (!CurrentUser.roles().contains(adminRole)) { + MessageDialog + .openError(Display.getCurrent().getActiveShell(), + "Forbidden", + "You are not allowed to access this resource."); + return; + } + + String editorArea = layout.getEditorArea(); + layout.setEditorAreaVisible(true); + layout.setFixed(false); + + IFolderLayout left = layout.createFolder("left", IPageLayout.LEFT, + 0.4f, editorArea); + + left.addView("org.argeo.security.ui.usersView"); + left.addView("org.argeo.security.ui.rolesView"); + // left.addView("org.argeo.security.ui.currentUserView"); + } + + public void setAdminRole(String adminRole) { + this.adminRole = adminRole; + } + +} diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/SecurityUiPlugin.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/SecurityUiPlugin.java new file mode 100644 index 000000000..bc05495b4 --- /dev/null +++ b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/SecurityUiPlugin.java @@ -0,0 +1,60 @@ +package org.argeo.security.ui; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class SecurityUiPlugin extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.argeo.security.ui"; //$NON-NLS-1$ + + // The shared instance + private static SecurityUiPlugin plugin; + + /** + * The constructor + */ + public SecurityUiPlugin() { + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext + * ) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext + * ) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static SecurityUiPlugin getDefault() { + return plugin; + } + + public static ImageDescriptor getImageDescriptor(String path) { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } +} diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/AddRole.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/AddRole.java new file mode 100644 index 000000000..1873a1391 --- /dev/null +++ b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/AddRole.java @@ -0,0 +1,40 @@ +package org.argeo.security.ui.commands; + +import org.argeo.ArgeoException; +import org.argeo.security.ArgeoSecurityService; +import org.argeo.security.ui.views.RolesView; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.ui.handlers.HandlerUtil; + +/** Add a new role. */ +public class AddRole extends AbstractHandler { + public final static String COMMAND_ID = "org.argeo.security.ui.addRole"; + private ArgeoSecurityService securityService; + private String rolePrefix = "ROLE_"; + + public Object execute(ExecutionEvent event) throws ExecutionException { + RolesView rolesView = (RolesView) HandlerUtil + .getActiveWorkbenchWindow(event).getActivePage() + .findView(RolesView.ID); + String role = rolesView.getNewRole(); + if (role.trim().equals("")) + return null; + if (role.equals(rolesView.getAddNewRoleText())) + return null; + role = role.trim().toUpperCase(); + if (!role.startsWith(rolePrefix)) + role = rolePrefix + role; + if (securityService.listEditableRoles().contains(role)) + throw new ArgeoException("Role " + role + " already exists"); + securityService.newRole(role); + rolesView.refresh(); + return null; + } + + public void setSecurityService(ArgeoSecurityService securityService) { + this.securityService = securityService; + } + +} diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/OpenArgeoUserEditor.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/OpenArgeoUserEditor.java new file mode 100644 index 000000000..c9bd25f54 --- /dev/null +++ b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/OpenArgeoUserEditor.java @@ -0,0 +1,28 @@ +package org.argeo.security.ui.commands; + +import org.argeo.security.ui.editors.ArgeoUserEditor; +import org.argeo.security.ui.editors.ArgeoUserEditorInput; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.handlers.HandlerUtil; + +/** Command handler to set visible or open a Argeo user. */ +public class OpenArgeoUserEditor extends AbstractHandler { + public final static String COMMAND_ID = "org.argeo.security.ui.openArgeoUserEditor"; + public final static String PARAM_USERNAME = "org.argeo.security.ui.username"; + + public Object execute(ExecutionEvent event) throws ExecutionException { + try { + ArgeoUserEditorInput editorInput = new ArgeoUserEditorInput( + event.getParameter(PARAM_USERNAME)); + IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow( + event).getActivePage(); + activePage.openEditor(editorInput, ArgeoUserEditor.ID); + } catch (Exception e) { + throw new ExecutionException("Cannot open editor", e); + } + return null; + } +} diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/OpenChangePasswordDialog.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/OpenChangePasswordDialog.java new file mode 100644 index 000000000..70471159d --- /dev/null +++ b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/OpenChangePasswordDialog.java @@ -0,0 +1,25 @@ +package org.argeo.security.ui.commands; + +import org.argeo.security.ArgeoSecurityService; +import org.argeo.security.ui.dialogs.ChangePasswordDialog; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.ui.handlers.HandlerUtil; + +/** Opens the change password dialog. */ +public class OpenChangePasswordDialog extends AbstractHandler { + private ArgeoSecurityService securityService; + + public Object execute(ExecutionEvent event) throws ExecutionException { + ChangePasswordDialog dialog = new ChangePasswordDialog( + HandlerUtil.getActiveShell(event), securityService); + dialog.open(); + return null; + } + + public void setSecurityService(ArgeoSecurityService securityService) { + this.securityService = securityService; + } + +} diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/RefreshUsersList.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/RefreshUsersList.java new file mode 100644 index 000000000..a385eb995 --- /dev/null +++ b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/RefreshUsersList.java @@ -0,0 +1,20 @@ +package org.argeo.security.ui.commands; + +import org.argeo.security.ui.views.UsersView; +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.ui.handlers.HandlerUtil; + +/** Refresh the main EBI list. */ +public class RefreshUsersList extends AbstractHandler { + + public Object execute(ExecutionEvent event) throws ExecutionException { + UsersView view = (UsersView) HandlerUtil + .getActiveWorkbenchWindow(event).getActivePage() + .findView(UsersView.ID); + view.refresh(); + return null; + } + +} \ No newline at end of file diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/SaveArgeoUser.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/SaveArgeoUser.java new file mode 100644 index 000000000..7d817435e --- /dev/null +++ b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/SaveArgeoUser.java @@ -0,0 +1,32 @@ +package org.argeo.security.ui.commands; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.handlers.HandlerUtil; + +/** Save the currently edited Argeo user. */ +public class SaveArgeoUser extends AbstractHandler { + public final static String COMMAND_ID = "org.argeo.security.ui.saveArgeoUser"; + + public Object execute(ExecutionEvent event) throws ExecutionException { + try { + IWorkbenchPart iwp = HandlerUtil.getActiveWorkbenchWindow(event) + .getActivePage().getActivePart(); + + if (!(iwp instanceof IEditorPart)) + return null; + IEditorPart editor = (IEditorPart) iwp; + editor.doSave(null); + } catch (Exception e) { + MessageDialog.openError(Display.getDefault().getActiveShell(), + "Error", "Cannot save user: " + e.getMessage()); + } + return null; + } + +} diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/dialogs/AbstractLoginDialog.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/dialogs/AbstractLoginDialog.java new file mode 100644 index 000000000..d3d1be38b --- /dev/null +++ b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/dialogs/AbstractLoginDialog.java @@ -0,0 +1,127 @@ +package org.argeo.security.ui.dialogs; + +import java.io.IOException; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.NameCallback; +import javax.security.auth.callback.PasswordCallback; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.operation.ModalContext; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +public abstract class AbstractLoginDialog extends TitleAreaDialog implements + CallbackHandler { + + boolean processCallbacks = false; + boolean isCancelled = false; + Callback[] callbackArray; + + protected final Callback[] getCallbacks() { + return this.callbackArray; + } + + public abstract void internalHandle(); + + public boolean isCancelled() { + return isCancelled; + } + + protected AbstractLoginDialog(Shell parentShell) { + super(parentShell); + } + + /* + * (non-Javadoc) + * + * @see + * javax.security.auth.callback.CallbackHandler#handle(javax.security.auth + * .callback.Callback[]) + */ + public void handle(final Callback[] callbacks) throws IOException { + this.callbackArray = callbacks; + final Display display = Display.getDefault(); + display.syncExec(new Runnable() { + + public void run() { + isCancelled = false; + setBlockOnOpen(false); + open(); + final Button okButton = getButton(IDialogConstants.OK_ID); + okButton.setText("Login"); + okButton.addSelectionListener(new SelectionListener() { + + public void widgetSelected(final SelectionEvent event) { + processCallbacks = true; + } + + public void widgetDefaultSelected(final SelectionEvent event) { + // nothing to do + } + }); + final Button cancel = getButton(IDialogConstants.CANCEL_ID); + cancel.addSelectionListener(new SelectionListener() { + + public void widgetSelected(final SelectionEvent event) { + isCancelled = true; + processCallbacks = true; + } + + public void widgetDefaultSelected(final SelectionEvent event) { + // nothing to do + } + }); + } + }); + try { + ModalContext.setAllowReadAndDispatch(true); // Works for now. + ModalContext.run(new IRunnableWithProgress() { + + public void run(final IProgressMonitor monitor) { + // Wait here until OK or cancel is pressed, then let it rip. + // The event + // listener + // is responsible for closing the dialog (in the + // loginSucceeded + // event). + while (!processCallbacks) { + try { + Thread.sleep(100); + } catch (final Exception e) { + // do nothing + } + } + processCallbacks = false; + // Call the adapter to handle the callbacks + if (!isCancelled()) + internalHandle(); + else + // clear callbacks are when cancelling + for (Callback callback : callbacks) + if (callback instanceof PasswordCallback) + ((PasswordCallback) callback).setPassword(null); + else if (callback instanceof NameCallback) + ((NameCallback) callback).setName(null); + } + }, true, new NullProgressMonitor(), Display.getDefault()); + } catch (final Exception e) { + final IOException ioe = new IOException(); + ioe.initCause(e); + throw ioe; + } + } + + protected void configureShell(Shell shell) { + super.configureShell(shell); + shell.setText("Login"); + } +} diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/dialogs/ChangePasswordDialog.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/dialogs/ChangePasswordDialog.java new file mode 100644 index 000000000..e2e78e814 --- /dev/null +++ b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/dialogs/ChangePasswordDialog.java @@ -0,0 +1,70 @@ +package org.argeo.security.ui.dialogs; + +import org.argeo.ArgeoException; +import org.argeo.security.ArgeoSecurityService; +import org.eclipse.jface.dialogs.IMessageProvider; +import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +/** Dialog to change the current user password */ +public class ChangePasswordDialog extends TitleAreaDialog { + private Text currentPassword, newPassword1, newPassword2; + private ArgeoSecurityService securityService; + + public ChangePasswordDialog(Shell parentShell, + ArgeoSecurityService securityService) { + super(parentShell); + this.securityService = securityService; + } + + protected Point getInitialSize() { + return new Point(300, 250); + } + + protected Control createDialogArea(Composite parent) { + Composite dialogarea = (Composite) super.createDialogArea(parent); + dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + Composite composite = new Composite(dialogarea, SWT.NONE); + composite.setLayout(new GridLayout(2, false)); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + currentPassword = createLP(composite, "Current password"); + newPassword1 = createLP(composite, "New password"); + newPassword2 = createLP(composite, "Repeat new password"); + + setMessage("Change password", IMessageProvider.INFORMATION); + parent.pack(); + return composite; + } + + @Override + protected void okPressed() { + if (!newPassword1.getText().equals(newPassword2.getText())) + throw new ArgeoException("Passwords are different"); + securityService.updateCurrentUserPassword(currentPassword.getText(), + newPassword1.getText()); + close(); + } + + /** Creates label and password. */ + protected Text createLP(Composite parent, String label) { + new Label(parent, SWT.NONE).setText(label); + Text text = new Text(parent, SWT.SINGLE | SWT.LEAD | SWT.PASSWORD + | SWT.BORDER); + text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + return text; + } + + protected void configureShell(Shell shell) { + super.configureShell(shell); + shell.setText("Change password"); + } + +} diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/dialogs/DefaultLoginDialog.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/dialogs/DefaultLoginDialog.java new file mode 100644 index 000000000..d00e961fb --- /dev/null +++ b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/dialogs/DefaultLoginDialog.java @@ -0,0 +1,114 @@ +package org.argeo.security.ui.dialogs; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.NameCallback; +import javax.security.auth.callback.PasswordCallback; +import javax.security.auth.callback.TextOutputCallback; + +import org.eclipse.jface.dialogs.IMessageProvider; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +public class DefaultLoginDialog extends AbstractLoginDialog { + + public DefaultLoginDialog() { + this(Display.getDefault().getActiveShell()); + } + + protected DefaultLoginDialog(Shell parentShell) { + super(parentShell); + } + + protected Point getInitialSize() { + return new Point(300, 250); + } + + protected Control createDialogArea(Composite parent) { + Composite dialogarea = (Composite) super.createDialogArea(parent); + // dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, + // true)); + Composite composite = new Composite(dialogarea, SWT.NONE); + composite.setLayout(new GridLayout(2, false)); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + createCallbackHandlers(composite); + parent.pack(); + return composite; + } + + private void createCallbackHandlers(Composite composite) { + Callback[] callbacks = getCallbacks(); + for (int i = 0; i < callbacks.length; i++) { + Callback callback = callbacks[i]; + if (callback instanceof TextOutputCallback) { + createTextoutputHandler(composite, + (TextOutputCallback) callback); + } else if (callback instanceof NameCallback) { + createNameHandler(composite, (NameCallback) callback); + } else if (callback instanceof PasswordCallback) { + createPasswordHandler(composite, (PasswordCallback) callback); + } + } + } + + private void createPasswordHandler(Composite composite, + final PasswordCallback callback) { + Label label = new Label(composite, SWT.NONE); + label.setText(callback.getPrompt()); + final Text passwordText = new Text(composite, SWT.SINGLE | SWT.LEAD + | SWT.PASSWORD | SWT.BORDER); + passwordText + .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + passwordText.addModifyListener(new ModifyListener() { + + public void modifyText(ModifyEvent event) { + callback.setPassword(passwordText.getText().toCharArray()); + } + }); + } + + private void createNameHandler(Composite composite, + final NameCallback callback) { + Label label = new Label(composite, SWT.NONE); + label.setText(callback.getPrompt()); + final Text text = new Text(composite, SWT.SINGLE | SWT.LEAD + | SWT.BORDER); + text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + text.addModifyListener(new ModifyListener() { + + public void modifyText(ModifyEvent event) { + callback.setName(text.getText()); + } + }); + } + + private void createTextoutputHandler(Composite composite, + TextOutputCallback callback) { + int messageType = callback.getMessageType(); + int dialogMessageType = IMessageProvider.NONE; + switch (messageType) { + case TextOutputCallback.INFORMATION: + dialogMessageType = IMessageProvider.INFORMATION; + break; + case TextOutputCallback.WARNING: + dialogMessageType = IMessageProvider.WARNING; + break; + case TextOutputCallback.ERROR: + dialogMessageType = IMessageProvider.ERROR; + break; + } + setMessage(callback.getMessage(), dialogMessageType); + } + + public void internalHandle() { + } +} diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/ArgeoUserEditor.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/ArgeoUserEditor.java new file mode 100644 index 000000000..99a4652a9 --- /dev/null +++ b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/ArgeoUserEditor.java @@ -0,0 +1,72 @@ +package org.argeo.security.ui.editors; + +import org.argeo.ArgeoException; +import org.argeo.security.ArgeoSecurityService; +import org.argeo.security.ArgeoUser; +import org.argeo.security.SimpleArgeoUser; +import org.argeo.security.nature.SimpleUserNature; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorSite; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.forms.editor.FormEditor; + +/** Editor for an Argeo user. */ +public class ArgeoUserEditor extends FormEditor { + public final static String ID = "org.argeo.security.ui.argeoUserEditor"; + + private ArgeoUser user; + private ArgeoSecurityService securityService; + + public void init(IEditorSite site, IEditorInput input) + throws PartInitException { + super.init(site, input); + String username = ((ArgeoUserEditorInput) getEditorInput()) + .getUsername(); + if (username == null) {// new + user = new SimpleArgeoUser(); + user.getUserNatures().put(SimpleUserNature.TYPE, + new SimpleUserNature()); + } else + user = securityService.getUser(username); + this.setPartProperty("name", username != null ? username : ""); + setPartName(username != null ? username : ""); + } + + protected void addPages() { + try { + addPage(new DefaultUserMainPage(this, securityService, user)); + + } catch (PartInitException e) { + throw new ArgeoException("Not able to add page ", e); + } + } + + @Override + public void doSave(IProgressMonitor monitor) { + // list pages + // TODO: make it more generic + findPage(DefaultUserMainPage.ID).doSave(monitor); + + if (securityService.userExists(user.getUsername())) + securityService.updateUser(user); + else { + securityService.newUser(user); + setPartName(user.getUsername()); + } + firePropertyChange(PROP_DIRTY); + } + + @Override + public void doSaveAs() { + } + + @Override + public boolean isSaveAsAllowed() { + return false; + } + + public void setSecurityService(ArgeoSecurityService securityService) { + this.securityService = securityService; + } +} diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/ArgeoUserEditorInput.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/ArgeoUserEditorInput.java new file mode 100644 index 000000000..9d61e9fab --- /dev/null +++ b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/ArgeoUserEditorInput.java @@ -0,0 +1,51 @@ +package org.argeo.security.ui.editors; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IPersistableElement; + +/** Editor input for an Argeo user. */ +public class ArgeoUserEditorInput implements IEditorInput { + private final String username; + + public ArgeoUserEditorInput(String username) { + this.username = username; + } + + public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) { + return null; + } + + public boolean exists() { + return username != null; + } + + public ImageDescriptor getImageDescriptor() { + return null; + } + + public String getName() { + return username != null ? username : ""; + } + + public IPersistableElement getPersistable() { + return null; + } + + public String getToolTipText() { + return username != null ? username : ""; + } + + public boolean equals(Object obj) { + if (!(obj instanceof ArgeoUserEditorInput)) + return false; + if (((ArgeoUserEditorInput) obj).getUsername() == null) + return false; + return ((ArgeoUserEditorInput) obj).getUsername().equals(username); + } + + public String getUsername() { + return username; + } + +} diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/DefaultUserMainPage.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/DefaultUserMainPage.java new file mode 100644 index 000000000..6180de49a --- /dev/null +++ b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/DefaultUserMainPage.java @@ -0,0 +1,337 @@ +package org.argeo.security.ui.editors; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.argeo.security.ArgeoSecurityService; +import org.argeo.security.ArgeoUser; +import org.argeo.security.SimpleArgeoUser; +import org.argeo.security.nature.SimpleUserNature; +import org.argeo.security.ui.SecurityUiPlugin; +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.CheckboxCellEditor; +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.EditingSupport; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.forms.AbstractFormPart; +import org.eclipse.ui.forms.IManagedForm; +import org.eclipse.ui.forms.SectionPart; +import org.eclipse.ui.forms.editor.FormEditor; +import org.eclipse.ui.forms.editor.FormPage; +import org.eclipse.ui.forms.widgets.ColumnLayout; +import org.eclipse.ui.forms.widgets.FormToolkit; +import org.eclipse.ui.forms.widgets.ScrolledForm; +import org.eclipse.ui.forms.widgets.Section; + +/** + * Display/edit the properties common to all {@link ArgeoUser} (username and + * roles) as well as the properties of the {@link SimpleUserNature}. + */ +public class DefaultUserMainPage extends FormPage { + final static String ID = "argeoUserEditor.mainPage"; + + private final static Log log = LogFactory.getLog(DefaultUserMainPage.class); + private final static Image ROLE_CHECKED = SecurityUiPlugin + .getImageDescriptor("icons/security.gif").createImage(); + + private ArgeoUser user; + private SimpleUserNature simpleNature; + private String simpleNatureType; + private ArgeoSecurityService securityService; + + public DefaultUserMainPage(FormEditor editor, + ArgeoSecurityService securityService, ArgeoUser user) { + super(editor, ID, "Main"); + this.securityService = securityService; + this.user = user; + this.simpleNature = SimpleUserNature.findSimpleUserNature(user, + simpleNatureType); + } + + protected void createFormContent(final IManagedForm mf) { + ScrolledForm form = mf.getForm(); + form.setText(simpleNature.getFirstName() + " " + + simpleNature.getLastName()); + ColumnLayout mainLayout = new ColumnLayout(); + mainLayout.minNumColumns = 1; + mainLayout.maxNumColumns = 4; + mainLayout.topMargin = 0; + mainLayout.bottomMargin = 5; + mainLayout.leftMargin = mainLayout.rightMargin = mainLayout.horizontalSpacing = mainLayout.verticalSpacing = 10; + form.getBody().setLayout(mainLayout); + + createGeneralPart(form.getBody()); + createRolesPart(form.getBody()); + createPassworPart(form.getBody()); + } + + /** Creates the general section */ + protected void createGeneralPart(Composite parent) { + FormToolkit tk = getManagedForm().getToolkit(); + Section section = tk.createSection(parent, Section.TITLE_BAR); + section.setText("General"); + + Composite body = tk.createComposite(section, SWT.WRAP); + section.setClient(body); + GridLayout layout = new GridLayout(); + layout.marginWidth = layout.marginHeight = 0; + layout.numColumns = 2; + body.setLayout(layout); + + // add widgets (view) + final Text username; + if (user.getUsername() != null) { + tk.createLabel(body, "Username"); + tk.createLabel(body, user.getUsername()); + username = null; + } else { + username = createLT(body, "Username", ""); + } + final Text firstName = createLT(body, "First name", + simpleNature.getFirstName()); + final Text lastName = createLT(body, "Last name", + simpleNature.getLastName()); + final Text email = createLT(body, "Email", simpleNature.getEmail()); + final Text description = createLT(body, "Description", + simpleNature.getDescription()); + + // create form part (controller) + AbstractFormPart part = new SectionPart(section) { + public void commit(boolean onSave) { + if (username != null) { + ((SimpleArgeoUser) user).setUsername(username.getText()); + username.setEditable(false); + username.setEnabled(false); + } + simpleNature.setFirstName(firstName.getText()); + simpleNature.setLastName(lastName.getText()); + simpleNature.setEmail(email.getText()); + simpleNature.setDescription(description.getText()); + super.commit(onSave); + if (log.isTraceEnabled()) + log.trace("General part committed"); + } + }; + if (username != null) + username.addModifyListener(new FormPartML(part)); + firstName.addModifyListener(new FormPartML(part)); + lastName.addModifyListener(new FormPartML(part)); + email.addModifyListener(new FormPartML(part)); + description.addModifyListener(new FormPartML(part)); + getManagedForm().addPart(part); + } + + /** Creates the password section */ + protected void createPassworPart(Composite parent) { + FormToolkit tk = getManagedForm().getToolkit(); + Section section = tk.createSection(parent, Section.TITLE_BAR); + section.setText("Password"); + + Composite body = tk.createComposite(section, SWT.WRAP); + section.setClient(body); + GridLayout layout = new GridLayout(); + layout.marginWidth = layout.marginHeight = 0; + layout.numColumns = 2; + body.setLayout(layout); + + // add widgets (view) + final Text password1 = createLP(body, "New password", ""); + final Text password2 = createLP(body, "Repeat password", ""); + // create form part (controller) + AbstractFormPart part = new SectionPart(section) { + public void commit(boolean onSave) { + if (!password1.getText().equals("") + && password1.getText().equals(password2.getText())) { + ((SimpleArgeoUser) user).setPassword(password1.getText()); + } + super.commit(onSave); + if (log.isTraceEnabled()) + log.trace("Password part committed"); + } + }; + password1.addModifyListener(new FormPartML(part)); + password2.addModifyListener(new FormPartML(part)); + getManagedForm().addPart(part); + } + + /** Creates the role section */ + protected void createRolesPart(Composite parent) { + FormToolkit tk = getManagedForm().getToolkit(); + Section section = tk.createSection(parent, Section.DESCRIPTION + | Section.TITLE_BAR); + section.setText("Roles"); + section.setDescription("Roles define " + + "the authorizations for this user."); + Table table = new Table(section, SWT.MULTI | SWT.H_SCROLL + | SWT.V_SCROLL); + section.setClient(table); + + AbstractFormPart part = new SectionPart(section) { + public void commit(boolean onSave) { + // roles have already been modified in editing + super.commit(onSave); + if (log.isTraceEnabled()) + log.trace("Role part committed"); + } + }; + getManagedForm().addPart(part); + + GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); + gridData.verticalSpan = 20; + table.setLayoutData(gridData); + table.setLinesVisible(true); + table.setHeaderVisible(false); + TableViewer viewer = new TableViewer(table); + + // check column + TableViewerColumn column = createTableViewerColumn(viewer, "checked", + 20); + column.setLabelProvider(new ColumnLabelProvider() { + public String getText(Object element) { + return null; + } + + public Image getImage(Object element) { + String role = element.toString(); + if (user.getRoles().contains(role)) { + return ROLE_CHECKED; + } else { + return null; + } + } + }); + column.setEditingSupport(new RoleEditingSupport(viewer, part)); + + // role column + column = createTableViewerColumn(viewer, "Role", 200); + column.setLabelProvider(new ColumnLabelProvider() { + public String getText(Object element) { + return element.toString(); + } + + public Image getImage(Object element) { + return null; + } + }); + viewer.setContentProvider(new RolesContentProvider()); + viewer.setInput(getEditorSite()); + } + + protected TableViewerColumn createTableViewerColumn(TableViewer viewer, + String title, int bound) { + final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, + SWT.NONE); + final TableColumn column = viewerColumn.getColumn(); + column.setText(title); + column.setWidth(bound); + column.setResizable(true); + column.setMoveable(true); + return viewerColumn; + + } + + /** Creates label and text. */ + protected Text createLT(Composite body, String label, String value) { + FormToolkit toolkit = getManagedForm().getToolkit(); + toolkit.createLabel(body, label); + Text text = toolkit.createText(body, value, SWT.BORDER); + text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + return text; + } + + /** Creates label and password. */ + protected Text createLP(Composite body, String label, String value) { + FormToolkit toolkit = getManagedForm().getToolkit(); + toolkit.createLabel(body, label); + Text text = toolkit.createText(body, value, SWT.BORDER | SWT.PASSWORD); + text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + return text; + } + + public void setSimpleNatureType(String simpleNatureType) { + this.simpleNatureType = simpleNatureType; + } + + private class FormPartML implements ModifyListener { + private AbstractFormPart formPart; + + public FormPartML(AbstractFormPart generalPart) { + this.formPart = generalPart; + } + + public void modifyText(ModifyEvent e) { + formPart.markDirty(); + } + + } + + private class RolesContentProvider implements IStructuredContentProvider { + public Object[] getElements(Object inputElement) { + return securityService.listEditableRoles().toArray(); + } + + public void dispose() { + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + } + + /** Select the columns by editing the checkbox in the first column */ + class RoleEditingSupport extends EditingSupport { + + private final TableViewer viewer; + private final AbstractFormPart formPart; + + public RoleEditingSupport(TableViewer viewer, AbstractFormPart formPart) { + super(viewer); + this.viewer = viewer; + this.formPart = formPart; + } + + @Override + protected CellEditor getCellEditor(Object element) { + return new CheckboxCellEditor(null, SWT.CHECK | SWT.READ_ONLY); + + } + + @Override + protected boolean canEdit(Object element) { + return true; + } + + @Override + protected Object getValue(Object element) { + String role = element.toString(); + return user.getRoles().contains(role); + + } + + @Override + protected void setValue(Object element, Object value) { + Boolean inRole = (Boolean) value; + String role = element.toString(); + if (inRole && !user.getRoles().contains(role)) { + user.getRoles().add(role); + formPart.markDirty(); + } else if (!inRole && user.getRoles().contains(role)) { + user.getRoles().remove(role); + formPart.markDirty(); + } + viewer.refresh(); + } + } + +} diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/CurrentUserView.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/CurrentUserView.java new file mode 100644 index 000000000..5b0492828 --- /dev/null +++ b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/CurrentUserView.java @@ -0,0 +1,129 @@ +package org.argeo.security.ui.views; + +import org.argeo.security.ui.CurrentUser; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.ui.part.ViewPart; + +public class CurrentUserView extends ViewPart { + private TableViewer viewer; + + @Override + public void createPartControl(Composite parent) { + + // viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL + // | SWT.V_SCROLL); + viewer = new TableViewer(createTable(parent)); + viewer.setContentProvider(new UsersContentProvider()); + viewer.setLabelProvider(new UsersLabelProvider()); + viewer.setInput(getViewSite()); + // viewer.setInput(SecurityContextHolder.getContext()); + } + + protected Table createTable(Composite parent) { + int style = SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL; + + Table table = new Table(parent, style); + + // GridData gridData = new GridData(GridData.FILL_BOTH); + // gridData.grabExcessVerticalSpace = true; + // gridData.grabExcessHorizontalSpace = true; + // gridData.horizontalSpan = 3; + // table.setLayoutData(gridData); + + table.setLinesVisible(true); + table.setHeaderVisible(true); + + TableColumn column = new TableColumn(table, SWT.LEFT, 0); + column.setText("ID"); + column.setWidth(100); + + // column = new TableColumn(table, SWT.LEFT, 1); + // column.setText("Password"); + // column.setWidth(200); + + // column = new TableColumn(table, SWT.LEFT, 2); + // column.setText("Roles"); + // column.setWidth(300); + + return table; + } + + @Override + public void setFocus() { + viewer.getTable().setFocus(); + } + + private class UsersContentProvider implements IStructuredContentProvider { + + public Object[] getElements(Object inputElement) { + return getChildren(inputElement); + } + + public Object[] getChildren(Object parentElement) { + // ILoginContext secureContext = LoginContextFactory + // .createContext("SPRING"); + // try { + // secureContext.login(); + // } catch (LoginException e) { + // // login failed + // } + // + // Subject subject = null; + // // subject = Subject.getSubject(AccessController.getContext()); + // try { + // subject = secureContext.getSubject(); + // } catch (Exception e) { + // e.printStackTrace(); + // throw new ArgeoException("Cannot retrieve subject", e); + // } + // + // if (subject == null) + // throw new ArgeoException("No subject found"); + // return subject.getPrincipals().toArray(); + return CurrentUser.roles().toArray(); + } + + public void dispose() { + // TODO Auto-generated method stub + + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + // TODO Auto-generated method stub + + } + + } + + private class UsersLabelProvider extends LabelProvider implements + ITableLabelProvider { + public String getColumnText(Object element, int columnIndex) { + // Principal argeoUser = (Principal) element; + // switch (columnIndex) { + // case 0: + // return argeoUser.getName(); + // case 1: + // return argeoUser.toString(); + // default: + // throw new ArgeoException("Unmanaged column " + columnIndex); + // } + return element.toString(); + } + + public Image getColumnImage(Object element, int columnIndex) { + // TODO Auto-generated method stub + return null; + } + + } + +} diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/RolesView.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/RolesView.java new file mode 100644 index 000000000..a58675e4b --- /dev/null +++ b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/RolesView.java @@ -0,0 +1,177 @@ +package org.argeo.security.ui.views; + +import java.util.ArrayList; + +import org.argeo.ArgeoException; +import org.argeo.security.ArgeoSecurityService; +import org.argeo.security.ArgeoUser; +import org.argeo.security.ui.SecurityUiPlugin; +import org.argeo.security.ui.commands.AddRole; +import org.argeo.security.ui.commands.OpenArgeoUserEditor; +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.IParameter; +import org.eclipse.core.commands.Parameterization; +import org.eclipse.core.commands.ParameterizedCommand; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.commands.ICommandService; +import org.eclipse.ui.handlers.IHandlerService; +import org.eclipse.ui.part.ViewPart; + +/** List all roles. */ +public class RolesView extends ViewPart { + public final static String ID = "org.argeo.security.ui.rolesView"; + + private Text newRole; + + private TableViewer viewer; + private ArgeoSecurityService securityService; + + private String addNewRoleText = ""; + + @Override + public void createPartControl(Composite parent) { + parent.setLayout(new GridLayout(1, false)); + + // new role text field + newRole = new Text(parent, SWT.BORDER); + newRole.setText(addNewRoleText); + newRole.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + // default action is add role + newRole.addListener(SWT.DefaultSelection, new Listener() { + public void handleEvent(Event evt) { + IWorkbench iw = SecurityUiPlugin.getDefault().getWorkbench(); + IHandlerService handlerService = (IHandlerService) iw + .getService(IHandlerService.class); + try { + handlerService.executeCommand(AddRole.COMMAND_ID, evt); + } catch (Exception e) { + throw new ArgeoException("Cannot execute add role command", + e); + } + } + }); + // select all on focus + newRole.addListener(SWT.FocusIn, new Listener() { + public void handleEvent(Event e) { + newRole.selectAll(); + } + }); + + // roles table + Table table = new Table(parent, SWT.V_SCROLL | SWT.BORDER); + table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + table.setLinesVisible(false); + table.setHeaderVisible(false); + viewer = new TableViewer(table); + viewer.setContentProvider(new RolesContentProvider()); + viewer.setLabelProvider(new UsersLabelProvider()); + viewer.setInput(getViewSite()); + viewer.addDoubleClickListener(new ViewDoubleClickListener()); + } + + @Override + public void setFocus() { + viewer.getTable().setFocus(); + } + + public void setSecurityService(ArgeoSecurityService securityService) { + this.securityService = securityService; + } + + public String getAddNewRoleText() { + return addNewRoleText; + } + + private class RolesContentProvider implements IStructuredContentProvider { + + public Object[] getElements(Object inputElement) { + return securityService.listEditableRoles().toArray(); + } + + public void dispose() { + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + } + + private class UsersLabelProvider extends LabelProvider implements + ITableLabelProvider { + public String getColumnText(Object element, int columnIndex) { + return element.toString(); + } + + public Image getColumnImage(Object element, int columnIndex) { + return null; + } + + } + + class ViewDoubleClickListener implements IDoubleClickListener { + public void doubleClick(DoubleClickEvent evt) { + Object obj = ((IStructuredSelection) evt.getSelection()) + .getFirstElement(); + + if (obj instanceof ArgeoUser) { + ArgeoUser argeoUser = (ArgeoUser) obj; + + IWorkbench iw = SecurityUiPlugin.getDefault().getWorkbench(); + IHandlerService handlerService = (IHandlerService) iw + .getService(IHandlerService.class); + try { + String commandId = OpenArgeoUserEditor.COMMAND_ID; + String paramName = OpenArgeoUserEditor.PARAM_USERNAME; + + // TODO: factorize this + // execute related command + IWorkbenchWindow window = iw.getActiveWorkbenchWindow(); + ICommandService cmdService = (ICommandService) window + .getService(ICommandService.class); + Command cmd = cmdService.getCommand(commandId); + ArrayList parameters = new ArrayList(); + IParameter iparam = cmd.getParameter(paramName); + Parameterization param = new Parameterization(iparam, + argeoUser.getUsername()); + parameters.add(param); + ParameterizedCommand pc = new ParameterizedCommand(cmd, + parameters.toArray(new Parameterization[parameters + .size()])); + handlerService = (IHandlerService) window + .getService(IHandlerService.class); + handlerService.executeCommand(pc, null); + } catch (Exception e) { + throw new ArgeoException("Cannot open editor", e); + } + + } + } + } + + public String getNewRole() { + return newRole.getText(); + } + + public void refresh() { + viewer.refresh(); + newRole.setText(addNewRoleText); + } +} diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/UsersView.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/UsersView.java new file mode 100644 index 000000000..5d7817827 --- /dev/null +++ b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/UsersView.java @@ -0,0 +1,174 @@ +package org.argeo.security.ui.views; + +import java.util.ArrayList; + +import org.argeo.ArgeoException; +import org.argeo.security.ArgeoSecurityService; +import org.argeo.security.ArgeoUser; +import org.argeo.security.nature.SimpleUserNature; +import org.argeo.security.ui.CurrentUser; +import org.argeo.security.ui.SecurityUiPlugin; +import org.argeo.security.ui.commands.OpenArgeoUserEditor; +import org.eclipse.core.commands.Command; +import org.eclipse.core.commands.IParameter; +import org.eclipse.core.commands.Parameterization; +import org.eclipse.core.commands.ParameterizedCommand; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.commands.ICommandService; +import org.eclipse.ui.handlers.IHandlerService; +import org.eclipse.ui.part.ViewPart; + +/** List all users. */ +public class UsersView extends ViewPart { + public final static String ID = "org.argeo.security.ui.usersView"; + + private TableViewer viewer; + private ArgeoSecurityService securityService; + + private String simpleNatureType = null; + + @Override + public void createPartControl(Composite parent) { + viewer = new TableViewer(createTable(parent)); + viewer.setContentProvider(new UsersContentProvider()); + viewer.setLabelProvider(new UsersLabelProvider()); + viewer.addDoubleClickListener(new ViewDoubleClickListener()); + viewer.setInput(getViewSite()); + } + + protected Table createTable(Composite parent) { + Table table = new Table(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); + table.setLinesVisible(true); + table.setHeaderVisible(true); + TableColumn column = new TableColumn(table, SWT.LEFT, 0); + column.setText("User"); + column.setWidth(50); + column = new TableColumn(table, SWT.LEFT, 1); + column.setText("First Name"); + column.setWidth(100); + column = new TableColumn(table, SWT.LEFT, 2); + column.setText("Last Name"); + column.setWidth(100); + column = new TableColumn(table, SWT.LEFT, 3); + column.setText("E-mail"); + column.setWidth(100); + return table; + } + + @Override + public void setFocus() { + viewer.getTable().setFocus(); + } + + public void setSecurityService(ArgeoSecurityService securityService) { + this.securityService = securityService; + } + + public void setSimpleNatureType(String simpleNatureType) { + this.simpleNatureType = simpleNatureType; + } + + public void refresh() { + viewer.refresh(); + } + + private class UsersContentProvider implements IStructuredContentProvider { + + public Object[] getElements(Object inputElement) { + return securityService.listUsers().toArray(); + } + + public void dispose() { + } + + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + } + + private class UsersLabelProvider extends LabelProvider implements + ITableLabelProvider { + public String getColumnText(Object element, int columnIndex) { + String currentUsername = CurrentUser.getUsername(); + ArgeoUser user = (ArgeoUser) element; + SimpleUserNature simpleNature = SimpleUserNature + .findSimpleUserNature(user, simpleNatureType); + switch (columnIndex) { + case 0: + String userName = user.getUsername(); + if (userName.equals(currentUsername)) + userName = userName + "*"; + return userName; + case 1: + return simpleNature.getFirstName(); + case 2: + return simpleNature.getLastName(); + case 3: + return simpleNature.getEmail(); + default: + throw new ArgeoException("Unmanaged column " + columnIndex); + } + } + + public Image getColumnImage(Object element, int columnIndex) { + // TODO Auto-generated method stub + return null; + } + + } + + class ViewDoubleClickListener implements IDoubleClickListener { + public void doubleClick(DoubleClickEvent evt) { + Object obj = ((IStructuredSelection) evt.getSelection()) + .getFirstElement(); + + if (obj instanceof ArgeoUser) { + ArgeoUser argeoUser = (ArgeoUser) obj; + + IWorkbench iw = SecurityUiPlugin.getDefault().getWorkbench(); + IHandlerService handlerService = (IHandlerService) iw + .getService(IHandlerService.class); + try { + String commandId = OpenArgeoUserEditor.COMMAND_ID; + String paramName = OpenArgeoUserEditor.PARAM_USERNAME; + + // TODO: factorize this + // execute related command + IWorkbenchWindow window = iw.getActiveWorkbenchWindow(); + ICommandService cmdService = (ICommandService) window + .getService(ICommandService.class); + Command cmd = cmdService.getCommand(commandId); + ArrayList parameters = new ArrayList(); + IParameter iparam = cmd.getParameter(paramName); + Parameterization param = new Parameterization(iparam, + argeoUser.getUsername()); + parameters.add(param); + ParameterizedCommand pc = new ParameterizedCommand(cmd, + parameters.toArray(new Parameterization[parameters + .size()])); + handlerService = (IHandlerService) window + .getService(IHandlerService.class); + handlerService.executeCommand(pc, null); + } catch (Exception e) { + throw new ArgeoException("Cannot open editor", e); + } + + } + } + } + +} diff --git a/security/plugins/pom.xml b/security/plugins/pom.xml new file mode 100644 index 000000000..ab837feb5 --- /dev/null +++ b/security/plugins/pom.xml @@ -0,0 +1,89 @@ + + 4.0.0 + + org.argeo.commons.security + 0.2.3-SNAPSHOT + eclipse + .. + + plugins + Commons Security Eclipse plugins + pom + + org.argeo.security.equinox + org.argeo.security.ui + org.argeo.security.ui.application + org.argeo.security.ui.rap + + + + + src/main/resources + + + . + + plugin.xml + META-INF/** + jaas/** + icons/** + + + + + + maven-clean-plugin + + + + META-INF + + MANIFEST.MF + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + META-INF/MANIFEST.MF + + + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + + org.apache.felix + maven-bundle-plugin + + META-INF + + ${pom.artifactId};singleton:=true + + + + + + + + org.argeo.commons.osgi + org.argeo.osgi.boot + 0.2.3-SNAPSHOT + test + + + javax.xml.stream + com.springsource.javax.xml.stream + test + + +