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====================================================
23 package org.onap.aaf.auth.hello;
28 import javax.servlet.Filter;
30 import org.onap.aaf.auth.cache.Cache.Dated;
31 import org.onap.aaf.auth.env.AuthzEnv;
32 import org.onap.aaf.auth.env.AuthzTrans;
33 import org.onap.aaf.auth.env.AuthzTransFilter;
34 import org.onap.aaf.auth.rserv.HttpCode;
35 import org.onap.aaf.auth.rserv.HttpMethods;
36 import org.onap.aaf.auth.server.AbsService;
37 import org.onap.aaf.auth.server.JettyServiceStarter;
38 import org.onap.aaf.auth.server.Log4JLogIt;
39 import org.onap.aaf.cadi.CadiException;
40 import org.onap.aaf.cadi.LocatorException;
41 import org.onap.aaf.cadi.PropAccess;
42 import org.onap.aaf.cadi.aaf.v2_0.AAFAuthn;
43 import org.onap.aaf.cadi.aaf.v2_0.AAFLurPerm;
44 import org.onap.aaf.cadi.aaf.v2_0.AAFTrustChecker;
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;
49 import org.onap.aaf.misc.env.Env;
51 public class AAF_Hello extends AbsService<AuthzEnv,AuthzTrans> {
52 public enum API{TOKEN_REQ, TOKEN,INTROSPECT, ERROR,VOID};
53 public Map<String, Dated> cacheUser;
54 public AAFAuthn<?> aafAuthn;
55 public AAFLurPerm aafLurPerm;
58 * Construct AuthzAPI with all the Context Supporting Routes that Authz needs
64 * @throws APIException
66 public AAF_Hello(final AuthzEnv env) throws Exception {
67 super(env.access(), env);
69 aafLurPerm = aafCon().newLur();
70 // Note: If you need both Authn and Authz construct the following:
71 aafAuthn = aafCon().newAuthn(aafLurPerm);
73 String aaf_env = env.getProperty(Config.AAF_ENV);
75 throw new APIException("aaf_env needs to be set");
78 // Initialize Facade for all uses
79 AuthzTrans trans = env.newTrans();
80 StringBuilder sb = new StringBuilder();
81 trans.auditTrail(2, sb);
88 * Setup XML and JSON implementations for each supported Version type
90 * We do this by taking the Code passed in and creating clones of these with the appropriate Facades and properties
91 * to do Versions and Content switches
94 public void route(HttpMethods meth, String path, API api, HttpCode<AuthzTrans, AAF_Hello> code) throws Exception {
95 String version = "1.0";
96 // Get Correct API Class from Mapper
97 route(env,meth,path,code,"text/plain;version="+version,"*/*");
101 public Filter[] filters() throws CadiException, LocatorException {
103 return new Filter[] {
104 new AuthzTransFilter(env,aafCon(),
105 new AAFTrustChecker((Env)env))
107 } catch (NumberFormatException e) {
108 throw new CadiException("Invalid Property information", e);
112 @SuppressWarnings("unchecked")
114 public Registrant<AuthzEnv>[] registrants(final int port) throws CadiException, LocatorException {
115 return new Registrant[] {
116 new RemoteRegistrant<AuthzEnv>(aafCon(),app_name,app_version,port)
120 public static void main(final String[] args) {
122 String propsFile = getArg(AAF_LOG4J_PREFIX, args, "org.osaaf")+".log4j.props";
123 String log_dir = getArg(Config.CADI_LOGDIR,args,"./logs");
124 String log_level = getArg(Config.CADI_LOGLEVEL,args,"INFO");
125 File logs = new File(log_dir);
126 if(!logs.isDirectory()) {
132 Log4JLogIt logIt = new Log4JLogIt(log_dir,log_level,propsFile, "hello");
133 PropAccess propAccess = new PropAccess(logIt,args);
135 AAF_Hello service = new AAF_Hello(new AuthzEnv(propAccess));
136 JettyServiceStarter<AuthzEnv,AuthzTrans> jss = new JettyServiceStarter<AuthzEnv,AuthzTrans>(service);
138 } catch (Exception e) {