2 // ========================LICENSE_START=================================
5 // Copyright (C) 2022: Nordix Foundation
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===================================
27 "github.com/labstack/echo/v4"
29 "oransc.org/nonrtric/capifcore/internal/common29122"
30 securityapi "oransc.org/nonrtric/capifcore/internal/securityapi"
32 "oransc.org/nonrtric/capifcore/internal/invokermanagement"
33 "oransc.org/nonrtric/capifcore/internal/providermanagement"
34 "oransc.org/nonrtric/capifcore/internal/publishservice"
37 type Security struct {
38 serviceRegister providermanagement.ServiceRegister
39 publishRegister publishservice.PublishRegister
40 invokerRegister invokermanagement.InvokerRegister
43 func NewSecurity(serviceRegister providermanagement.ServiceRegister, publishRegister publishservice.PublishRegister, invokerRegister invokermanagement.InvokerRegister) *Security {
45 serviceRegister: serviceRegister,
46 publishRegister: publishRegister,
47 invokerRegister: invokerRegister,
51 func (s *Security) PostSecuritiesSecurityIdToken(ctx echo.Context, securityId string) error {
52 clientId := ctx.FormValue("client_id")
53 clientSecret := ctx.FormValue("client_secret")
54 scope := ctx.FormValue("scope")
56 if !s.invokerRegister.IsInvokerRegistered(clientId) {
57 return sendCoreError(ctx, http.StatusBadRequest, "Invoker not registered")
59 if !s.invokerRegister.VerifyInvokerSecret(clientId, clientSecret) {
60 return sendCoreError(ctx, http.StatusBadRequest, "Invoker secret not valid")
63 scopeData := strings.Split(strings.Split(scope, "#")[1], ":")
64 if !s.serviceRegister.IsFunctionRegistered(scopeData[0]) {
65 return sendCoreError(ctx, http.StatusBadRequest, "Function not registered")
67 if !s.publishRegister.IsAPIPublished(scopeData[0], scopeData[1]) {
68 return sendCoreError(ctx, http.StatusBadRequest, "API not published")
72 accessTokenResp := securityapi.AccessTokenRsp{
73 AccessToken: "asdadfsrt dsr t5",
79 err := ctx.JSON(http.StatusCreated, accessTokenResp)
81 // Something really bad happened, tell Echo that our handler failed
88 func (s *Security) DeleteTrustedInvokersApiInvokerId(ctx echo.Context, apiInvokerId string) error {
89 return ctx.NoContent(http.StatusNotImplemented)
92 func (s *Security) GetTrustedInvokersApiInvokerId(ctx echo.Context, apiInvokerId string, params securityapi.GetTrustedInvokersApiInvokerIdParams) error {
93 return ctx.NoContent(http.StatusNotImplemented)
96 func (s *Security) PutTrustedInvokersApiInvokerId(ctx echo.Context, apiInvokerId string) error {
97 return ctx.NoContent(http.StatusNotImplemented)
100 func (s *Security) PostTrustedInvokersApiInvokerIdDelete(ctx echo.Context, apiInvokerId string) error {
101 return ctx.NoContent(http.StatusNotImplemented)
104 func (s *Security) PostTrustedInvokersApiInvokerIdUpdate(ctx echo.Context, apiInvokerId string) error {
105 return ctx.NoContent(http.StatusNotImplemented)
108 func sendCoreError(ctx echo.Context, code int, message string) error {
109 pd := common29122.ProblemDetails{
113 err := ctx.JSON(code, pd)