This repository has been archived by the owner on Jul 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rest): add admin privilege verification to the authorization server
- Loading branch information
1 parent
4b5098b
commit 5ff8423
Showing
33 changed files
with
514 additions
and
166 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
* @author [email protected] | ||
* @author [email protected] | ||
* @author [email protected] | ||
* @author [email protected] | ||
*/ | ||
public class PermissionUtils { | ||
|
||
|
@@ -33,7 +34,7 @@ public static boolean isNormalUser(User user) { | |
} | ||
|
||
public static boolean isAdmin(User user) { | ||
return isInGroup(user,UserGroup.SW360_ADMIN) || isInGroup(user, UserGroup.ADMIN); | ||
return isInGroup(user, UserGroup.SW360_ADMIN) || isInGroup(user, UserGroup.ADMIN); | ||
} | ||
|
||
public static boolean isClearingAdmin(User user) { | ||
|
@@ -55,13 +56,15 @@ private static boolean isInGroup(User user, UserGroup userGroup) { | |
public static boolean isUserAtLeast(UserGroup group, User user) { | ||
switch (group) { | ||
case USER: | ||
return isNormalUser(user) || isClearingAdmin(user) || isEccAdmin(user) || isAdmin(user) || isSecurityAdmin(user); | ||
return isNormalUser(user) || isAdmin(user) || isClearingAdmin(user) || isEccAdmin(user) || isSecurityAdmin(user); | ||
case CLEARING_ADMIN: | ||
return isClearingAdmin(user) || isAdmin(user); | ||
case ECC_ADMIN: | ||
return isEccAdmin(user) || isAdmin(user); | ||
case SECURITY_ADMIN: | ||
return isSecurityAdmin(user) || isAdmin(user); | ||
return isSecurityAdmin(user) || isAdmin(user); | ||
case SW360_ADMIN: | ||
return isAdmin(user); | ||
case ADMIN: | ||
return isAdmin(user); | ||
default: | ||
|
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
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
41 changes: 41 additions & 0 deletions
41
...erver/src/main/java/org/eclipse/sw360/rest/authserver/security/Sw360GrantedAuthority.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,41 @@ | ||
/* | ||
* Copyright Siemens AG, 2017. Part of the SW360 Portal Project. | ||
* | ||
* SPDX-License-Identifier: EPL-1.0 | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package org.eclipse.sw360.rest.authserver.security; | ||
|
||
import org.springframework.security.core.GrantedAuthority; | ||
|
||
public enum Sw360GrantedAuthority implements GrantedAuthority { | ||
|
||
/* | ||
* BASIC: | ||
* only authorized with clientName/clientSecret secret (without valid sw360 user credentials) | ||
*/ | ||
BASIC, | ||
|
||
/* | ||
* READ: | ||
* authorized with clientName/clientSecret and valid sw360 user (without rest api write privileges) | ||
*/ | ||
READ, | ||
|
||
/* | ||
* WRITE | ||
* authorized with clientName/clientSecret and valid sw360 user with rest api write privileges | ||
*/ | ||
WRITE; | ||
|
||
@Override | ||
public String getAuthority() { | ||
return toString(); | ||
} | ||
|
||
} |
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
Oops, something went wrong.