2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
22 package org.onap.aaf.auth.fs;
24 import static org.onap.aaf.auth.rserv.HttpMethods.GET;
26 import java.io.IOException;
28 import javax.servlet.Filter;
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
32 import org.onap.aaf.auth.env.AuthzEnv;
33 import org.onap.aaf.auth.env.AuthzTrans;
34 import org.onap.aaf.auth.env.AuthzTransOnlyFilter;
35 import org.onap.aaf.auth.rserv.CachingFileAccess;
36 import org.onap.aaf.auth.rserv.HttpCode;
37 import org.onap.aaf.auth.server.AbsService;
38 import org.onap.aaf.auth.server.JettyServiceStarter;
39 import org.onap.aaf.cadi.Access.Level;
40 import org.onap.aaf.cadi.CadiException;
41 import org.onap.aaf.cadi.LocatorException;
42 import org.onap.aaf.cadi.PropAccess;
43 import org.onap.aaf.cadi.config.Config;
44 import org.onap.aaf.cadi.register.Registrant;
45 import org.onap.aaf.cadi.register.RemoteRegistrant;
46 import org.onap.aaf.misc.env.APIException;
49 public class AAF_FS extends AbsService<AuthzEnv, AuthzTrans> {
51 public AAF_FS(final AuthzEnv env) throws APIException, IOException, CadiException {
52 super(env.access(),env);
54 ///////////////////////
56 ///////////////////////
57 // creates StaticSlot, needed for CachingFileAccess, and sets to public Dir
58 env.staticSlot(CachingFileAccess.CFA_WEB_PATH,"aaf_public_dir");
60 CachingFileAccess<AuthzTrans> cfa = new CachingFileAccess<AuthzTrans>(env);
61 route(env,GET,"/:key", cfa);
62 route(env,GET,"/:key/:cmd", cfa);
63 final String aaf_locate_url = access.getProperty(Config.AAF_LOCATE_URL, null);
64 if(aaf_locate_url == null) {
65 access.printf(Level.WARN, "Redirection requires property %s",Config.AAF_LOCATE_URL);
67 route(env,GET,"/", new Redirect(this,aaf_locate_url));
69 } catch (Exception e) {
74 private static class Redirect extends HttpCode<AuthzTrans, AAF_FS> {
75 private final String url;
77 public Redirect(AAF_FS context,String url) {
78 super(context, "Redirect to HTTP/S");
83 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
84 trans.info().printf("Redirecting %s to HTTP/S %s", req.getRemoteAddr(), req.getLocalAddr());
85 resp.sendRedirect(url);
90 public Filter[] filters() throws CadiException, LocatorException {
92 new AuthzTransOnlyFilter(env)
96 @SuppressWarnings("unchecked")
98 public Registrant<AuthzEnv>[] registrants(final int port) throws CadiException, LocatorException {
99 return new Registrant[] {
100 new RemoteRegistrant<AuthzEnv>(aafCon(),app_name,app_version,port)
104 public static void main(final String[] args) {
105 PropAccess propAccess = new PropAccess(args);
107 AAF_FS service = new AAF_FS(new AuthzEnv(propAccess));
108 // env.setLog4JNames("log4j.properties","authz","fs","audit","init",null);
109 JettyServiceStarter<AuthzEnv,AuthzTrans> jss = new JettyServiceStarter<AuthzEnv,AuthzTrans>(service);
110 jss.insecure().start();
111 } catch (Exception e) {