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;
27 import javax.servlet.Filter;
29 import org.onap.aaf.auth.cache.Cache.Dated;
30 import org.onap.aaf.auth.env.AuthzEnv;
31 import org.onap.aaf.auth.env.AuthzTrans;
32 import org.onap.aaf.auth.env.AuthzTransFilter;
33 import org.onap.aaf.auth.rserv.HttpCode;
34 import org.onap.aaf.auth.rserv.HttpMethods;
35 import org.onap.aaf.auth.server.AbsService;
36 import org.onap.aaf.auth.server.JettyServiceStarter;
37 import org.onap.aaf.auth.server.Log4JLogIt;
38 import org.onap.aaf.cadi.CadiException;
39 import org.onap.aaf.cadi.LocatorException;
40 import org.onap.aaf.cadi.PropAccess;
41 import org.onap.aaf.cadi.aaf.v2_0.AAFAuthn;
42 import org.onap.aaf.cadi.aaf.v2_0.AAFLurPerm;
43 import org.onap.aaf.cadi.aaf.v2_0.AAFTrustChecker;
44 import org.onap.aaf.cadi.config.Config;
45 import org.onap.aaf.cadi.register.Registrant;
46 import org.onap.aaf.cadi.register.RemoteRegistrant;
47 import org.onap.aaf.misc.env.APIException;
48 import org.onap.aaf.misc.env.Env;
50 public class AAF_Hello extends AbsService<AuthzEnv,AuthzTrans> {
51 public enum API{TOKEN_REQ, TOKEN,INTROSPECT, ERROR,VOID};
52 public Map<String, Dated> cacheUser;
53 public AAFAuthn<?> aafAuthn;
54 public AAFLurPerm aafLurPerm;
57 * Construct AuthzAPI with all the Context Supporting Routes that Authz needs
63 * @throws APIException
65 public AAF_Hello(final AuthzEnv env) throws Exception {
66 super(env.access(), env);
68 aafLurPerm = aafCon().newLur();
69 // Note: If you need both Authn and Authz construct the following:
70 aafAuthn = aafCon().newAuthn(aafLurPerm);
72 String aaf_env = env.getProperty(Config.AAF_ENV);
74 throw new APIException("aaf_env needs to be set");
77 // Initialize Facade for all uses
78 AuthzTrans trans = env.newTrans();
79 StringBuilder sb = new StringBuilder();
80 trans.auditTrail(2, sb);
87 * Setup XML and JSON implementations for each supported Version type
89 * We do this by taking the Code passed in and creating clones of these with the appropriate Facades and properties
90 * to do Versions and Content switches
93 public void route(HttpMethods meth, String path, API api, HttpCode<AuthzTrans, AAF_Hello> code) throws Exception {
94 String version = "1.0";
95 // Get Correct API Class from Mapper
96 route(env,meth,path,code,"text/plain;version="+version,"*/*");
100 public Filter[] _filters(Object ... additionalTafLurs) throws CadiException, LocatorException {
102 return new Filter[] {
103 new AuthzTransFilter(env,aafCon(),
104 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(),port)
120 public static void main(final String[] args) {
122 Log4JLogIt logIt = new Log4JLogIt(args, "hello");
123 PropAccess propAccess = new PropAccess(logIt,args);
125 AAF_Hello service = new AAF_Hello(new AuthzEnv(propAccess));
126 JettyServiceStarter<AuthzEnv,AuthzTrans> jss = new JettyServiceStarter<AuthzEnv,AuthzTrans>(service);
128 } catch (Exception e) {