[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[List Home]
|
[jetty-commit] r951 - in jetty/branches/jetty-7.0.0.x/example-jetty-embedded: . src src/main/java/org/eclipse/jetty/embedded src/test src/test/resources
|
- From: genie@xxxxxxxxxxx
- Date: Mon, 28 Sep 2009 11:32:17 -0400 (EDT)
- Delivered-to: jetty-commit@eclipse.org
Author: jmcconnell
Date: 2009-09-28 11:32:17 -0400 (Mon, 28 Sep 2009)
New Revision: 951
Added:
jetty/branches/jetty-7.0.0.x/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/SecuredHelloHandler.java
jetty/branches/jetty-7.0.0.x/example-jetty-embedded/src/test/
jetty/branches/jetty-7.0.0.x/example-jetty-embedded/src/test/resources/
jetty/branches/jetty-7.0.0.x/example-jetty-embedded/src/test/resources/realm.properties
Modified:
jetty/branches/jetty-7.0.0.x/example-jetty-embedded/pom.xml
Log:
added example secured hello handler
Modified: jetty/branches/jetty-7.0.0.x/example-jetty-embedded/pom.xml
===================================================================
--- jetty/branches/jetty-7.0.0.x/example-jetty-embedded/pom.xml 2009-09-24 04:34:09 UTC (rev 950)
+++ jetty/branches/jetty-7.0.0.x/example-jetty-embedded/pom.xml 2009-09-28 15:32:17 UTC (rev 951)
@@ -25,6 +25,11 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-security</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-deploy</artifactId>
<version>${project.version}</version>
</dependency>
Added: jetty/branches/jetty-7.0.0.x/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/SecuredHelloHandler.java
===================================================================
--- jetty/branches/jetty-7.0.0.x/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/SecuredHelloHandler.java (rev 0)
+++ jetty/branches/jetty-7.0.0.x/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/SecuredHelloHandler.java 2009-09-28 15:32:17 UTC (rev 951)
@@ -0,0 +1,64 @@
+// ========================================================================
+// Copyright (c) 2006-2009 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+
+package org.eclipse.jetty.embedded;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.jetty.http.security.Constraint;
+import org.eclipse.jetty.security.ConstraintMapping;
+import org.eclipse.jetty.security.ConstraintSecurityHandler;
+import org.eclipse.jetty.security.HashLoginService;
+import org.eclipse.jetty.security.LoginService;
+import org.eclipse.jetty.security.authentication.BasicAuthenticator;
+import org.eclipse.jetty.server.Server;
+
+public class SecuredHelloHandler
+{
+ public static void main(String[] args) throws Exception
+ {
+ Server server = new Server(0);
+
+ LoginService loginService = new HashLoginService("MyRealm","src/test/resources/realm.properties");
+ server.addBean(loginService);
+
+ ConstraintSecurityHandler security = new ConstraintSecurityHandler();
+ server.setHandler(security);
+
+ Constraint constraint = new Constraint();
+ constraint.setName("auth");
+ constraint.setAuthenticate( true );
+ constraint.setRoles(new String[]{"user", "admin"});
+
+ ConstraintMapping mapping = new ConstraintMapping();
+ mapping.setPathSpec( "/*" );
+ mapping.setConstraint( constraint );
+
+ Set<String> knownRoles = new HashSet<String>();
+ knownRoles.add("user");
+ knownRoles.add("admin");
+
+ security.setConstraintMappings(new ConstraintMapping[] {mapping}, knownRoles);
+ security.setAuthenticator(new BasicAuthenticator());
+ security.setLoginService(loginService);
+ security.setStrict(false);
+
+ HelloHandler hh = new HelloHandler();
+
+ security.setHandler(hh);
+
+ server.start();
+ server.join();
+ }
+}
Added: jetty/branches/jetty-7.0.0.x/example-jetty-embedded/src/test/resources/realm.properties
===================================================================
--- jetty/branches/jetty-7.0.0.x/example-jetty-embedded/src/test/resources/realm.properties (rev 0)
+++ jetty/branches/jetty-7.0.0.x/example-jetty-embedded/src/test/resources/realm.properties 2009-09-28 15:32:17 UTC (rev 951)
@@ -0,0 +1,22 @@
+#
+# This file defines users passwords and roles for a HashUserRealm
+#
+# The format is
+# <username>: <password>[,<rolename> ...]
+#
+# Passwords may be clear text, obfuscated or checksummed. The class
+# org.eclipse.util.Password should be used to generate obfuscated
+# passwords or password checksums
+#
+# If DIGEST Authentication is used, the password must be in a recoverable
+# format, either plain text or OBF:.
+#
+# if using digest authentication, do not MD5-hash the password
+jetty: jetty,user
+admin: CRYPT:ad1ks..kc.1Ug,server-administrator,content-administrator,admin,user
+other: OBF:1xmk1w261u9r1w1c1xmq,user
+plain: plain,user
+user: password,user
+
+# This entry is for digest auth. The credential is a MD5 hash of username:realmname:password
+digest: MD5:6e120743ad67abfbc385bc2bb754e297,user