From 71037c39a37d3549dcfe31926832a657744fbe05 Mon Sep 17 00:00:00 2001 From: Instrumental Date: Mon, 26 Mar 2018 13:51:48 -0700 Subject: AT&T 2.0.19 Code drop, stage 3 Issue-ID: AAF-197 Change-Id: I8b02cb073ccba318ccaf6ea0276446bdce88fb82 Signed-off-by: Instrumental --- auth/auth-fs/src/main/config/.gitignore | 1 + auth/auth-fs/src/main/config/FileServer.props | 23 +++++ auth/auth-fs/src/main/data/favicon.ico | Bin 0 -> 3638 bytes auth/auth-fs/src/main/data/test.html | 20 ++++ .../src/main/java/org/onap/aaf/auth/fs/AAF_FS.java | 115 +++++++++++++++++++++ .../org/onap/aaf/auth/fs/test/JU_FileServer.java | 81 +++++++++++++++ 6 files changed, 240 insertions(+) create mode 100644 auth/auth-fs/src/main/config/.gitignore create mode 100644 auth/auth-fs/src/main/config/FileServer.props create mode 100644 auth/auth-fs/src/main/data/favicon.ico create mode 100644 auth/auth-fs/src/main/data/test.html create mode 100644 auth/auth-fs/src/main/java/org/onap/aaf/auth/fs/AAF_FS.java create mode 100644 auth/auth-fs/src/test/java/org/onap/aaf/auth/fs/test/JU_FileServer.java (limited to 'auth/auth-fs/src') diff --git a/auth/auth-fs/src/main/config/.gitignore b/auth/auth-fs/src/main/config/.gitignore new file mode 100644 index 00000000..e53ef90a --- /dev/null +++ b/auth/auth-fs/src/main/config/.gitignore @@ -0,0 +1 @@ +/log4j.properties diff --git a/auth/auth-fs/src/main/config/FileServer.props b/auth/auth-fs/src/main/config/FileServer.props new file mode 100644 index 00000000..9c123307 --- /dev/null +++ b/auth/auth-fs/src/main/config/FileServer.props @@ -0,0 +1,23 @@ +## +## AUTHZ API (authz-service) Properties +## + +hostname=_HOSTNAME_ + +## DISCOVERY (DME2) Parameters on the Command Line +AFT_LATITUDE=_AFT_LATITUDE_ +AFT_LONGITUDE=_AFT_LONGITUDE_ +AFT_ENVIRONMENT=_AFT_ENVIRONMENT_ +DEPLOYED_VERSION=_ARTIFACT_VERSION_ + +cadi_prop_files=/opt/app/aaf/common/com.att.aaf.common.props:/opt/app/aaf/common/com.att.aaf.props + +DMEServiceName=service=com.att.authz.authz-fs/version=_MAJOR_VER_._MINOR_VER_._PATCH_VER_/envContext=_ENV_CONTEXT_/routeOffer=_ROUTE_OFFER_ +AFT_DME2_PORT_RANGE=_AUTHZ_FS_PORT_RANGE_ +AFT_DME2_SSL_ENABLE=false +AFT_DME2_DISABLE_PERSISTENT_CACHE=true + +CFA_WebPath=/opt/app/aaf/public +CFA_ClearCommand=FmzYPpMY918MwE1hyacoiFSt +CFA_MaxSize=2000000 + diff --git a/auth/auth-fs/src/main/data/favicon.ico b/auth/auth-fs/src/main/data/favicon.ico new file mode 100644 index 00000000..3aea2722 Binary files /dev/null and b/auth/auth-fs/src/main/data/favicon.ico differ diff --git a/auth/auth-fs/src/main/data/test.html b/auth/auth-fs/src/main/data/test.html new file mode 100644 index 00000000..ec50246c --- /dev/null +++ b/auth/auth-fs/src/main/data/test.html @@ -0,0 +1,20 @@ + + + + AT&T Authentication/Authorization Tool + + + +
+

AT&T Auth Tool on _ENV_CONTEXT_

+

AAF Version: _ARTIFACT_VERSION_

+
+

Success for File Server Access

+ + diff --git a/auth/auth-fs/src/main/java/org/onap/aaf/auth/fs/AAF_FS.java b/auth/auth-fs/src/main/java/org/onap/aaf/auth/fs/AAF_FS.java new file mode 100644 index 00000000..50791393 --- /dev/null +++ b/auth/auth-fs/src/main/java/org/onap/aaf/auth/fs/AAF_FS.java @@ -0,0 +1,115 @@ +/** + * ============LICENSE_START==================================================== + * org.onap.aaf + * =========================================================================== + * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * =========================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END==================================================== + * + */ + +package org.onap.aaf.auth.fs; + +import static org.onap.aaf.auth.rserv.HttpMethods.GET; + +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.onap.aaf.auth.env.AuthzEnv; +import org.onap.aaf.auth.env.AuthzTrans; +import org.onap.aaf.auth.env.AuthzTransOnlyFilter; +import org.onap.aaf.auth.rserv.CachingFileAccess; +import org.onap.aaf.auth.rserv.HttpCode; +import org.onap.aaf.auth.server.AbsService; +import org.onap.aaf.auth.server.JettyServiceStarter; +import org.onap.aaf.cadi.Access.Level; +import org.onap.aaf.cadi.CadiException; +import org.onap.aaf.cadi.LocatorException; +import org.onap.aaf.cadi.PropAccess; +import org.onap.aaf.cadi.config.Config; +import org.onap.aaf.cadi.register.Registrant; +import org.onap.aaf.cadi.register.RemoteRegistrant; +import org.onap.aaf.misc.env.APIException; + + +public class AAF_FS extends AbsService { + + public AAF_FS(final AuthzEnv env) throws APIException, IOException, CadiException { + super(env.access(),env); + try { + /////////////////////// + // File Server + /////////////////////// + // creates StaticSlot, needed for CachingFileAccess, and sets to public Dir + env.staticSlot(CachingFileAccess.CFA_WEB_PATH,"aaf_public_dir"); + + CachingFileAccess cfa = new CachingFileAccess(env); + route(env,GET,"/:key", cfa); + route(env,GET,"/:key/:cmd", cfa); + final String aaf_locate_url = access.getProperty(Config.AAF_LOCATE_URL, null); + if(aaf_locate_url == null) { + access.printf(Level.WARN, "Redirection requires property %s",Config.AAF_LOCATE_URL); + } else { + route(env,GET,"/", new Redirect(this,aaf_locate_url)); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static class Redirect extends HttpCode { + private final String url; + + public Redirect(AAF_FS context,String url) { + super(context, "Redirect to HTTP/S"); + this.url = url; + } + + @Override + public void handle(AuthzTrans trans, HttpServletRequest req, HttpServletResponse resp) throws Exception { + trans.info().printf("Redirecting %s to HTTP/S %s", req.getRemoteAddr(), req.getLocalAddr()); + resp.sendRedirect(url); + } + }; + + @Override + public Filter[] filters() throws CadiException, LocatorException { + return new Filter[] { + new AuthzTransOnlyFilter(env) + }; + } + + @SuppressWarnings("unchecked") + @Override + public Registrant[] registrants(final int port) throws CadiException, LocatorException { + return new Registrant[] { + new RemoteRegistrant(aafCon(),app_name,app_version,port) + }; + } + + public static void main(final String[] args) { + PropAccess propAccess = new PropAccess(args); + try { + AAF_FS service = new AAF_FS(new AuthzEnv(propAccess)); +// env.setLog4JNames("log4j.properties","authz","fs","audit","init",null); + JettyServiceStarter jss = new JettyServiceStarter(service); + jss.insecure().start(); + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/auth/auth-fs/src/test/java/org/onap/aaf/auth/fs/test/JU_FileServer.java b/auth/auth-fs/src/test/java/org/onap/aaf/auth/fs/test/JU_FileServer.java new file mode 100644 index 00000000..6e24f6dc --- /dev/null +++ b/auth/auth-fs/src/test/java/org/onap/aaf/auth/fs/test/JU_FileServer.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * ============LICENSE_START==================================================== + * * org.onap.aaf + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * + ******************************************************************************/ +package org.onap.aaf.auth.fs.test; + +import static org.junit.Assert.*; +import static org.onap.aaf.auth.rserv.HttpMethods.GET; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.Properties; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.aaf.auth.env.AuthzEnv; +import org.onap.aaf.auth.env.AuthzTrans; +import org.onap.aaf.auth.fs.*; +import org.onap.aaf.auth.rserv.CachingFileAccess; +import org.onap.aaf.misc.env.APIException; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(MockitoJUnitRunner.class) +public class JU_FileServer { + @Mock + AuthzEnv authzEnvMock; + AuthzEnv authzEnv = new AuthzEnv(); + + @Before + public void setUp() throws APIException, IOException{ + + } + + @SuppressWarnings("static-access") + @Test + public void testMain() throws Exception{ + + String[] args = null; + Properties props = new Properties(); + ClassLoader classLoader = getClass().getClassLoader(); + File file = new File(classLoader.getResource("FileServer.props").getFile()); + +//PowerMockito.whenNew(Something.class).withArguments(argument).thenReturn(mockSomething); + // env.setLog4JNames("log4j.properties","authz","fs","audit","init",null); + // PowerMockito.whenNew(AuthzEnv.class).withArguments(props).thenReturn(authzEnvMock); + // PowerMockito.doNothing().when(authzEnvMock.setLog4JNames(Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), Matchers.anyString())); + // PowerMockito.when(new AuthzEnv(props)).thenReturn(authzEnvMock); + //PowerMockito.doNothing().when(authzEnv).setLog4JNames(Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), Matchers.anyString()); + //PowerMockito.doNothing().when(authzEnvMock).setLog4JNames(" "," "," "," "," "," "); + + AAF_FS.main(args); + //assertTrue(true); + + } + +} -- cgit 1.2.3-korg