1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * Copyright © 2017 Amdocs
\r
7 * * ===========================================================================
\r
8 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * * you may not use this file except in compliance with the License.
\r
10 * * You may obtain a copy of the License at
\r
12 * * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * * Unless required by applicable law or agreed to in writing, software
\r
15 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * * See the License for the specific language governing permissions and
\r
18 * * limitations under the License.
\r
19 * * ============LICENSE_END====================================================
\r
21 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
23 ******************************************************************************/
\r
24 package com.att.authz.gw;
\r
26 import java.net.HttpURLConnection;
\r
27 import java.util.ArrayList;
\r
28 import java.util.EnumSet;
\r
29 import java.util.List;
\r
30 import java.util.Map;
\r
31 import java.util.Properties;
\r
33 import com.att.aft.dme2.api.DME2Exception;
\r
35 import com.att.aft.dme2.api.DME2Manager;
\r
36 import com.att.aft.dme2.api.DME2Server;
\r
37 import com.att.aft.dme2.api.DME2ServerProperties;
\r
38 import com.att.aft.dme2.api.DME2ServiceHolder;
\r
39 import com.att.aft.dme2.api.util.DME2FilterHolder;
\r
40 import com.att.aft.dme2.api.util.DME2FilterHolder.RequestDispatcherType;
\r
41 import com.att.aft.dme2.api.util.DME2ServletHolder;
\r
42 import com.att.authz.env.AuthzEnv;
\r
43 import com.att.authz.gw.api.API_AAFAccess;
\r
44 import com.att.authz.gw.api.API_Api;
\r
45 import com.att.authz.gw.api.API_Find;
\r
46 import com.att.authz.gw.api.API_Proxy;
\r
47 import com.att.authz.gw.api.API_TGuard;
\r
48 import com.att.authz.gw.facade.GwFacade_1_0;
\r
49 import com.att.authz.gw.mapper.Mapper.API;
\r
50 import com.att.authz.server.AbsServer;
\r
51 import com.att.cache.Cache;
\r
52 import com.att.cache.Cache.Dated;
\r
53 import com.att.cadi.CadiException;
\r
54 //import com.att.cadi.PropAccess;
\r
55 import com.att.cadi.aaf.v2_0.AAFAuthn;
\r
56 import com.att.cadi.aaf.v2_0.AAFLurPerm;
\r
57 import com.att.cadi.config.Config;
\r
58 import com.att.cssa.rserv.HttpMethods;
\r
59 import com.att.inno.env.APIException;
\r
61 public class GwAPI extends AbsServer {
\r
62 private static final String USER_PERMS = "userPerms";
\r
63 private GwFacade_1_0 facade; // this is the default Facade
\r
64 private GwFacade_1_0 facade_1_0_XML;
\r
65 public Map<String, Dated> cacheUser;
\r
66 public final String aafurl;
\r
67 public final AAFAuthn<HttpURLConnection> aafAuthn;
\r
68 public final AAFLurPerm aafLurPerm;
\r
69 public DME2Manager dme2Man;
\r
73 * Construct AuthzAPI with all the Context Supporting Routes that Authz needs
\r
79 * @throws APIException
\r
81 public GwAPI(AuthzEnv env) throws Exception {
\r
82 super(env,"AAF GW");
\r
83 aafurl = env.getProperty(Config.AAF_URL);
\r
86 //env.setLog4JNames("log4j.properties","authz","gw","audit","init","trace");
\r
88 aafLurPerm = aafCon.newLur();
\r
89 // Note: If you need both Authn and Authz construct the following:
\r
90 aafAuthn = aafCon.newAuthn(aafLurPerm);
\r
92 // Initialize Facade for all uses
\r
93 //AuthzTrans trans = env.newTrans();
\r
95 // facade = GwFacadeFactory.v1_0(env,trans,Data.TYPE.JSON); // Default Facade
\r
96 // facade_1_0_XML = GwFacadeFactory.v1_0(env,trans,Data.TYPE.XML);
\r
99 if(cacheUser == null) {
\r
100 cacheUser = Cache.obtain(USER_PERMS);
\r
101 //Cache.startCleansing(env, USER_PERMS);
\r
102 Cache.addShutdownHook(); // Setup Shutdown Hook to close cache
\r
106 ////////////////////////////////////////////////////////////////////////////
\r
108 // These will always be evaluated first
\r
109 ////////////////////////////////////////////////////////////////////////
\r
110 API_AAFAccess.init(this,facade);
\r
111 API_Find.init(this, facade);
\r
112 API_TGuard.init(this, facade);
\r
113 API_Proxy.init(this, facade);
\r
115 ////////////////////////////////////////////////////////////////////////
\r
117 ////////////////////////////////////////////////////////////////////////
\r
118 // There are several APIs around each concept, and it gets a bit too
\r
119 // long in this class to create. The initialization of these Management
\r
120 // APIs have therefore been pushed to StandAlone Classes with static
\r
122 API_Api.init(this, facade);
\r
124 ////////////////////////////////////////////////////////////////////////
\r
125 // Default Function
\r
126 ////////////////////////////////////////////////////////////////////////
\r
127 API_AAFAccess.initDefault(this,facade);
\r
132 * Setup XML and JSON implementations for each supported Version type
\r
134 * We do this by taking the Code passed in and creating clones of these with the appropriate Facades and properties
\r
135 * to do Versions and Content switches
\r
138 public void route(HttpMethods meth, String path, API api, GwCode code) throws Exception {
\r
139 String version = "1.0";
\r
140 // Get Correct API Class from Mapper
\r
141 Class<?> respCls = facade.mapper().getClass(api);
\r
142 if(respCls==null) throw new Exception("Unknown class associated with " + api.getClass().getName() + ' ' + api.name());
\r
143 // setup Application API HTML ContentTypes for JSON and Route
\r
144 String application = applicationJSON(respCls, version);
\r
145 //route(env,meth,path,code,application,"application/json;version="+version,"*/*");
\r
147 // setup Application API HTML ContentTypes for XML and Route
\r
148 application = applicationXML(respCls, version);
\r
149 //route(env,meth,path,code.clone(facade_1_0_XML,false),application,"text/xml;version="+version);
\r
151 // Add other Supported APIs here as created
\r
154 public void routeAll(HttpMethods meth, String path, API api, GwCode code) throws Exception {
\r
155 //route(env,meth,path,code,""); // this will always match
\r
160 * Start up AuthzAPI as DME2 Service
\r
163 * @throws DME2Exception
\r
164 * @throws CadiException
\r
166 public void startDME2(Properties props) throws DME2Exception, CadiException {
\r
168 dme2Man = new DME2Manager("GatewayDME2Manager",props);
\r
170 DME2ServiceHolder svcHolder;
\r
171 List<DME2ServletHolder> slist = new ArrayList<DME2ServletHolder>();
\r
172 svcHolder = new DME2ServiceHolder();
\r
173 String serviceName = env.getProperty("DMEServiceName",null);
\r
174 if(serviceName!=null) {
\r
175 svcHolder.setServiceURI(serviceName);
\r
176 svcHolder.setManager(dme2Man);
\r
177 svcHolder.setContext("/");
\r
181 DME2ServletHolder srvHolder = new DME2ServletHolder(this, new String[] {"/dme2","/api"});
\r
182 srvHolder.setContextPath("/*");
\r
183 slist.add(srvHolder);
\r
185 EnumSet<RequestDispatcherType> edlist = EnumSet.of(
\r
186 RequestDispatcherType.REQUEST,
\r
187 RequestDispatcherType.FORWARD,
\r
188 RequestDispatcherType.ASYNC
\r
191 ///////////////////////
\r
193 ///////////////////////
\r
194 List<DME2FilterHolder> flist = new ArrayList<DME2FilterHolder>();
\r
196 // Leave Login page un secured
\r
197 // AuthzTransOnlyFilter atof = new AuthzTransOnlyFilter(env);
\r
198 // flist.add(new DME2FilterHolder(atof,"/login", edlist));
\r
200 // Secure all other interactions with AuthzTransFilter
\r
201 // flist.add(new DME2FilterHolder(
\r
202 // new AuthzTransFilter(env, aafCon, new AAFTrustChecker(
\r
203 // env.getProperty(Config.CADI_TRUST_PROP, Config.CADI_USER_CHAIN),
\r
204 // Define.ROOT_NS + ".mechid|"+Define.ROOT_COMPANY+"|trust"
\r
209 svcHolder.setFilters(flist);
\r
210 svcHolder.setServletHolders(slist);
\r
212 DME2Server dme2svr = dme2Man.getServer();
\r
213 // dme2svr.setGracefulShutdownTimeMs(1000);
\r
215 // env.init().log("Starting GW Jetty/DME2 server...");
\r
217 DME2ServerProperties dsprops = dme2svr.getServerProperties();
\r
219 // if(env.getProperty("NO_REGISTER",null)!=null)
\r
220 dme2Man.bindService(svcHolder);
\r
221 // env.init().log("DME2 is available as HTTP"+(dsprops.isSslEnable()?"/S":""),"on port:",dsprops.getPort());
\r
223 while(true) { // Per DME2 Examples...
\r
224 Thread.sleep(5000);
\r
226 } catch(InterruptedException e) {
\r
227 // env.init().log("AAF Jetty Server interrupted!");
\r
228 } catch(Exception e) { // Error binding service doesn't seem to stop DME2 or Process
\r
229 // env.init().log(e,"DME2 Initialization Error");
\r
234 //env.init().log("Properties must contain DMEServiceName");
\r
238 public static void main(String[] args) {
\r
239 setup(GwAPI.class,"authGW.props");
\r
242 // public void route(PropAccess env, HttpMethods get, String string, GwCode gwCode, String string2, String string3,
\r
243 // String string4) {
\r
244 // // TODO Auto-generated method stub
\r