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 apiRegister publishservice.APIRegister
40 invokerRegister invokermanagement.InvokerRegister
43 func NewSecurity(serviceRegister providermanagement.ServiceRegister, apiRegister publishservice.APIRegister, invokerRegister invokermanagement.InvokerRegister) *Security {
45 serviceRegister: serviceRegister,
46 apiRegister: apiRegister,
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 // grantType := ctx.FormValue("grant_type")
55 scope := ctx.FormValue("scope")
57 if !s.invokerRegister.IsInvokerRegistered(clientId) {
58 return sendCoreError(ctx, http.StatusBadRequest, "Invoker not registered")
60 if !s.invokerRegister.VerifyInvokerSecret(clientId, clientSecret) {
61 return sendCoreError(ctx, http.StatusBadRequest, "Invoker secret not valid")
64 scopeData := strings.Split(strings.Split(scope, "#")[1], ":")
65 if !s.serviceRegister.IsFunctionRegistered(scopeData[0]) {
66 return sendCoreError(ctx, http.StatusBadRequest, "Function not registered")
68 if !s.apiRegister.IsAPIRegistered(scopeData[0], scopeData[1]) {
69 return sendCoreError(ctx, http.StatusBadRequest, "API not published")
73 accessTokenResp := securityapi.AccessTokenRsp{
74 AccessToken: "asdadfsrt dsr t5",
80 err := ctx.JSON(http.StatusCreated, accessTokenResp)
82 // Something really bad happened, tell Echo that our handler failed
89 func (s *Security) DeleteTrustedInvokersApiInvokerId(ctx echo.Context, apiInvokerId string) error {
90 return ctx.NoContent(http.StatusNotImplemented)
93 func (s *Security) GetTrustedInvokersApiInvokerId(ctx echo.Context, apiInvokerId string, params securityapi.GetTrustedInvokersApiInvokerIdParams) error {
94 return ctx.NoContent(http.StatusNotImplemented)
97 func (s *Security) PutTrustedInvokersApiInvokerId(ctx echo.Context, apiInvokerId string) error {
98 return ctx.NoContent(http.StatusNotImplemented)
101 func (s *Security) PostTrustedInvokersApiInvokerIdDelete(ctx echo.Context, apiInvokerId string) error {
102 return ctx.NoContent(http.StatusNotImplemented)
105 func (s *Security) PostTrustedInvokersApiInvokerIdUpdate(ctx echo.Context, apiInvokerId string) error {
106 return ctx.NoContent(http.StatusNotImplemented)
109 func sendCoreError(ctx echo.Context, code int, message string) error {
110 pd := common29122.ProblemDetails{
114 err := ctx.JSON(code, pd)