2
* Copyright 2005-2012 Restlet S.A.S.
4
* The contents of this file are subject to the terms of one of the following
5
* open source licenses: Apache 2.0 or LGPL 3.0 or LGPL 2.1 or CDDL 1.0 or EPL
6
* 1.0 (the "Licenses"). You can select the license that you prefer but you may
7
* not use this file except in compliance with one of these Licenses.
9
* You can obtain a copy of the Apache 2.0 license at
10
* http://www.opensource.org/licenses/apache-2.0
12
* You can obtain a copy of the LGPL 3.0 license at
13
* http://www.opensource.org/licenses/lgpl-3.0
15
* You can obtain a copy of the LGPL 2.1 license at
16
* http://www.opensource.org/licenses/lgpl-2.1
18
* You can obtain a copy of the CDDL 1.0 license at
19
* http://www.opensource.org/licenses/cddl1
21
* You can obtain a copy of the EPL 1.0 license at
22
* http://www.opensource.org/licenses/eclipse-1.0
24
* See the Licenses for the specific language governing permissions and
25
* limitations under the Licenses.
27
* Alternatively, you can obtain a royalty free commercial license with less
28
* limitations, transferable or non-transferable, directly at
29
* http://www.restlet.com/products/restlet-framework
31
* Restlet is a registered trademark of Restlet S.A.S.
34
package org.restlet.example.book.restlet.ch05.sec2;
36
import org.restlet.Application;
37
import org.restlet.Component;
38
import org.restlet.Restlet;
39
import org.restlet.data.ChallengeScheme;
40
import org.restlet.data.Protocol;
41
import org.restlet.example.book.restlet.ch05.EchoPrincipalsResource;
42
import org.restlet.routing.Router;
43
import org.restlet.security.ChallengeAuthenticator;
44
import org.restlet.security.LocalVerifier;
45
import org.restlet.security.MapVerifier;
48
* @author Bruno Harbulot (bruno/distributedmatter.net)
51
public class BasicAuthenticationApplication extends Application {
52
private final LocalVerifier verifier;
54
public BasicAuthenticationApplication() {
55
MapVerifier verifier = new MapVerifier();
56
verifier.getLocalSecrets().put("scott", "tiger".toCharArray());
57
this.verifier = verifier;
61
public synchronized Restlet createInboundRoot() {
62
Router router = new Router(getContext());
63
router.attachDefault(EchoPrincipalsResource.class);
65
ChallengeAuthenticator authenticator = new ChallengeAuthenticator(
66
getContext(), ChallengeScheme.HTTP_BASIC, "Basic Test");
67
authenticator.setVerifier(verifier);
69
authenticator.setNext(router);
73
public static void main(String[] args) throws Exception {
74
Component component = new Component();
75
component.getServers().add(Protocol.HTTP, 8111);
77
component.getDefaultHost().attachDefault(
78
new BasicAuthenticationApplication());