-
Notifications
You must be signed in to change notification settings - Fork 741
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature visibility and Application Id RBAC auth logic added
- Loading branch information
1 parent
69b392f
commit c87e2a0
Showing
9 changed files
with
542 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
gate-web/src/main/java/com/opsmx/spinnaker/gate/enums/PermissionEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright 2022 OpsMx, Inc. | ||
* | ||
* 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. | ||
*/ | ||
|
||
package com.opsmx.spinnaker.gate.enums; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public enum PermissionEnum { | ||
view("view a feature"), | ||
create_or_edit("create or edit a feature"), | ||
delete("delete a feature"), | ||
runtime_access("execute (trigger custom gate)"), | ||
approve_gate("approve a visibility gate"); | ||
|
||
public String description; | ||
|
||
public String getDescription() { | ||
return this.description; | ||
} | ||
|
||
private PermissionEnum(String description) { | ||
this.description = description; | ||
} | ||
|
||
public static PermissionEnum getPermissionEnum(String permissionId) { | ||
return Arrays.stream(PermissionEnum.values()) | ||
.filter(permission -> permission.name().equals(permissionId)) | ||
.findFirst() | ||
.orElse(null); | ||
} | ||
|
||
public static List<PermissionEnum> getPermissionEnumsByValues(String[] values) { | ||
return Arrays.stream(values) | ||
.map(val -> PermissionEnum.getPermissionEnum(val)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public static String getPermissionEnumDisplayName(PermissionEnum permissionId) { | ||
String displayName = ""; | ||
switch (permissionId) { | ||
case view: | ||
displayName = "View"; | ||
break; | ||
case create_or_edit: | ||
displayName = "Create/Edit"; | ||
break; | ||
case delete: | ||
displayName = "Delete"; | ||
break; | ||
case runtime_access: | ||
displayName = "Runtime Access"; | ||
break; | ||
case approve_gate: | ||
displayName = "Approval Gate"; | ||
break; | ||
} | ||
return displayName; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
gate-web/src/main/java/com/opsmx/spinnaker/gate/enums/RbacFeatureType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2022 OpsMx, Inc. | ||
* | ||
* 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. | ||
*/ | ||
|
||
package com.opsmx.spinnaker.gate.enums; | ||
|
||
public enum RbacFeatureType { | ||
APP("Application"), | ||
AGENT("Agent"), | ||
AUDIT("Audit"), | ||
APPROVAL_GATE("Approval Gate"), | ||
CLOUD_PROVIDER("Cloud Provider"), | ||
INTEGRATION("Integration"), | ||
POLICY("Policy"); | ||
|
||
public String description; | ||
|
||
public String getDescription() { | ||
return this.description; | ||
} | ||
|
||
private RbacFeatureType(String description) { | ||
this.description = description; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
gate-web/src/main/java/com/opsmx/spinnaker/gate/exception/AccessForbiddenException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2022 Netflix, Inc. | ||
* | ||
* 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. | ||
*/ | ||
|
||
package com.opsmx.spinnaker.gate.exception; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
@Slf4j | ||
@ResponseStatus(HttpStatus.FORBIDDEN) | ||
public class AccessForbiddenException extends RuntimeException { | ||
|
||
public AccessForbiddenException(String message) { | ||
super(message); | ||
log.error(message); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
gate-web/src/main/java/com/opsmx/spinnaker/gate/exception/InvalidResourceIdException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2022 OpsMx, Inc. | ||
* | ||
* 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. | ||
*/ | ||
|
||
package com.opsmx.spinnaker.gate.exception; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
@Slf4j | ||
@ResponseStatus(HttpStatus.BAD_REQUEST) | ||
public class InvalidResourceIdException extends RuntimeException { | ||
|
||
public InvalidResourceIdException(String message) { | ||
super(message); | ||
log.error(message); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...web/src/main/java/com/opsmx/spinnaker/gate/interceptors/ApplicationIdRbacInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2022 OpsMx, Inc. | ||
* | ||
* 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. | ||
*/ | ||
|
||
package com.opsmx.spinnaker.gate.interceptors; | ||
|
||
import com.opsmx.spinnaker.gate.rbac.ApplicationFeatureRbac; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
|
||
@Slf4j | ||
@Component | ||
public class ApplicationIdRbacInterceptor implements HandlerInterceptor { | ||
|
||
@Autowired private ApplicationFeatureRbac applicationFeatureRbac; | ||
|
||
@Override | ||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) | ||
throws Exception { | ||
log.info( | ||
"Request intercepted for authorizing if the user is having enough access to perform the action"); | ||
applicationFeatureRbac.authorizeUser( | ||
request.getUserPrincipal().getName(), request.getRequestURI(), request.getMethod()); | ||
return false; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...src/main/java/com/opsmx/spinnaker/gate/interceptors/FeatureVisibilityRbacInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2022 OpsMx, Inc. | ||
* | ||
* 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. | ||
*/ | ||
|
||
package com.opsmx.spinnaker.gate.interceptors; | ||
|
||
import com.opsmx.spinnaker.gate.rbac.ApplicationFeatureRbac; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
|
||
@Slf4j | ||
@Component | ||
public class FeatureVisibilityRbacInterceptor implements HandlerInterceptor { | ||
|
||
@Autowired private ApplicationFeatureRbac applicationFeatureRbac; | ||
|
||
@Override | ||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) | ||
throws Exception { | ||
log.info("request intercepted to authorize if the user is having feature visibility"); | ||
applicationFeatureRbac.authorizeUser(request.getUserPrincipal().getName()); | ||
return true; | ||
} | ||
} |
Oops, something went wrong.