From: Claudio D. Gasparini Date: Tue, 11 May 2021 05:38:19 +0000 (+0200) Subject: NF OAM Adopter RAN Mock application X-Git-Tag: 1.0.0~26 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=adb95fb55dc438e9e08db9cfae9ee098b448f512;p=oam%2Fnf-oam-adopter.git NF OAM Adopter RAN Mock application Issue-ID: OAM-214 Signed-off-by: Claudio D. Gasparini Change-Id: Ide7a146b1f959b12e53325f271698066109dc506 --- diff --git a/solution/README.md b/solution/README.md index 77be58d..054d41c 100644 --- a/solution/README.md +++ b/solution/README.md @@ -1 +1,3 @@ -Folder for docker solution \ No newline at end of file +Local deploy example + +docker-compose up \ No newline at end of file diff --git a/solution/docker-compose.yaml b/solution/docker-compose.yaml new file mode 100644 index 0000000..595f1f8 --- /dev/null +++ b/solution/docker-compose.yaml @@ -0,0 +1,42 @@ +version: "3.5" + +services: +# ves-collector: +# restart: unless-stopped +# ports: +# - "8080:8080/udp" +# image: nexus3.onap.org:10001/onap/org.onap.dcaegen2.collectors.ves.vescollector:latest +# container_name: vescollector +# environment: +# DMAAPHOST: 50.50.50.50 + + ves-nf-oam-adopter-ran-mock: + ports: + - "444:443/tcp" + network_mode: host + restart: unless-stopped + image: nexus3.o-ran-sc.org:10003/o-ran-sc/ves-nf-oam-adopter-ran-mock:latest + container_name: ves-nf-oam-adopter-ran-mock + environment: + KEY_PASSWORD: nf-oam-adopter + KEY_STORE_PASSWORD: nf-oam-adopter + SNMP-DESTINY: 0.0.0.0/162 + + ves-nf-oam-adopter: + ports: + - "162:162/udp" + - "443:443/tcp" + network_mode: host + restart: unless-stopped + image: nexus3.o-ran-sc.org:10003/o-ran-sc/ves-nf-oam-adopter:latest + container_name: ves-nf-oam-adopter + environment: + USERNAME: admin + PASSWORD: admin + KEY_PASSWORD: nf-oam-adopter + KEY_STORE_PASSWORD: nf-oam-adopter + TRUST_STORE_PASSWORD: nf-oam-adopter + VES_COLLECTOR: http://vescollector:8080/eventListener/v7 + VES_ENCODED_AUTH: YWRtaW46YWRtaW4= + PM_SYNC_TIME_START: "06:05:00" + PM_SYNC_TIME_FREQ: "24:00:00" \ No newline at end of file diff --git a/ves-nf-oam-adopter/pom.xml b/ves-nf-oam-adopter/pom.xml index 0ce9d8b..aa53ec3 100644 --- a/ves-nf-oam-adopter/pom.xml +++ b/ves-nf-oam-adopter/pom.xml @@ -46,6 +46,7 @@ ves-nf-oam-adopter-artifacts ves-nf-oam-adopter-checkstyle ves-nf-oam-adopter-spotbugs + ves-nf-oam-adopter-mock ves-nf-oam-adopter-api ves-nf-oam-adopter-event-notifier ves-nf-oam-adopter-snmp-manager diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-artifacts/pom.xml b/ves-nf-oam-adopter/ves-nf-oam-adopter-artifacts/pom.xml index 0307a2e..63cb23f 100644 --- a/ves-nf-oam-adopter/ves-nf-oam-adopter-artifacts/pom.xml +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-artifacts/pom.xml @@ -46,6 +46,11 @@ ves-nf-oam-adopter-spotbugs ${project.version} + + ${project.groupId} + ves-nf-oam-adopter-mock + ${project.version} + ${project.groupId} ves-nf-oam-adopter-api diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/configuration/application.yml b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/configuration/application.yml new file mode 100644 index 0000000..6bd01fd --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/configuration/application.yml @@ -0,0 +1,39 @@ +spring.devtools.restart.log-condition-evaluation-delta: false +scheduler: + fixedDelay: 8000 + initialDelay: 4000 +security: + auth: + username: admin + password: admin +server: + port: ${SERVER_PORT:443} + ssl: + enabled: true + key-store-type: JKS + key-alias: nf-oam-adopter + key-store: ${KEYSTORE_PATH:ssl/nf-oam-adopter-keystore.jks} + key-store-password: ${KEY_STORE_PASSWORD:nf-oam-adopter} + key-password: ${KEY_PASSWORD:nf-oam-adopter} + enabled-protocols: TLSv1.3 + ciphers: TLS_AES_128_GCM_SHA256,TLS_AES_256_GCM_SHA384,TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_CCM_8_SHA256, TLS_AES_128_CCM_SHA256 +snmp: + destiny: ${SNMP-DESTINY:0.0.0.0/162} + alarm-trap: + 1.3.6.1.2.1.1.3.0: "0:00:50.00" + 1.3.6.1.6.3.1.1.4.1.0: "1.3.6.1.4.1.1007.0.0.1.0.1" + 1.3.6.1.4.1.1007.0.0.1.0.2: "OAM-BOX" + 1.3.6.1.4.1.1007.0.0.1.0.3: "Port DOWN" + 1.3.6.1.4.1.1007.0.0.1.0.4: "1613592976108380" + 1.3.6.1.4.1.1007.0.0.1.0.5: "1613592976108380" + 1.3.6.1.4.1.1007.0.0.1.0.6: "10283" + 1.3.6.1.4.1.1007.0.0.1.0.7: "A0" + clear-trap: + 1.3.6.1.2.1.1.3.0: "0:00:50.00" + 1.3.6.1.6.3.1.1.4.1.0: "1.3.6.1.4.1.1007.0.0.1.0.2" + 1.3.6.1.4.1.1007.0.0.1.0.2: "OAM-BOX" + 1.3.6.1.4.1.1007.0.0.1.0.3: "Port UP" + 1.3.6.1.4.1.1007.0.0.1.0.4: "1613592976109380" + 1.3.6.1.4.1.1007.0.0.1.0.5: "1613592976109880" + 1.3.6.1.4.1.1007.0.0.1.0.6: "10283" + 1.3.6.1.4.1.1007.0.0.1.0.7: "A0" diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/configuration/log4j2.yml b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/configuration/log4j2.yml new file mode 100644 index 0000000..c10a74b --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/configuration/log4j2.yml @@ -0,0 +1,48 @@ +Configuration: + status: debug + + appenders: + Console: + name: LogToConsole + PatternLayout: + Pattern: "[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" + + RollingFile: + - name: LogToRollingFile + fileName: logs/o-ran-ves-adapter.log + filePattern: "logs/$${date:yyyy-MM}/o-ran-ves-adapter-%d{MM-dd-yyyy}-%i.log.gz" + PatternLayout: + pattern: "[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" + Policies: + SizeBasedTriggeringPolicy: + size: 100MB + DefaultRollOverStrategy: + max: 10 + + Loggers: + logger: + - name: org.o.ran.oam.nf.oam + level: debug + additivity: false + AppenderRef: + - ref: LogToConsole + - ref: LogToRollingFile + - name: org.springframework.boot.actuate.audit.listener + level: info + additivity: false + AppenderRef: + - ref: LogToConsole + - ref: LogToRollingFile + - name: org.springframework + level: warn + additivity: false + AppenderRef: + - ref: LogToConsole + - ref: LogToRollingFile + + Root: + level: info + AppenderRef: + AppenderRef: + - ref: LogToConsole + - ref: LogToRollingFile diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/configuration/ssl/nf-oam-adopter-keystore.jks b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/configuration/ssl/nf-oam-adopter-keystore.jks new file mode 100644 index 0000000..8712bd5 Binary files /dev/null and b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/configuration/ssl/nf-oam-adopter-keystore.jks differ diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/configuration/zip/pmFiles.zip b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/configuration/zip/pmFiles.zip new file mode 100644 index 0000000..6ea3cb8 Binary files /dev/null and b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/configuration/zip/pmFiles.zip differ diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/docs/api/swagger/openapi.yaml b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/docs/api/swagger/openapi.yaml new file mode 100644 index 0000000..3f0aaaa --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/docs/api/swagger/openapi.yaml @@ -0,0 +1,107 @@ +# ============LICENSE_START======================================================= +# Copyright © 2021 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. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= +openapi: 3.0.3 +info: + title: O-RAN OAM Adopter RAN Mock + description: API for O-RAN OAM Adopter RAN Mock service. + version: "1.0.0" + license: + name: "Apache 2.0" + url: "http://www.apache.org/licenses/LICENSE-2.0" + +servers: + - url: https://example.io/v1 + +paths: + /auth/token: + post: + security: + - BasicAuth: [ ] + tags: + - controller + summary: Generate token + description: Generate token + operationId: authenticateAndGenerateToken + responses: + '200': + description: Successfully returned a list of adapters host address + content: + application/json: + schema: + type: string + '400': + $ref: '#/components/responses/400Error' + '401': + $ref: '#/components/responses/401Error' + /pm/files: + post: + tags: + - controller + summary: Read Performance Management Files + description: Read Performance Management Files + operationId: getPerformanceManagementFiles + responses: + '200': + description: Successfully returned ZIP with CSV pm files + content: + application/zip: + schema: + type: string + format: binary + '400': + $ref: '#/components/responses/400Error' + '401': + $ref: '#/components/responses/401Error' + /system/timeZone: + post: + tags: + - controller + summary: Read time zone + description: Read time zone + operationId: getTimeZone + responses: + '200': + description: Successfully returned time zone of the RAN + content: + application/json: + schema: + type: string + '400': + $ref: '#/components/responses/400Error' + '401': + $ref: '#/components/responses/401Error' + +components: + responses: + 400Error: + description: Invalid request + content: + application/json: + schema: + type: object + properties: + message: + type: string + 401Error: + description: Unauthorized + content: + application/json: + schema: + type: object + properties: + message: + type: string \ No newline at end of file diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/pom.xml b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/pom.xml new file mode 100644 index 0000000..7c8c356 --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/pom.xml @@ -0,0 +1,209 @@ + + + + 4.0.0 + + + org.o-ran-sc.oam + ves-nf-oam-adopter-parent + 1.0.0-SNAPSHOT + ../ves-nf-oam-adopter-parent/pom.xml + + + ves-nf-oam-adopter-mock + + + + ves-nf-oam-adopter-ran-mock + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-validation + + + org.springframework.boot + spring-boot-starter-log4j2 + + + io.swagger.core.v3 + swagger-annotations + + + org.projectlombok + lombok + + + org.snmp4j + snmp4j + + + com.google.code.gson + gson + + + com.github.spotbugs + spotbugs-annotations + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + io.swagger.codegen.v3 + swagger-codegen-maven-plugin + ${swagger-codegen-maven-plugin.version} + + + + generate + + + ${project.basedir}/docs/api/swagger/openapi.yaml + org.o.ran.oam.nf.oam.adopter.mock.app.controller + org.o.ran.oam.nf.oam.adopter.mock.model + org.o.ran.oam.nf.oam.adopter.mock.api + spring + false + + src/gen/java + java11 + true + true + true + + + + + + + + + + + docker + + false + + + + + io.fabric8 + docker-maven-plugin + true + + true + + + ${nexus.repository}${image.name} + + ${base.image} + + ${project.version} + + ${image.workdir} + + + java + -jar + ${project.artifactId}-${project.version}.jar + + + + ${image.workdir} + + + + true + + ${project.groupId}:${project.artifactId} + + ${project.build.finalName}.jar + + + + + ${base.config}application.yml + + + ${base.config}/zip/pmFiles.zip + . + ./pmFiles.zip + + + ${base.config}log4j2.yml + + + ${base.config}/ssl/nf-oam-adopter-keystore.jks + ./ssl + nf-oam-adopter-keystore.jks + + + + + + + + + + + build-docker-image + package + + build + + + + push-image + deploy + + push + + + + + + + + + + \ No newline at end of file diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/MockRanApplication.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/MockRanApplication.java new file mode 100644 index 0000000..500d27d --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/MockRanApplication.java @@ -0,0 +1,30 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 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.o.ran.oam.nf.oam.adopter.mock.app; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication(scanBasePackages = {"org.o.ran.oam.nf.oam.adopter"}) +public class MockRanApplication { + public static void main(final String[] args) { + SpringApplication.run(MockRanApplication.class, args); + } +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/SnmpNotifier.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/SnmpNotifier.java new file mode 100644 index 0000000..388a1ce --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/SnmpNotifier.java @@ -0,0 +1,95 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 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.o.ran.oam.nf.oam.adopter.mock.app; + +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import java.io.IOException; +import java.util.HashMap; +import org.o.ran.oam.nf.oam.adopter.mock.app.properties.SnmpProperties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.snmp4j.CommunityTarget; +import org.snmp4j.PDU; +import org.snmp4j.Snmp; +import org.snmp4j.mp.SnmpConstants; +import org.snmp4j.smi.OID; +import org.snmp4j.smi.OctetString; +import org.snmp4j.smi.UdpAddress; +import org.snmp4j.smi.VariableBinding; +import org.snmp4j.transport.DefaultUdpTransportMapping; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +@Service +@EnableScheduling +public class SnmpNotifier { + + private static final Logger LOG = LoggerFactory.getLogger(SnmpNotifier.class); + + private final HashMap alarmTrap; + private final HashMap clearTrap; + private final CommunityTarget target; + + /** + * Default constructor. + */ + @Autowired + public SnmpNotifier(final SnmpProperties snmpProperties) { + this.alarmTrap = snmpProperties.getAlarmTrap(); + this.clearTrap = snmpProperties.getClearTrap(); + this.target = new CommunityTarget(); + target.setCommunity(new OctetString("public")); + target.setVersion(SnmpConstants.version2c); + target.setAddress(new UdpAddress(snmpProperties.getDestiny())); + } + + @Scheduled(fixedDelayString = "${scheduler.fixedDelay}") + @SuppressFBWarnings("UPM_UNCALLED_PRIVATE_METHOD") + private void sendAlarmTrap() throws IOException { + sendTrap(target, alarmTrap, "alarm"); + } + + @Scheduled(fixedDelayString = "${scheduler.fixedDelay}", initialDelayString = "${scheduler.initialDelay}") + @SuppressFBWarnings("UPM_UNCALLED_PRIVATE_METHOD") + private void sendClearTrap() throws IOException { + sendTrap(target, clearTrap, "clear"); + } + + private static void sendTrap(final CommunityTarget target, final HashMap trap, + final String trapType) throws IOException { + final PDU pdu = new PDU(); + pdu.setType(PDU.TRAP); + trap.forEach((key, value) -> { + try { + pdu.add(new VariableBinding(new OID(key), new OctetString(value))); + } catch (final Exception e) { + LOG.error("Failed to parse oid / value : {}, {}", key, value, e); + } + }); + + + final Snmp snmp = new Snmp(new DefaultUdpTransportMapping()); + snmp.send(pdu, target, null, null); + snmp.close(); + LOG.info("Trap {} sent successfully.", trapType); + } +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/config/AuthTokenFilter.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/config/AuthTokenFilter.java new file mode 100644 index 0000000..ca5ec04 --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/config/AuthTokenFilter.java @@ -0,0 +1,69 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 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.o.ran.oam.nf.oam.adopter.mock.app.config; + +import java.io.IOException; +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.o.ran.oam.nf.oam.adopter.mock.app.properties.SecurityProperties; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.util.StringUtils; +import org.springframework.web.filter.OncePerRequestFilter; + +public class AuthTokenFilter extends OncePerRequestFilter { + private static final Logger logger = LoggerFactory.getLogger(AuthTokenFilter.class); + + public static final String TOKEN = "someRandomToken"; + private final UsernamePasswordAuthenticationToken authentication; + + public AuthTokenFilter(final SecurityProperties security) { + this.authentication = new UsernamePasswordAuthenticationToken(security.getUsername(), security.getPassword()); + } + + @Override + protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, + final FilterChain filterChain) throws ServletException, IOException { + try { + final String token = extractToken(request); + if (token != null && token.equals(TOKEN)) { + + SecurityContextHolder.getContext().setAuthentication(authentication); + } + } catch (final Exception e) { + logger.error("Cannot set user authentication", e); + } + + filterChain.doFilter(request, response); + } + + private static String extractToken(final HttpServletRequest request) { + final String headerAuth = request.getHeader("Authorization"); + if (StringUtils.hasText(headerAuth) && headerAuth.startsWith("Bearer ")) { + return headerAuth.substring(7); + } + + return null; + } +} \ No newline at end of file diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/config/BasicAuthConfiguration.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/config/BasicAuthConfiguration.java new file mode 100644 index 0000000..0c4be6a --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/config/BasicAuthConfiguration.java @@ -0,0 +1,70 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 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.o.ran.oam.nf.oam.adopter.mock.app.config; + +import org.o.ran.oam.nf.oam.adopter.mock.app.properties.SecurityProperties; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.core.annotation.Order; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + +@EnableWebSecurity +@Order(1) +public class BasicAuthConfiguration extends WebSecurityConfigurerAdapter { + + private static final String ADMIN_ROLE = "ADMIN"; + private final SecurityProperties security; + + @Autowired + public BasicAuthConfiguration(final SecurityProperties security) { + super(); + this.security = security; + } + + @Override + protected void configure(final HttpSecurity http) throws Exception { + http.requiresChannel().anyRequest().requiresSecure(); + http.csrf().disable() + .antMatcher("/auth/**") + .authorizeRequests().anyRequest().authenticated() + .and() + .httpBasic(); + } + + @Bean + public AuthenticationManager authenticationManagerBean() throws Exception { + return super.authenticationManagerBean(); + } + + /** + * Configure default in-memory user. + */ + @Autowired + public void configureGlobal(final AuthenticationManagerBuilder auth) throws Exception { + auth.inMemoryAuthentication() + .withUser(security.getUsername()) + .password("{noop}" + security.getPassword()) + .roles(ADMIN_ROLE); + } +} \ No newline at end of file diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/config/TokenSecurityConfiguration.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/config/TokenSecurityConfiguration.java new file mode 100644 index 0000000..bcd2fce --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/config/TokenSecurityConfiguration.java @@ -0,0 +1,54 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 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.o.ran.oam.nf.oam.adopter.mock.app.config; + +import org.o.ran.oam.nf.oam.adopter.mock.app.properties.SecurityProperties; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.annotation.Order; +import org.springframework.http.HttpMethod; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; + +@EnableWebSecurity +@Order(2) +public class TokenSecurityConfiguration extends WebSecurityConfigurerAdapter { + + private final SecurityProperties security; + + @Autowired + public TokenSecurityConfiguration(final SecurityProperties security) { + super(); + this.security = security; + } + + @Override + protected void configure(final HttpSecurity http) throws Exception { + http.requiresChannel().anyRequest().requiresSecure(); + http.csrf().disable() + .addFilterAfter(new AuthTokenFilter(security), UsernamePasswordAuthenticationFilter.class) + .authorizeRequests() + .antMatchers(HttpMethod.POST, "/pm").permitAll() + .antMatchers(HttpMethod.POST, "/system").permitAll() + .anyRequest() + .authenticated(); + } +} \ No newline at end of file diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/controller/RanController.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/controller/RanController.java new file mode 100644 index 0000000..3b35d94 --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/controller/RanController.java @@ -0,0 +1,68 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 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.o.ran.oam.nf.oam.adopter.mock.app.controller; + +import static org.o.ran.oam.nf.oam.adopter.mock.app.config.AuthTokenFilter.TOKEN; + +import com.google.gson.Gson; +import java.time.Instant; +import java.time.ZoneId; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import org.o.ran.oam.nf.oam.adopter.mock.api.ControllerApi; +import org.o.ran.oam.nf.oam.adopter.mock.app.pojo.TimeZoneOffsetResponse; +import org.o.ran.oam.nf.oam.adopter.mock.app.pojo.TokenResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.io.Resource; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class RanController implements ControllerApi { + + private static final Logger LOG = LoggerFactory.getLogger(RanController.class); + private static final DateTimeFormatter OFFSET_FORMATTER = DateTimeFormatter.ofPattern("xxx"); + private static final Gson GSON = new Gson(); + + @Override + public ResponseEntity authenticateAndGenerateToken() { + return ResponseEntity.ok(GSON.toJson(new TokenResponse(TOKEN))); + } + + @Override + public ResponseEntity getPerformanceManagementFiles() { + LOG.info("Read pm files."); + final HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); + return new ResponseEntity<>(ZipUtil.read(), headers, HttpStatus.OK); + } + + @Override + public ResponseEntity getTimeZone() { + final ZoneId zoneId = ZoneId.systemDefault(); + final ZoneOffset offset = zoneId.getRules().getOffset(Instant.now()); + LOG.info("ZoneId {} / Offset {}", zoneId, offset); + return ResponseEntity.ok(GSON.toJson(new TimeZoneOffsetResponse(OFFSET_FORMATTER.format(offset)))); + } +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/controller/ZipUtil.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/controller/ZipUtil.java new file mode 100644 index 0000000..395f475 --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/controller/ZipUtil.java @@ -0,0 +1,47 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 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.o.ran.oam.nf.oam.adopter.mock.app.controller; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import lombok.experimental.UtilityClass; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.io.InputStreamResource; +import org.springframework.core.io.Resource; + +@UtilityClass +public final class ZipUtil { + private static final Logger LOG = LoggerFactory.getLogger(ZipUtil.class); + private static final String ZIP = "pmFiles.zip"; + + /** + * Read Zip File. + */ + public static Resource read() { + try { + return new InputStreamResource(new FileInputStream(new File(new File("."), ZIP))); + } catch (final FileNotFoundException e) { + LOG.error("Failed to load file.", e); + return null; + } + } +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/pojo/TimeZoneOffsetResponse.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/pojo/TimeZoneOffsetResponse.java new file mode 100644 index 0000000..17418df --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/pojo/TimeZoneOffsetResponse.java @@ -0,0 +1,34 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 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.o.ran.oam.nf.oam.adopter.mock.app.pojo; + +import lombok.Getter; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@RequiredArgsConstructor +@Getter +@Setter +public class TimeZoneOffsetResponse { + + @NonNull + private String offset; +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/pojo/TokenResponse.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/pojo/TokenResponse.java new file mode 100644 index 0000000..7f6c0bc --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/pojo/TokenResponse.java @@ -0,0 +1,33 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 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.o.ran.oam.nf.oam.adopter.mock.app.pojo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.NonNull; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TokenResponse { + @NonNull + private String token; +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/properties/SecurityProperties.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/properties/SecurityProperties.java new file mode 100644 index 0000000..2198687 --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/properties/SecurityProperties.java @@ -0,0 +1,18 @@ +package org.o.ran.oam.nf.oam.adopter.mock.app.properties; + +import javax.validation.constraints.NotEmpty; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Component +@ConfigurationProperties(prefix = "security.auth") +@Data +@NoArgsConstructor +public class SecurityProperties { + @NotEmpty + private String username; + @NotEmpty + private String password; +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/properties/SnmpProperties.java b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/properties/SnmpProperties.java new file mode 100644 index 0000000..28155fe --- /dev/null +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-mock/src/main/java/org/o/ran/oam/nf/oam/adopter/mock/app/properties/SnmpProperties.java @@ -0,0 +1,41 @@ +/* + * ============LICENSE_START======================================================= + * O-RAN-SC + * ================================================================================ + * Copyright © 2021 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.o.ran.oam.nf.oam.adopter.mock.app.properties; + +import java.util.HashMap; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Component +@ConfigurationProperties(prefix = "snmp") +@Data +@NoArgsConstructor +public class SnmpProperties { + @NotEmpty + private String destiny; + @NotNull + private HashMap alarmTrap; + @NotNull + private HashMap clearTrap; +} diff --git a/ves-nf-oam-adopter/ves-nf-oam-adopter-parent/pom.xml b/ves-nf-oam-adopter/ves-nf-oam-adopter-parent/pom.xml index 980d256..a694efe 100644 --- a/ves-nf-oam-adopter/ves-nf-oam-adopter-parent/pom.xml +++ b/ves-nf-oam-adopter/ves-nf-oam-adopter-parent/pom.xml @@ -42,10 +42,11 @@ ../ves-nf-oam-adopter-event-notifier/target/site/jacoco-ut/jacoco.xml, - ../ves-nf-oam-adopter-event-notifier/target/site/jacoco-aggregate/jacoco.xml + ../ves-nf-oam-adopter-event-notifier/target/site/jacoco-aggregate/jacoco.xml, ../ves-nf-oam-adopter-snmp-manager/target/site/jacoco-ut/jacoco.xml, ../ves-nf-oam-adopter-snmp-manager/target/site/jacoco-aggregate/jacoco.xml + 3.8.0.2131 2.7 2.6 @@ -53,21 +54,25 @@ 2.8.6 5.0.3 2.2.600 - 5.7.1 1.18.20 3.0.12 - 4.2.3 - 2.4.5 3.4.4 4.2.3 + 2.4.5 + 2.1.9 - 3.8.0.2131 8.41 3.1.2 3.8.1 3.0.0-M3 3.1.1 4.2.3 + 3.0.25 + + openjdk:11-jre-slim + ${project.basedir}/configuration/ + /o-ran-ves-adapter/ + nexus3.o-ran-sc.org:10003/o-ran-sc/ @@ -79,6 +84,11 @@ pom import + + io.swagger.core.v3 + swagger-annotations + ${swagger-annotations.version} + com.google.code.gson gson @@ -161,31 +171,6 @@ - - org.springframework.boot - spring-boot-starter-test - ${spring.boot.version} - - - org.springframework.boot - spring-boot-starter-logging - - - junit - junit - - - - - org.junit.jupiter - junit-jupiter-api - ${junit.jupiter.version} - - - org.junit.jupiter - junit-jupiter-engine - ${junit.jupiter.version} - @@ -437,6 +422,18 @@ + + org.springframework.boot + spring-boot-maven-plugin + ${spring.boot.version} + + + + repackage + + + +