This is an automated email from the ASF dual-hosted git repository.
bhliva pushed a commit to branch dlab_refactored
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git
The following commit(s) were added to refs/heads/dlab_refactored by this push:
new 4c8f563 DLAB-000 added correct authorization class for keycloak
4c8f563 is described below
commit 4c8f563eb46501e3c605891b1627f30947d88da9
Author: bhliva <[email protected]>
AuthorDate: Mon Aug 5 13:45:22 2019 +0300
DLAB-000 added correct authorization class for keycloak
---
.../com/epam/dlab/auth/SecurityAuthorizer.java | 54 ----------------------
.../dlab/backendapi/SelfServiceApplication.java | 8 +++-
2 files changed, 6 insertions(+), 56 deletions(-)
diff --git
a/services/dlab-webapp-common/src/main/java/com/epam/dlab/auth/SecurityAuthorizer.java
b/services/dlab-webapp-common/src/main/java/com/epam/dlab/auth/SecurityAuthorizer.java
deleted file mode 100644
index 3758f67..0000000
---
a/services/dlab-webapp-common/src/main/java/com/epam/dlab/auth/SecurityAuthorizer.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.epam.dlab.auth;
-
-import io.dropwizard.auth.Authorizer;
-import lombok.extern.slf4j.Slf4j;
-
-@Slf4j
-public class SecurityAuthorizer implements Authorizer<UserInfo> {
-
- /*
- Add annotations to the service resource class:
-@PermitAll. All authenticated users will have access to the method.
-@RolesAllowed("awsUser"). Access will be granted to the users with the
specified roles.
-@DenyAll. No access will be granted to anyone.
- */
-
- @Override
- public boolean authorize(UserInfo userInfo, String role) {
- log.debug("authorize user = {} with role = {}", userInfo.getName(),
role);
- if (role == null) {
- return true;
- }
-
- boolean authorized = false;
-
- switch (role.toUpperCase()) {
- case "AWSUSER":
- authorized = userInfo.isAwsUser();
- break;
- default:
- authorized = true;
- }
-
- return authorized;
- }
-}
diff --git
a/services/self-service/src/main/java/com/epam/dlab/backendapi/SelfServiceApplication.java
b/services/self-service/src/main/java/com/epam/dlab/backendapi/SelfServiceApplication.java
index 73455f1..2c66f0a 100644
---
a/services/self-service/src/main/java/com/epam/dlab/backendapi/SelfServiceApplication.java
+++
b/services/self-service/src/main/java/com/epam/dlab/backendapi/SelfServiceApplication.java
@@ -20,6 +20,7 @@
package com.epam.dlab.backendapi;
import com.epam.dlab.auth.UserInfo;
+import com.epam.dlab.backendapi.auth.SelfServiceSecurityAuthorizer;
import com.epam.dlab.backendapi.dao.IndexCreator;
import com.epam.dlab.backendapi.domain.EnvStatusListener;
import com.epam.dlab.backendapi.domain.ExploratoryLibCache;
@@ -72,6 +73,7 @@ import javax.servlet.DispatcherType;
import javax.servlet.http.HttpServletRequest;
import java.security.Principal;
import java.util.EnumSet;
+import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -128,7 +130,7 @@ public class SelfServiceApplication extends
Application<SelfServiceApplicationCo
@Override
protected Authorizer createAuthorizer() {
- return (Authorizer<UserInfo>) (principal, role)
-> principal.getRoles().contains(role);
+ return new SelfServiceSecurityAuthorizer();
}
@Override
@@ -146,7 +148,9 @@ public class SelfServiceApplication extends
Application<SelfServiceApplicationCo
final AccessToken token =
keycloakSecurityContext.getToken();
final UserInfo userInfo = new
UserInfo(token.getPreferredUsername(),
keycloakSecurityContext.getTokenString());
-
userInfo.addRoles(token.getResourceAccess(keycloakConfiguration.getResource()).getRoles());
+ final AccessToken.Access
resourceAccess =
+
token.getResourceAccess(keycloakConfiguration.getResource());
+
Optional.ofNullable(resourceAccess).ifPresent(ra ->
userInfo.addRoles(ra.getRoles()));
return userInfo;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]