From: <jav...@us...> - 2009-07-27 08:14:08
|
Revision: 11994 http://dcm4che.svn.sourceforge.net/dcm4che/?rev=11994&view=rev Author: javawilli Date: 2009-07-27 08:13:57 +0000 (Mon, 27 Jul 2009) Log Message: ----------- [#WEB-22] Add JAAS Authentification [#WEB-23] Add initial WicketTest [#WEB-24] Add initial EJB3 Testing Modified Paths: -------------- dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/pom.xml dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/java/org/dcm4chee/web/wicket/MainPage.java dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/java/org/dcm4chee/web/wicket/WicketApplication.java dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/java/org/dcm4chee/web/wicket/WicketSession.java dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/java/org/dcm4chee/web/wicket/util/JNDIUtils.java Added Paths: ----------- dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/java/org/dcm4chee/web/wicket/JaasWicketSession.java dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/java/org/dcm4chee/web/wicket/LoginPage.java dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/resources/org/dcm4chee/web/wicket/LoginPage.html dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/ dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/java/ dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/java/org/ dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/java/org/dcm4chee/ dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/java/org/dcm4chee/web/ dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/java/org/dcm4chee/web/wicket/ dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/java/org/dcm4chee/web/wicket/WicketApplicationTest.java dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/resources/ dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/resources/ejb3unit.properties dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/resources/jndi.properties dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/resources/log4j.properties dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/resources/roles.properties dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/resources/users.properties dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/resources/wicket.login.file Modified: dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/pom.xml =================================================================== --- dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/pom.xml 2009-07-24 17:51:41 UTC (rev 11993) +++ dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/pom.xml 2009-07-27 08:13:57 UTC (rev 11994) @@ -1,82 +1,156 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <parent> - <artifactId>dcm4chee-web</artifactId> - <groupId>dcm4che.dcm4chee</groupId> - <version>3.0.0-SNAPSHOT</version> - </parent> - <modelVersion>4.0.0</modelVersion> - <groupId>dcm4che.dcm4chee</groupId> - <artifactId>dcm4chee-web-war</artifactId> - <packaging>war</packaging> - <version>3.0.0-SNAPSHOT</version> - <name>WAR for dcm4chee-web</name> - <description></description> - <dependencies> - <dependency> - <groupId>dcm4che.dcm4chee</groupId> - <artifactId>dcm4chee-arc-entities-hsql - </artifactId> - <version>3.0.0-SNAPSHOT</version> - <scope>provided</scope> - <exclusions> - <exclusion> - <groupId>dcm4che</groupId> - <artifactId>dcm4che-core</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>dcm4che</groupId> - <artifactId>dcm4che-core</artifactId> - <version>2.0.19</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>dcm4che.dcm4chee</groupId> - <artifactId>dcm4chee-web-ejb</artifactId> - <version>3.0.0-SNAPSHOT</version> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.apache.wicket</groupId> - <artifactId>wicket</artifactId> - <version>${wicket.version}</version> - <exclusions> - <exclusion> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> <groupId>org.apache.wicket</groupId> - <artifactId>wicket-extensions</artifactId> - <version>${wicket.version}</version> - <exclusions> - <exclusion> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - </exclusion> - </exclusions> - </dependency> - - </dependencies> - <build> - <plugins> - <plugin> - <inherited>true</inherited> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <configuration> - <source>1.5</source> - <target>1.5</target> - <optimise>true</optimise> - <debug>true</debug> - </configuration> - </plugin> - </plugins> - </build> - <properties> - <wicket.version>1.3.6</wicket.version> - </properties> -</project> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <artifactId>dcm4chee-web</artifactId> + <groupId>dcm4che.dcm4chee</groupId> + <version>3.0.0-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <groupId>dcm4che.dcm4chee</groupId> + <artifactId>dcm4chee-web-war</artifactId> + <packaging>war</packaging> + <version>3.0.0-SNAPSHOT</version> + <name>WAR for dcm4chee-web</name> + <description></description> + <dependencies> + <dependency> + <groupId>dcm4che.dcm4chee</groupId> + <artifactId>dcm4chee-arc-entities-hsql</artifactId> + <version>3.0.0-SNAPSHOT</version> + <scope>provided</scope> + <exclusions> + <exclusion> + <groupId>dcm4che</groupId> + <artifactId>dcm4che-core</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>dcm4che</groupId> + <artifactId>dcm4che-core</artifactId> + <version>2.0.19</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>jboss</groupId> + <artifactId>jbosssx</artifactId> + <version>4.2.3.GA</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>jboss</groupId> + <artifactId>jboss-common</artifactId> + <version>4.2.3.GA</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>jboss</groupId> + <artifactId>jboss-annotations-ejb3</artifactId> + <version>4.2.3.GA</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>dcm4che.dcm4chee</groupId> + <artifactId>dcm4chee-web-ejb</artifactId> + <version>3.0.0-SNAPSHOT</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.wicket</groupId> + <artifactId>wicket</artifactId> + <version>${wicket.version}</version> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.wicket</groupId> + <artifactId>wicket-extensions</artifactId> + <version>${wicket.version}</version> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.wicket</groupId> + <artifactId>wicket-auth-roles</artifactId> + <version>${wicket.version}</version> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.3</version> + <scope>test</scope> + </dependency> + <!-- JETTY DEPENDENCIES FOR TESTING --> + + <dependency> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty</artifactId> + <version>${jetty.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty-util</artifactId> + <version>${jetty.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty-management</artifactId> + <version>${jetty.version}</version> + <scope>provided</scope> + </dependency> + <!-- ejb3unit dependencies --> + <dependency> + <groupId>com.bm</groupId> + <artifactId>ejb3unit</artifactId> + <version>2.0.0-RC-1</version> + <scope>provided</scope> + </dependency> + + </dependencies> + <build> + <testResources> + <testResource> + <directory>src/test/resources</directory> + <filtering>true</filtering> + </testResource> + </testResources> + <plugins> + <plugin> + <inherited>true</inherited> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.5</source> + <target>1.5</target> + <optimise>true</optimise> + <debug>true</debug> + </configuration> + </plugin> + <plugin> + <groupId>org.mortbay.jetty</groupId> + <artifactId>maven-jetty-plugin</artifactId> + </plugin> + </plugins> + </build> + <properties> + <wicket.version>1.3.6</wicket.version> + <jetty.version>6.1.4</jetty.version> + </properties> +</project> Added: dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/java/org/dcm4chee/web/wicket/JaasWicketSession.java =================================================================== --- dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/java/org/dcm4chee/web/wicket/JaasWicketSession.java (rev 0) +++ dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/java/org/dcm4chee/web/wicket/JaasWicketSession.java 2009-07-27 08:13:57 UTC (rev 11994) @@ -0,0 +1,139 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is part of dcm4che, an implementation of DICOM(TM) in + * Java(TM), hosted at http://sourceforge.net/projects/dcm4che. + * + * The Initial Developer of the Original Code is + * Agfa-Gevaert AG. + * Portions created by the Initial Developer are Copyright (C) 2008 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * See listed authors below. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +package org.dcm4chee.web.wicket; + +import java.io.IOException; +import java.security.Principal; +import java.security.acl.Group; +import java.util.Enumeration; + +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.UnsupportedCallbackException; +import javax.security.auth.login.LoginContext; +import javax.security.auth.login.LoginException; + +import org.apache.wicket.Request; +import org.apache.wicket.authentication.AuthenticatedWebSession; +import org.apache.wicket.authorization.strategies.role.Roles; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * JAAS based Wicket Session to use JBoss web security. + */ +public class JaasWicketSession extends WicketSession { + + public static final String ROLES_NAME = "Roles"; + + /** The name of the application-policy (JBoss login-config.xml) */ + public static final String APPLICATION_POLICY_NAME = "dcm4chee"; + + private final static Logger log = LoggerFactory.getLogger(JaasWicketSession.class); + + private Subject subject; + private Roles roles = new Roles(); + + @SuppressWarnings("deprecation") + public JaasWicketSession(Request req) { + super(req); + } + + public boolean authenticate(String username, String password) { + if (log.isDebugEnabled()) + log.debug("authenticate(" + username + ", " + password + ")"); + + boolean authenticated = false; + LoginCallbackHandler handler = new LoginCallbackHandler(username, password); + try { + LoginContext ctx = new LoginContext(APPLICATION_POLICY_NAME, handler); + ctx.login(); + authenticated = true; + subject = ctx.getSubject(); + + for (Principal p : subject.getPrincipals()) { + if (log.isDebugEnabled()) log.debug("Principal for " + username + ": " + p.toString()); + // Group is a subclass of Principal, and the members are the names of the roles + if ((p instanceof Group) && (ROLES_NAME.equalsIgnoreCase(p.getName()))) { + Group g = (Group) p; + Enumeration<? extends Principal> members = g.members(); + while (members.hasMoreElements()) { + Principal member = members.nextElement(); + roles.add(member.getName()); + if (log.isDebugEnabled()) log.debug("Added role user:"+ username + " role:" + member.getName()); + } + } + } + } catch (LoginException e) { + authenticated = false; + } + return authenticated; + } + + public Roles getRoles() { + return roles; + } + + private class LoginCallbackHandler implements CallbackHandler { + + private String user; + private String passwd; + + public LoginCallbackHandler(String user, String passwd) { + this.user = user; + this.passwd = passwd; + } + + public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { + for (Callback cb : callbacks) { + if (cb instanceof NameCallback) { + ((NameCallback) cb).setName(user); + } else if (cb instanceof PasswordCallback) { + ((PasswordCallback)cb).setPassword(passwd.toCharArray()); + } else { + throw new UnsupportedCallbackException(cb, "Callback not supported! (only Name and Password Callback are supported)"); + } + } + } + + } +} Added: dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/java/org/dcm4chee/web/wicket/LoginPage.java =================================================================== --- dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/java/org/dcm4chee/web/wicket/LoginPage.java (rev 0) +++ dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/java/org/dcm4chee/web/wicket/LoginPage.java 2009-07-27 08:13:57 UTC (rev 11994) @@ -0,0 +1,57 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is part of dcm4che, an implementation of DICOM(TM) in + * Java(TM), hosted at http://sourceforge.net/projects/dcm4che. + * + * The Initial Developer of the Original Code is + * Agfa-Gevaert AG. + * Portions created by the Initial Developer are Copyright (C) 2008 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * See listed authors below. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ +package org.dcm4chee.web.wicket; + +import org.apache.wicket.authentication.panel.SignInPanel; +import org.apache.wicket.markup.html.WebPage; + +/** + * <p/> + * The original implementation checks the length of the top level domain (2 <= x <= 4) but in case of simple hostnames this would be fail! + * + * @author Franz Willer <fra...@gm...> + * @version $Revision$ $Date$ + * @since July 20, 2009 + */ +public class LoginPage extends WebPage +{ + public LoginPage() + { + add(new SignInPanel("signInPanel")); + } +} Modified: dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/java/org/dcm4chee/web/wicket/MainPage.java =================================================================== --- dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/java/org/dcm4chee/web/wicket/MainPage.java 2009-07-24 17:51:41 UTC (rev 11993) +++ dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/java/org/dcm4chee/web/wicket/MainPage.java 2009-07-27 08:13:57 UTC (rev 11994) @@ -38,6 +38,7 @@ package org.dcm4chee.web.wicket; +import org.apache.wicket.authorization.strategies.role.annotations.AuthorizeInstantiation; import org.apache.wicket.markup.html.WebPage; import org.dcm4chee.web.wicket.ae.AEMgtPage; import org.dcm4chee.web.wicket.folder.StudyListPage; @@ -50,7 +51,7 @@ * @version $Revision$ $Date$ * @since July 7, 2009 */ - +@AuthorizeInstantiation({"user","WebUser"}) public class MainPage extends WebPage { private static Logger log = LoggerFactory.getLogger(MainPage.class); Modified: dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/java/org/dcm4chee/web/wicket/WicketApplication.java =================================================================== --- dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/java/org/dcm4chee/web/wicket/WicketApplication.java 2009-07-24 17:51:41 UTC (rev 11993) +++ dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/java/org/dcm4chee/web/wicket/WicketApplication.java 2009-07-27 08:13:57 UTC (rev 11994) @@ -4,6 +4,9 @@ import org.apache.wicket.Request; import org.apache.wicket.Response; import org.apache.wicket.Session; +import org.apache.wicket.authentication.AuthenticatedWebApplication; +import org.apache.wicket.authentication.AuthenticatedWebSession; +import org.apache.wicket.markup.html.WebPage; import org.apache.wicket.protocol.http.WebApplication; /** @@ -12,12 +15,19 @@ * * @see wicket.myproject.Start#main(String[]) */ -public class WicketApplication extends WebApplication { +public class WicketApplication extends AuthenticatedWebApplication { /** * Constructor */ public WicketApplication() { } + + @Override + protected void init() { + super.init(); + getApplicationSettings().setAccessDeniedPage(LoginPage.class); + mountBookmarkablePage("/login", LoginPage.class); + } @Override public Class<? extends Page> getHomePage() { @@ -25,8 +35,13 @@ } @Override - public Session newSession(Request request, Response response) { - return new WicketSession(request); + protected Class<? extends WebPage> getSignInPageClass() { + return LoginPage.class; } + @Override + protected Class<? extends AuthenticatedWebSession> getWebSessionClass() { + return JaasWicketSession.class; + } + } Modified: dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/java/org/dcm4chee/web/wicket/WicketSession.java =================================================================== --- dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/java/org/dcm4chee/web/wicket/WicketSession.java 2009-07-24 17:51:41 UTC (rev 11993) +++ dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/java/org/dcm4chee/web/wicket/WicketSession.java 2009-07-27 08:13:57 UTC (rev 11994) @@ -39,7 +39,8 @@ package org.dcm4chee.web.wicket; import org.apache.wicket.Request; -import org.apache.wicket.protocol.http.WebSession; +import org.apache.wicket.authentication.AuthenticatedWebSession; +import org.apache.wicket.authorization.strategies.role.Roles; import org.dcm4chee.web.wicket.folder.ViewPort; /** @@ -47,9 +48,10 @@ * @version $Revision$ $Date$ * @since Jan 13, 2009 */ -public class WicketSession extends WebSession { +public class WicketSession extends AuthenticatedWebSession { private ViewPort viewport = new ViewPort(); + private String username; public WicketSession(Request request) { super(request); @@ -58,4 +60,20 @@ public ViewPort getViewPort() { return viewport; } + + @Override + public boolean authenticate(String username, String password) { + boolean success = username.equals(password); + if ( success ) + this.username = username; + return success; + } + + @Override + public Roles getRoles() { + Roles roles = new Roles(); + if ( isSignedIn() ) + roles.add("user"); + return roles; + } } Modified: dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/java/org/dcm4chee/web/wicket/util/JNDIUtils.java =================================================================== --- dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/java/org/dcm4chee/web/wicket/util/JNDIUtils.java 2009-07-24 17:51:41 UTC (rev 11993) +++ dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/java/org/dcm4chee/web/wicket/util/JNDIUtils.java 2009-07-27 08:13:57 UTC (rev 11994) @@ -53,11 +53,12 @@ try { return jndiCtx.lookup(name); } finally { - jndiCtx.close(); + try { + jndiCtx.close(); + } catch ( Exception ignore ) {} } } catch (Exception e) { throw new RuntimeException(e); } } - } Added: dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/resources/org/dcm4chee/web/wicket/LoginPage.html =================================================================== --- dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/resources/org/dcm4chee/web/wicket/LoginPage.html (rev 0) +++ dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/main/resources/org/dcm4chee/web/wicket/LoginPage.html 2009-07-27 08:13:57 UTC (rev 11994) @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" + xmlns:wicket="http://wicket.sourceforge.net/"> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <title>Please Log In</title> + </head> + <body> + <div wicket:id="signInPanel"/> + </body> +</html> Added: dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/java/org/dcm4chee/web/wicket/WicketApplicationTest.java =================================================================== --- dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/java/org/dcm4chee/web/wicket/WicketApplicationTest.java (rev 0) +++ dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/java/org/dcm4chee/web/wicket/WicketApplicationTest.java 2009-07-27 08:13:57 UTC (rev 11994) @@ -0,0 +1,98 @@ +package org.dcm4chee.web.wicket; + + +import java.net.URL; + +import org.apache.wicket.Page; +import org.apache.wicket.util.tester.FormTester; +import org.apache.wicket.util.tester.WicketTester; +import org.dcm4chee.archive.entity.AE; +import org.dcm4chee.archive.entity.Code; +import org.dcm4chee.archive.entity.File; +import org.dcm4chee.archive.entity.FileSystem; +import org.dcm4chee.archive.entity.GPPPS; +import org.dcm4chee.archive.entity.GPSPS; +import org.dcm4chee.archive.entity.GPSPSPerformer; +import org.dcm4chee.archive.entity.GPSPSRequest; +import org.dcm4chee.archive.entity.Instance; +import org.dcm4chee.archive.entity.MPPS; +import org.dcm4chee.archive.entity.MWLItem; +import org.dcm4chee.archive.entity.Media; +import org.dcm4chee.archive.entity.OtherPatientID; +import org.dcm4chee.archive.entity.Patient; +import org.dcm4chee.archive.entity.RequestAttributes; +import org.dcm4chee.archive.entity.Series; +import org.dcm4chee.archive.entity.Study; +import org.dcm4chee.archive.entity.StudyOnFileSystem; +import org.dcm4chee.archive.entity.VerifyingObserver; +import org.dcm4chee.web.dao.StudyListBean; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.bm.testsuite.BaseSessionBeanFixture; + +public class WicketApplicationTest extends BaseSessionBeanFixture<StudyListBean> +{ + private WicketApplication testApplicaton; + private WicketTester wicketTester; + + private static final Class<?>[] usedBeans = {Patient.class, Study.class, Series.class, Instance.class, + File.class, FileSystem.class, StudyOnFileSystem.class, VerifyingObserver.class, + Media.class, MPPS.class, GPSPS.class, GPPPS.class, GPSPSRequest.class, GPSPSPerformer.class, + MWLItem.class, + OtherPatientID.class, AE.class, RequestAttributes.class, Code.class}; + private static Logger log = LoggerFactory.getLogger(WicketApplicationTest.class); + + public WicketApplicationTest() throws Exception { + super(StudyListBean.class, usedBeans); + } + @Override + public void setUp() throws Exception + { + super.setUp(); + testApplicaton = new WicketApplication(); + wicketTester = new WicketTester(testApplicaton); + URL url = this.getClass().getResource("/wicket.login.file"); + //Set login configuration file! '=' means: overwrite other login configuration given in Java security properties file. + System.setProperty("java.security.auth.login.config", "="+url.getPath()); + } + + @Test + public void testShouldAuthChallenge() + { + wicketTester.startPage(MainPage.class); + wicketTester.assertRenderedPage(LoginPage.class); + } + + @Test + public void testAdminLoginShouldAllow() { + checkLogin("admin", "admin", MainPage.class); + } + @Test + public void testAdminLoginShouldFail() { + checkLogin("admin", "admon", LoginPage.class); + } + @Test + public void testUserLoginShouldAllow() { + checkLogin("user", "user", MainPage.class); + } + @Test + public void testUserLoginShouldFail() { + checkLogin("user", "wrong", LoginPage.class); + } + @Test + public void testUnknownLoginShouldFail() { + checkLogin("unknown", "unknown", LoginPage.class); + } + private void checkLogin(String user, String passwd, Class pageClass) { + wicketTester.startPage(MainPage.class); + FormTester formTester = wicketTester.newFormTester("signInPanel:signInForm"); + formTester.setValue("username", user); + formTester.setValue("password", passwd); + formTester.submit(); + wicketTester.assertRenderedPage(pageClass); + } + +} Added: dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/resources/ejb3unit.properties =================================================================== --- dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/resources/ejb3unit.properties (rev 0) +++ dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/resources/ejb3unit.properties 2009-07-27 08:13:57 UTC (rev 11994) @@ -0,0 +1,15 @@ +### The ejb3unit configuration file ### + +### USE THIS FOR JUNIT IN MEMORY TESTS (Unit testing without a database)## +ejb3unit.inMemoryTest=true + +### Other configuration values ## +ejb3unit.show_sql=false + + +## JNDI bindings ## +ejb3unit_jndi.1.isSessionBean=true +ejb3unit_jndi.1.jndiName=dcm4chee-web-ear/StudyListBean/local +ejb3unit_jndi.1.className=org.dcm4chee.web.dao.StudyListBean + +##values are create-drop, create, update ## \ No newline at end of file Added: dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/resources/jndi.properties =================================================================== --- dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/resources/jndi.properties (rev 0) +++ dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/resources/jndi.properties 2009-07-27 08:13:57 UTC (rev 11994) @@ -0,0 +1 @@ +java.naming.factory.initial=com.bm.jndi.MemoryContextFactory \ No newline at end of file Added: dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/resources/log4j.properties =================================================================== --- dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/resources/log4j.properties (rev 0) +++ dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/resources/log4j.properties 2009-07-27 08:13:57 UTC (rev 11994) @@ -0,0 +1,12 @@ +log4j.appender.Stdout=org.apache.log4j.ConsoleAppender +log4j.appender.Stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.Stdout.layout.conversionPattern=%-5p - %-26.26c{1} - %m\n + +log4j.rootLogger=INFO,Stdout + +log4j.logger.wicket=INFO +log4j.logger.wicket.protocol.http.HttpSessionStore=INFO +log4j.logger.wicket.version=INFO +log4j.logger.wicket.RequestCycle=INFO + + Added: dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/resources/roles.properties =================================================================== --- dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/resources/roles.properties (rev 0) +++ dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/resources/roles.properties 2009-07-27 08:13:57 UTC (rev 11994) @@ -0,0 +1,4 @@ +admin=WebUser,WebAdmin,Doctor,JBossAdmin,AuditLogUser +user=WebUser,AuditLogUser +doc=WebUser,Doctor,AuditLogUser +guest=WebUser \ No newline at end of file Added: dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/resources/users.properties =================================================================== --- dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/resources/users.properties (rev 0) +++ dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/resources/users.properties 2009-07-27 08:13:57 UTC (rev 11994) @@ -0,0 +1,4 @@ +admin=admin +user=user +doc=doc +guest=guest Added: dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/resources/wicket.login.file =================================================================== --- dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/resources/wicket.login.file (rev 0) +++ dcm4chee/dcm4chee-web/trunk/dcm4chee-web-war/src/test/resources/wicket.login.file 2009-07-27 08:13:57 UTC (rev 11994) @@ -0,0 +1,3 @@ + dcm4chee { + org.jboss.security.auth.spi.UsersRolesLoginModule required; + }; \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |