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;
27 import java.io.IOException;
29 import javax.servlet.Filter;
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
33 import org.onap.aaf.auth.env.AuthzEnv;
34 import org.onap.aaf.auth.env.AuthzTrans;
35 import org.onap.aaf.auth.env.AuthzTransOnlyFilter;
36 import org.onap.aaf.auth.rserv.CachingFileAccess;
37 import org.onap.aaf.auth.rserv.HttpCode;
38 import org.onap.aaf.auth.server.AbsService;
39 import org.onap.aaf.auth.server.JettyServiceStarter;
40 import org.onap.aaf.auth.server.Log4JLogIt;
41 import org.onap.aaf.cadi.Access.Level;
42 import org.onap.aaf.cadi.CadiException;
43 import org.onap.aaf.cadi.LocatorException;
44 import org.onap.aaf.cadi.PropAccess;
45 import org.onap.aaf.cadi.config.Config;
46 import org.onap.aaf.cadi.register.Registrant;
47 import org.onap.aaf.cadi.register.RemoteRegistrant;
48 import org.onap.aaf.misc.env.APIException;
51 public class AAF_FS extends AbsService<AuthzEnv, AuthzTrans> {
53 public AAF_FS(final AuthzEnv env) throws APIException, IOException, CadiException {
54 super(env.access(),env);
56 ///////////////////////
58 ///////////////////////
59 // creates StaticSlot, needed for CachingFileAccess, and sets to public Dir
60 env.staticSlot(CachingFileAccess.CFA_WEB_PATH,"aaf_public_dir");
62 CachingFileAccess<AuthzTrans> cfa = new CachingFileAccess<AuthzTrans>(env);
63 route(env,GET,"/:key", cfa);
64 route(env,GET,"/:key/:cmd", cfa);
65 final String aaf_locate_url = access.getProperty(Config.AAF_LOCATE_URL, null);
66 if(aaf_locate_url == null) {
67 access.printf(Level.WARN, "Redirection requires property %s",Config.AAF_LOCATE_URL);
69 route(env,GET,"/", new Redirect(this,aaf_locate_url));
71 } catch (Exception e) {
76 private static class Redirect extends HttpCode<AuthzTrans, AAF_FS> {
77 private final String url;
79 public Redirect(AAF_FS context,String url) {
80 super(context, "Redirect to HTTP/S");
85 public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception {
86 trans.info().printf("Redirecting %s to HTTP/S %s", req.getRemoteAddr(), req.getLocalAddr());
87 resp.sendRedirect(url);
92 public Filter[] filters() throws CadiException, LocatorException {
94 new AuthzTransOnlyFilter(env)
98 @SuppressWarnings("unchecked")
100 public Registrant<AuthzEnv>[] registrants(final int port) throws CadiException, LocatorException {
101 return new Registrant[] {
102 new RemoteRegistrant<AuthzEnv>(aafCon(),app_name,app_version,port)
106 public static void main(final String[] args) {
108 String propsFile = getArg(AAF_LOG4J_PREFIX, args, "org.osaaf")+".log4j.props";
109 String log_dir = getArg(Config.CADI_LOGDIR,args,"./logs");
110 String log_level = getArg(Config.CADI_LOGLEVEL,args,"INFO");
111 File logs = new File(log_dir);
112 if(!logs.isDirectory()) {
118 Log4JLogIt logIt = new Log4JLogIt(log_dir,log_level,propsFile, "fs");
119 PropAccess propAccess = new PropAccess(logIt,args);
121 AAF_FS service = new AAF_FS(new AuthzEnv(propAccess));
122 JettyServiceStarter<AuthzEnv,AuthzTrans> jss = new JettyServiceStarter<AuthzEnv,AuthzTrans>(service);
123 jss.insecure().start();
124 } catch (Exception e) {