/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package com.myastronomy.resource; import io.milton.http.Auth; import io.milton.http.Request; import io.milton.http.Request.Method; import io.milton.http.http11.auth.DigestGenerator; import io.milton.http.http11.auth.DigestResponse; import io.milton.resource.DigestResource; import io.milton.resource.PropFindableResource; import java.util.Date; /** * * */ public abstract class AbstractResource implements DigestResource, PropFindableResource { private static org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(AbstractResource.class); public AbstractResource() { } @Override public Object authenticate(String user, String requestedPassword) { if( user.equals("user") && requestedPassword.equals("password")) { return user; } return null; } @Override public Object authenticate(DigestResponse digestRequest) { if (digestRequest.getUser().equals("user")) { DigestGenerator gen = new DigestGenerator(); String actual = gen.generateDigest(digestRequest, "password"); if (actual.equals(digestRequest.getResponseDigest())) { return digestRequest.getUser(); } else { log.warn("that password is incorrect. Try 'password'"); } } else { log.warn("user not found: " + digestRequest.getUser() + " - try 'user'"); } return null; } @Override public String getUniqueId() { return null; } @Override public String checkRedirect(Request request) { return null; } @Override public boolean authorise(Request request, Method method, Auth auth) { log.debug("authorise"); return auth != null; } @Override public String getRealm() { return "testrealm@host.com"; } @Override public Date getModifiedDate() { return null; } @Override public Date getCreateDate() { return null; } @Override public boolean isDigestAllowed() { return true; } }