Removed unused class fields to prevent static
[aaf/authz.git] / auth / auth-hello / src / main / java / org / onap / aaf / auth / hello / AAF_Hello.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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====================================================
19  *
20  */
21
22
23 package org.onap.aaf.auth.hello;
24
25 import java.util.Map;
26
27 import javax.servlet.Filter;
28
29 import org.onap.aaf.auth.env.AuthzEnv;
30 import org.onap.aaf.auth.env.AuthzTrans;
31 import org.onap.aaf.auth.env.AuthzTransFilter;
32 import org.onap.aaf.auth.rserv.HttpCode;
33 import org.onap.aaf.auth.rserv.HttpMethods;
34 import org.onap.aaf.auth.server.AbsService;
35 import org.onap.aaf.auth.server.JettyServiceStarter;
36 import org.onap.aaf.auth.server.Log4JLogIt;
37 import org.onap.aaf.cadi.CadiException;
38 import org.onap.aaf.cadi.LocatorException;
39 import org.onap.aaf.cadi.PropAccess;
40 import org.onap.aaf.cadi.aaf.v2_0.AAFAuthn;
41 import org.onap.aaf.cadi.aaf.v2_0.AAFLurPerm;
42 import org.onap.aaf.cadi.aaf.v2_0.AAFTrustChecker;
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;
47 import org.onap.aaf.misc.env.Env;
48
49 public class AAF_Hello extends AbsService<AuthzEnv,AuthzTrans> {
50     public enum API{TOKEN_REQ, TOKEN,INTROSPECT, ERROR,VOID};
51     public AAFAuthn<?> aafAuthn;
52     public AAFLurPerm aafLurPerm;
53
54     /**
55      * Construct AuthzAPI with all the Context Supporting Routes that Authz needs
56      *
57      * @param env
58      * @throws APIException
59      */
60     public AAF_Hello(final AuthzEnv env) throws Exception {
61         super(env.access(), env);
62
63         aafLurPerm = aafCon().newLur();
64         // Note: If you need both Authn and Authz construct the following:
65         aafAuthn = aafCon().newAuthn(aafLurPerm);
66
67         String aaf_env = env.getProperty(Config.AAF_ENV);
68         if (aaf_env==null) {
69             throw new APIException("aaf_env needs to be set");
70         }
71
72         // Initialize Facade for all uses
73         AuthzTrans trans = env.newTrans();
74         StringBuilder sb = new StringBuilder();
75         trans.auditTrail(2, sb);
76         trans.init().log(sb);
77
78         API_Hello.init(this);
79 }
80
81     /**
82      * Setup XML and JSON implementations for each supported Version type
83      *
84      * We do this by taking the Code passed in and creating clones of these with the appropriate Facades and properties
85      * to do Versions and Content switches
86      *
87      */
88     public void route(HttpMethods meth, String path, API api, HttpCode<AuthzTrans, AAF_Hello> code){
89         String version = "1.0";
90         // Get Correct API Class from Mapper
91         route(env,meth,path,code,"text/plain;version="+version,"*/*");
92     }
93
94     @Override
95     public Filter[] _filters(Object ... additionalTafLurs) throws CadiException, LocatorException {
96         try {
97             return new Filter[] {
98                     new AuthzTransFilter(env,aafCon(),
99                         new AAFTrustChecker((Env)env),
100                         additionalTafLurs)
101                 };
102         } catch (NumberFormatException e) {
103             throw new CadiException("Invalid Property information", e);
104         }
105     }
106
107     @SuppressWarnings("unchecked")
108     @Override
109     public Registrant<AuthzEnv>[] registrants(final int port) throws CadiException, LocatorException {
110         return new Registrant[] {
111             new RemoteRegistrant<AuthzEnv>(aafCon(),port)
112         };
113     }
114
115     public static void main(final String[] args) {
116         try {
117             Log4JLogIt logIt = new Log4JLogIt(args, "hello");
118             PropAccess propAccess = new PropAccess(logIt,args);
119
120             try {
121                 new JettyServiceStarter<AuthzEnv,AuthzTrans>(
122                     new AAF_Hello(new AuthzEnv(propAccess)),true)
123                         .start();
124             } catch (Exception e) {
125                 propAccess.log(e);
126             }
127         } catch (Exception e) {
128             e.printStackTrace();
129         }
130     }
131 }