[GitHub] airavata pull request #108: Identity Server Admin Services
Github user anujbhan commented on a diff in the pull request: https://github.com/apache/airavata/pull/108#discussion_r114192869 --- Diff: airavata-services/profile-service/iam-admin-services-core/src/main/java/org/apache/airavata/service/profile/iam/admin/services/core/impl/TenantManagementKeycloakImpl.java --- @@ -0,0 +1,254 @@ +/* + * + * 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 org.apache.airavata.service.profile.iam.admin.services.core.impl; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.model.credential.store.PasswordCredential; +import org.apache.airavata.model.user.UserProfile; +import org.apache.airavata.model.workspace.Gateway; +import org.apache.airavata.service.profile.iam.admin.services.core.interfaces.TenantManagementInterface; +import org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException; +import org.keycloak.admin.client.Keycloak; +import org.keycloak.admin.client.resource.UserResource; +import org.keycloak.representations.idm.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; + +public class TenantManagementKeycloakImpl implements TenantManagementInterface { + +private final static Logger logger = LoggerFactory.getLogger(TenantManagementKeycloakImpl.class); + +private static Keycloak getClient(String adminUrl, String realm, PasswordCredential AdminPasswordCreds) { + +return Keycloak.getInstance( +adminUrl, +realm, // the realm to log in to +AdminPasswordCreds.getLoginUserName(), AdminPasswordCreds.getPassword(), // the user +"admin-cli"); // admin-cli is the client ID used for keycloak admin operations. +} + +@Override +public Gateway addTenant(PasswordCredential isSuperAdminPasswordCreds, Gateway gatewayDetails) throws IamAdminServicesException { +try { +// get client +Keycloak client = TenantManagementKeycloakImpl.getClient(ServerSettings.getIamServerUrl(), "master", isSuperAdminPasswordCreds); +// create realm +RealmRepresentation newRealmDetails = new RealmRepresentation(); +newRealmDetails.setEnabled(true); +newRealmDetails.setId(gatewayDetails.getGatewayId()); + newRealmDetails.setDisplayName(gatewayDetails.getGatewayName()); +newRealmDetails.setRealm(gatewayDetails.getGatewayId()); +RealmRepresentation realmWithRoles = TenantManagementKeycloakImpl.createDefaultRoles(newRealmDetails); +client.realms().create(realmWithRoles); +return gatewayDetails; +} catch (ApplicationSettingsException ex) { +logger.error("Error getting values from property file, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error getting Iam server Url from property file, reason: " + ex.getMessage()); +throw exception; +} catch (Exception ex){ +logger.error("Error creating Realm in Keycloak Server, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error creating Realm in Keycloak Server, reason: " + ex.getMessage()); +throw exception; +} +} + +public static RealmRepresentation createDefaultRoles(RealmRepresentation realmDetails){ +List defaultRoles = new ArrayList(); +RoleRepresentation adminRole = new RoleRepresentation(); +adminRole.setName("admin"); +
[GitHub] airavata pull request #108: Identity Server Admin Services
Github user anujbhan commented on a diff in the pull request: https://github.com/apache/airavata/pull/108#discussion_r114192120 --- Diff: airavata-services/profile-service/iam-admin-services-core/src/main/java/org/apache/airavata/service/profile/iam/admin/services/core/impl/TenantManagementKeycloakImpl.java --- @@ -0,0 +1,254 @@ +/* + * + * 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 org.apache.airavata.service.profile.iam.admin.services.core.impl; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.model.credential.store.PasswordCredential; +import org.apache.airavata.model.user.UserProfile; +import org.apache.airavata.model.workspace.Gateway; +import org.apache.airavata.service.profile.iam.admin.services.core.interfaces.TenantManagementInterface; +import org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException; +import org.keycloak.admin.client.Keycloak; +import org.keycloak.admin.client.resource.UserResource; +import org.keycloak.representations.idm.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; + +public class TenantManagementKeycloakImpl implements TenantManagementInterface { + +private final static Logger logger = LoggerFactory.getLogger(TenantManagementKeycloakImpl.class); + +private static Keycloak getClient(String adminUrl, String realm, PasswordCredential AdminPasswordCreds) { + +return Keycloak.getInstance( +adminUrl, +realm, // the realm to log in to +AdminPasswordCreds.getLoginUserName(), AdminPasswordCreds.getPassword(), // the user +"admin-cli"); // admin-cli is the client ID used for keycloak admin operations. +} + +@Override +public Gateway addTenant(PasswordCredential isSuperAdminPasswordCreds, Gateway gatewayDetails) throws IamAdminServicesException { +try { +// get client +Keycloak client = TenantManagementKeycloakImpl.getClient(ServerSettings.getIamServerUrl(), "master", isSuperAdminPasswordCreds); +// create realm +RealmRepresentation newRealmDetails = new RealmRepresentation(); +newRealmDetails.setEnabled(true); +newRealmDetails.setId(gatewayDetails.getGatewayId()); + newRealmDetails.setDisplayName(gatewayDetails.getGatewayName()); +newRealmDetails.setRealm(gatewayDetails.getGatewayId()); +RealmRepresentation realmWithRoles = TenantManagementKeycloakImpl.createDefaultRoles(newRealmDetails); +client.realms().create(realmWithRoles); +return gatewayDetails; +} catch (ApplicationSettingsException ex) { +logger.error("Error getting values from property file, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error getting Iam server Url from property file, reason: " + ex.getMessage()); +throw exception; +} catch (Exception ex){ +logger.error("Error creating Realm in Keycloak Server, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error creating Realm in Keycloak Server, reason: " + ex.getMessage()); +throw exception; +} +} + +public static RealmRepresentation createDefaultRoles(RealmRepresentation realmDetails){ +List defaultRoles = new ArrayList(); +RoleRepresentation adminRole = new RoleRepresentation(); +adminRole.setName("admin"); +
[GitHub] airavata pull request #108: Identity Server Admin Services
Github user anujbhan commented on a diff in the pull request: https://github.com/apache/airavata/pull/108#discussion_r114191990 --- Diff: airavata-services/profile-service/iam-admin-services-core/src/main/java/org/apache/airavata/service/profile/iam/admin/services/core/impl/TenantManagementKeycloakImpl.java --- @@ -0,0 +1,254 @@ +/* + * + * 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 org.apache.airavata.service.profile.iam.admin.services.core.impl; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.model.credential.store.PasswordCredential; +import org.apache.airavata.model.user.UserProfile; +import org.apache.airavata.model.workspace.Gateway; +import org.apache.airavata.service.profile.iam.admin.services.core.interfaces.TenantManagementInterface; +import org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException; +import org.keycloak.admin.client.Keycloak; +import org.keycloak.admin.client.resource.UserResource; +import org.keycloak.representations.idm.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; + +public class TenantManagementKeycloakImpl implements TenantManagementInterface { + +private final static Logger logger = LoggerFactory.getLogger(TenantManagementKeycloakImpl.class); + +private static Keycloak getClient(String adminUrl, String realm, PasswordCredential AdminPasswordCreds) { + +return Keycloak.getInstance( +adminUrl, +realm, // the realm to log in to +AdminPasswordCreds.getLoginUserName(), AdminPasswordCreds.getPassword(), // the user +"admin-cli"); // admin-cli is the client ID used for keycloak admin operations. +} + +@Override +public Gateway addTenant(PasswordCredential isSuperAdminPasswordCreds, Gateway gatewayDetails) throws IamAdminServicesException { +try { +// get client +Keycloak client = TenantManagementKeycloakImpl.getClient(ServerSettings.getIamServerUrl(), "master", isSuperAdminPasswordCreds); +// create realm +RealmRepresentation newRealmDetails = new RealmRepresentation(); +newRealmDetails.setEnabled(true); +newRealmDetails.setId(gatewayDetails.getGatewayId()); + newRealmDetails.setDisplayName(gatewayDetails.getGatewayName()); +newRealmDetails.setRealm(gatewayDetails.getGatewayId()); +RealmRepresentation realmWithRoles = TenantManagementKeycloakImpl.createDefaultRoles(newRealmDetails); +client.realms().create(realmWithRoles); +return gatewayDetails; +} catch (ApplicationSettingsException ex) { +logger.error("Error getting values from property file, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error getting Iam server Url from property file, reason: " + ex.getMessage()); +throw exception; +} catch (Exception ex){ +logger.error("Error creating Realm in Keycloak Server, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error creating Realm in Keycloak Server, reason: " + ex.getMessage()); +throw exception; +} +} + +public static RealmRepresentation createDefaultRoles(RealmRepresentation realmDetails){ +List defaultRoles = new ArrayList(); +RoleRepresentation adminRole = new RoleRepresentation(); +adminRole.setName("admin"); +
[GitHub] airavata pull request #108: Identity Server Admin Services
Github user machristie commented on a diff in the pull request: https://github.com/apache/airavata/pull/108#discussion_r114191936 --- Diff: airavata-services/profile-service/iam-admin-services-core/src/main/java/org/apache/airavata/service/profile/iam/admin/services/core/impl/TenantManagementKeycloakImpl.java --- @@ -0,0 +1,254 @@ +/* + * + * 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 org.apache.airavata.service.profile.iam.admin.services.core.impl; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.model.credential.store.PasswordCredential; +import org.apache.airavata.model.user.UserProfile; +import org.apache.airavata.model.workspace.Gateway; +import org.apache.airavata.service.profile.iam.admin.services.core.interfaces.TenantManagementInterface; +import org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException; +import org.keycloak.admin.client.Keycloak; +import org.keycloak.admin.client.resource.UserResource; +import org.keycloak.representations.idm.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; + +public class TenantManagementKeycloakImpl implements TenantManagementInterface { + +private final static Logger logger = LoggerFactory.getLogger(TenantManagementKeycloakImpl.class); + +private static Keycloak getClient(String adminUrl, String realm, PasswordCredential AdminPasswordCreds) { + +return Keycloak.getInstance( +adminUrl, +realm, // the realm to log in to +AdminPasswordCreds.getLoginUserName(), AdminPasswordCreds.getPassword(), // the user +"admin-cli"); // admin-cli is the client ID used for keycloak admin operations. +} + +@Override +public Gateway addTenant(PasswordCredential isSuperAdminPasswordCreds, Gateway gatewayDetails) throws IamAdminServicesException { +try { +// get client +Keycloak client = TenantManagementKeycloakImpl.getClient(ServerSettings.getIamServerUrl(), "master", isSuperAdminPasswordCreds); +// create realm +RealmRepresentation newRealmDetails = new RealmRepresentation(); +newRealmDetails.setEnabled(true); +newRealmDetails.setId(gatewayDetails.getGatewayId()); + newRealmDetails.setDisplayName(gatewayDetails.getGatewayName()); +newRealmDetails.setRealm(gatewayDetails.getGatewayId()); +RealmRepresentation realmWithRoles = TenantManagementKeycloakImpl.createDefaultRoles(newRealmDetails); +client.realms().create(realmWithRoles); +return gatewayDetails; +} catch (ApplicationSettingsException ex) { +logger.error("Error getting values from property file, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error getting Iam server Url from property file, reason: " + ex.getMessage()); +throw exception; +} catch (Exception ex){ +logger.error("Error creating Realm in Keycloak Server, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error creating Realm in Keycloak Server, reason: " + ex.getMessage()); +throw exception; +} +} + +public static RealmRepresentation createDefaultRoles(RealmRepresentation realmDetails){ +List defaultRoles = new ArrayList(); +RoleRepresentation adminRole = new RoleRepresentation(); +adminRole.setName("admin"); +
[GitHub] airavata pull request #108: Identity Server Admin Services
Github user machristie commented on a diff in the pull request: https://github.com/apache/airavata/pull/108#discussion_r114191738 --- Diff: airavata-services/profile-service/iam-admin-services-core/src/main/java/org/apache/airavata/service/profile/iam/admin/services/core/impl/TenantManagementKeycloakImpl.java --- @@ -0,0 +1,254 @@ +/* + * + * 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 org.apache.airavata.service.profile.iam.admin.services.core.impl; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.model.credential.store.PasswordCredential; +import org.apache.airavata.model.user.UserProfile; +import org.apache.airavata.model.workspace.Gateway; +import org.apache.airavata.service.profile.iam.admin.services.core.interfaces.TenantManagementInterface; +import org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException; +import org.keycloak.admin.client.Keycloak; +import org.keycloak.admin.client.resource.UserResource; +import org.keycloak.representations.idm.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; + +public class TenantManagementKeycloakImpl implements TenantManagementInterface { + +private final static Logger logger = LoggerFactory.getLogger(TenantManagementKeycloakImpl.class); + +private static Keycloak getClient(String adminUrl, String realm, PasswordCredential AdminPasswordCreds) { + +return Keycloak.getInstance( +adminUrl, +realm, // the realm to log in to +AdminPasswordCreds.getLoginUserName(), AdminPasswordCreds.getPassword(), // the user +"admin-cli"); // admin-cli is the client ID used for keycloak admin operations. +} + +@Override +public Gateway addTenant(PasswordCredential isSuperAdminPasswordCreds, Gateway gatewayDetails) throws IamAdminServicesException { +try { +// get client +Keycloak client = TenantManagementKeycloakImpl.getClient(ServerSettings.getIamServerUrl(), "master", isSuperAdminPasswordCreds); +// create realm +RealmRepresentation newRealmDetails = new RealmRepresentation(); +newRealmDetails.setEnabled(true); +newRealmDetails.setId(gatewayDetails.getGatewayId()); + newRealmDetails.setDisplayName(gatewayDetails.getGatewayName()); +newRealmDetails.setRealm(gatewayDetails.getGatewayId()); +RealmRepresentation realmWithRoles = TenantManagementKeycloakImpl.createDefaultRoles(newRealmDetails); +client.realms().create(realmWithRoles); +return gatewayDetails; +} catch (ApplicationSettingsException ex) { +logger.error("Error getting values from property file, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error getting Iam server Url from property file, reason: " + ex.getMessage()); +throw exception; +} catch (Exception ex){ +logger.error("Error creating Realm in Keycloak Server, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error creating Realm in Keycloak Server, reason: " + ex.getMessage()); +throw exception; +} +} + +public static RealmRepresentation createDefaultRoles(RealmRepresentation realmDetails){ +List defaultRoles = new ArrayList(); +RoleRepresentation adminRole = new RoleRepresentation(); +adminRole.setName("admin"); +
[GitHub] airavata pull request #108: Identity Server Admin Services
Github user anujbhan commented on a diff in the pull request: https://github.com/apache/airavata/pull/108#discussion_r114189806 --- Diff: airavata-services/profile-service/iam-admin-services-core/src/main/java/org/apache/airavata/service/profile/iam/admin/services/core/impl/TenantManagementKeycloakImpl.java --- @@ -0,0 +1,254 @@ +/* + * + * 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 org.apache.airavata.service.profile.iam.admin.services.core.impl; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.model.credential.store.PasswordCredential; +import org.apache.airavata.model.user.UserProfile; +import org.apache.airavata.model.workspace.Gateway; +import org.apache.airavata.service.profile.iam.admin.services.core.interfaces.TenantManagementInterface; +import org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException; +import org.keycloak.admin.client.Keycloak; +import org.keycloak.admin.client.resource.UserResource; +import org.keycloak.representations.idm.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; + +public class TenantManagementKeycloakImpl implements TenantManagementInterface { + +private final static Logger logger = LoggerFactory.getLogger(TenantManagementKeycloakImpl.class); + +private static Keycloak getClient(String adminUrl, String realm, PasswordCredential AdminPasswordCreds) { + +return Keycloak.getInstance( +adminUrl, +realm, // the realm to log in to +AdminPasswordCreds.getLoginUserName(), AdminPasswordCreds.getPassword(), // the user +"admin-cli"); // admin-cli is the client ID used for keycloak admin operations. +} + +@Override +public Gateway addTenant(PasswordCredential isSuperAdminPasswordCreds, Gateway gatewayDetails) throws IamAdminServicesException { +try { +// get client +Keycloak client = TenantManagementKeycloakImpl.getClient(ServerSettings.getIamServerUrl(), "master", isSuperAdminPasswordCreds); +// create realm +RealmRepresentation newRealmDetails = new RealmRepresentation(); +newRealmDetails.setEnabled(true); +newRealmDetails.setId(gatewayDetails.getGatewayId()); + newRealmDetails.setDisplayName(gatewayDetails.getGatewayName()); +newRealmDetails.setRealm(gatewayDetails.getGatewayId()); +RealmRepresentation realmWithRoles = TenantManagementKeycloakImpl.createDefaultRoles(newRealmDetails); +client.realms().create(realmWithRoles); +return gatewayDetails; +} catch (ApplicationSettingsException ex) { +logger.error("Error getting values from property file, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error getting Iam server Url from property file, reason: " + ex.getMessage()); +throw exception; +} catch (Exception ex){ +logger.error("Error creating Realm in Keycloak Server, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error creating Realm in Keycloak Server, reason: " + ex.getMessage()); +throw exception; +} +} + +public static RealmRepresentation createDefaultRoles(RealmRepresentation realmDetails){ +List defaultRoles = new ArrayList(); +RoleRepresentation adminRole = new RoleRepresentation(); +adminRole.setName("admin"); +
[GitHub] airavata pull request #108: Identity Server Admin Services
Github user anujbhan commented on a diff in the pull request: https://github.com/apache/airavata/pull/108#discussion_r114189064 --- Diff: airavata-services/profile-service/iam-admin-services-core/src/main/java/org/apache/airavata/service/profile/iam/admin/services/core/impl/TenantManagementKeycloakImpl.java --- @@ -0,0 +1,254 @@ +/* + * + * 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 org.apache.airavata.service.profile.iam.admin.services.core.impl; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.model.credential.store.PasswordCredential; +import org.apache.airavata.model.user.UserProfile; +import org.apache.airavata.model.workspace.Gateway; +import org.apache.airavata.service.profile.iam.admin.services.core.interfaces.TenantManagementInterface; +import org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException; +import org.keycloak.admin.client.Keycloak; +import org.keycloak.admin.client.resource.UserResource; +import org.keycloak.representations.idm.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; + +public class TenantManagementKeycloakImpl implements TenantManagementInterface { + +private final static Logger logger = LoggerFactory.getLogger(TenantManagementKeycloakImpl.class); + +private static Keycloak getClient(String adminUrl, String realm, PasswordCredential AdminPasswordCreds) { + +return Keycloak.getInstance( +adminUrl, +realm, // the realm to log in to +AdminPasswordCreds.getLoginUserName(), AdminPasswordCreds.getPassword(), // the user +"admin-cli"); // admin-cli is the client ID used for keycloak admin operations. +} + +@Override +public Gateway addTenant(PasswordCredential isSuperAdminPasswordCreds, Gateway gatewayDetails) throws IamAdminServicesException { +try { +// get client +Keycloak client = TenantManagementKeycloakImpl.getClient(ServerSettings.getIamServerUrl(), "master", isSuperAdminPasswordCreds); +// create realm +RealmRepresentation newRealmDetails = new RealmRepresentation(); +newRealmDetails.setEnabled(true); +newRealmDetails.setId(gatewayDetails.getGatewayId()); + newRealmDetails.setDisplayName(gatewayDetails.getGatewayName()); +newRealmDetails.setRealm(gatewayDetails.getGatewayId()); +RealmRepresentation realmWithRoles = TenantManagementKeycloakImpl.createDefaultRoles(newRealmDetails); +client.realms().create(realmWithRoles); +return gatewayDetails; +} catch (ApplicationSettingsException ex) { +logger.error("Error getting values from property file, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error getting Iam server Url from property file, reason: " + ex.getMessage()); +throw exception; +} catch (Exception ex){ +logger.error("Error creating Realm in Keycloak Server, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error creating Realm in Keycloak Server, reason: " + ex.getMessage()); +throw exception; +} +} + +public static RealmRepresentation createDefaultRoles(RealmRepresentation realmDetails){ +List defaultRoles = new ArrayList(); +RoleRepresentation adminRole = new RoleRepresentation(); +adminRole.setName("admin"); +
[GitHub] airavata pull request #108: Identity Server Admin Services
Github user anujbhan commented on a diff in the pull request: https://github.com/apache/airavata/pull/108#discussion_r114188916 --- Diff: airavata-services/profile-service/iam-admin-services-core/src/main/java/org/apache/airavata/service/profile/iam/admin/services/core/impl/TenantManagementKeycloakImpl.java --- @@ -0,0 +1,254 @@ +/* + * + * 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 org.apache.airavata.service.profile.iam.admin.services.core.impl; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.model.credential.store.PasswordCredential; +import org.apache.airavata.model.user.UserProfile; +import org.apache.airavata.model.workspace.Gateway; +import org.apache.airavata.service.profile.iam.admin.services.core.interfaces.TenantManagementInterface; +import org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException; +import org.keycloak.admin.client.Keycloak; +import org.keycloak.admin.client.resource.UserResource; +import org.keycloak.representations.idm.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; + +public class TenantManagementKeycloakImpl implements TenantManagementInterface { + +private final static Logger logger = LoggerFactory.getLogger(TenantManagementKeycloakImpl.class); + +private static Keycloak getClient(String adminUrl, String realm, PasswordCredential AdminPasswordCreds) { + +return Keycloak.getInstance( +adminUrl, +realm, // the realm to log in to +AdminPasswordCreds.getLoginUserName(), AdminPasswordCreds.getPassword(), // the user +"admin-cli"); // admin-cli is the client ID used for keycloak admin operations. +} + +@Override +public Gateway addTenant(PasswordCredential isSuperAdminPasswordCreds, Gateway gatewayDetails) throws IamAdminServicesException { +try { +// get client +Keycloak client = TenantManagementKeycloakImpl.getClient(ServerSettings.getIamServerUrl(), "master", isSuperAdminPasswordCreds); +// create realm +RealmRepresentation newRealmDetails = new RealmRepresentation(); +newRealmDetails.setEnabled(true); +newRealmDetails.setId(gatewayDetails.getGatewayId()); + newRealmDetails.setDisplayName(gatewayDetails.getGatewayName()); +newRealmDetails.setRealm(gatewayDetails.getGatewayId()); +RealmRepresentation realmWithRoles = TenantManagementKeycloakImpl.createDefaultRoles(newRealmDetails); +client.realms().create(realmWithRoles); +return gatewayDetails; +} catch (ApplicationSettingsException ex) { +logger.error("Error getting values from property file, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error getting Iam server Url from property file, reason: " + ex.getMessage()); +throw exception; +} catch (Exception ex){ +logger.error("Error creating Realm in Keycloak Server, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error creating Realm in Keycloak Server, reason: " + ex.getMessage()); +throw exception; +} +} + +public static RealmRepresentation createDefaultRoles(RealmRepresentation realmDetails){ +List defaultRoles = new ArrayList(); +RoleRepresentation adminRole = new RoleRepresentation(); +adminRole.setName("admin"); +
[GitHub] airavata pull request #108: Identity Server Admin Services
Github user machristie commented on a diff in the pull request: https://github.com/apache/airavata/pull/108#discussion_r114188896 --- Diff: airavata-services/profile-service/iam-admin-services-core/src/main/java/org/apache/airavata/service/profile/iam/admin/services/core/impl/TenantManagementKeycloakImpl.java --- @@ -0,0 +1,254 @@ +/* + * + * 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 org.apache.airavata.service.profile.iam.admin.services.core.impl; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.model.credential.store.PasswordCredential; +import org.apache.airavata.model.user.UserProfile; +import org.apache.airavata.model.workspace.Gateway; +import org.apache.airavata.service.profile.iam.admin.services.core.interfaces.TenantManagementInterface; +import org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException; +import org.keycloak.admin.client.Keycloak; +import org.keycloak.admin.client.resource.UserResource; +import org.keycloak.representations.idm.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; + +public class TenantManagementKeycloakImpl implements TenantManagementInterface { + +private final static Logger logger = LoggerFactory.getLogger(TenantManagementKeycloakImpl.class); + +private static Keycloak getClient(String adminUrl, String realm, PasswordCredential AdminPasswordCreds) { + +return Keycloak.getInstance( +adminUrl, +realm, // the realm to log in to +AdminPasswordCreds.getLoginUserName(), AdminPasswordCreds.getPassword(), // the user +"admin-cli"); // admin-cli is the client ID used for keycloak admin operations. +} + +@Override +public Gateway addTenant(PasswordCredential isSuperAdminPasswordCreds, Gateway gatewayDetails) throws IamAdminServicesException { +try { +// get client +Keycloak client = TenantManagementKeycloakImpl.getClient(ServerSettings.getIamServerUrl(), "master", isSuperAdminPasswordCreds); +// create realm +RealmRepresentation newRealmDetails = new RealmRepresentation(); +newRealmDetails.setEnabled(true); +newRealmDetails.setId(gatewayDetails.getGatewayId()); + newRealmDetails.setDisplayName(gatewayDetails.getGatewayName()); +newRealmDetails.setRealm(gatewayDetails.getGatewayId()); +RealmRepresentation realmWithRoles = TenantManagementKeycloakImpl.createDefaultRoles(newRealmDetails); +client.realms().create(realmWithRoles); +return gatewayDetails; +} catch (ApplicationSettingsException ex) { +logger.error("Error getting values from property file, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error getting Iam server Url from property file, reason: " + ex.getMessage()); +throw exception; +} catch (Exception ex){ +logger.error("Error creating Realm in Keycloak Server, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error creating Realm in Keycloak Server, reason: " + ex.getMessage()); +throw exception; +} +} + +public static RealmRepresentation createDefaultRoles(RealmRepresentation realmDetails){ +List defaultRoles = new ArrayList(); +RoleRepresentation adminRole = new RoleRepresentation(); +adminRole.setName("admin"); +
[GitHub] airavata pull request #108: Identity Server Admin Services
Github user machristie commented on a diff in the pull request: https://github.com/apache/airavata/pull/108#discussion_r114188541 --- Diff: airavata-services/profile-service/iam-admin-services-core/src/main/java/org/apache/airavata/service/profile/iam/admin/services/core/impl/TenantManagementKeycloakImpl.java --- @@ -0,0 +1,254 @@ +/* + * + * 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 org.apache.airavata.service.profile.iam.admin.services.core.impl; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.model.credential.store.PasswordCredential; +import org.apache.airavata.model.user.UserProfile; +import org.apache.airavata.model.workspace.Gateway; +import org.apache.airavata.service.profile.iam.admin.services.core.interfaces.TenantManagementInterface; +import org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException; +import org.keycloak.admin.client.Keycloak; +import org.keycloak.admin.client.resource.UserResource; +import org.keycloak.representations.idm.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; + +public class TenantManagementKeycloakImpl implements TenantManagementInterface { + +private final static Logger logger = LoggerFactory.getLogger(TenantManagementKeycloakImpl.class); + +private static Keycloak getClient(String adminUrl, String realm, PasswordCredential AdminPasswordCreds) { + +return Keycloak.getInstance( +adminUrl, +realm, // the realm to log in to +AdminPasswordCreds.getLoginUserName(), AdminPasswordCreds.getPassword(), // the user +"admin-cli"); // admin-cli is the client ID used for keycloak admin operations. +} + +@Override +public Gateway addTenant(PasswordCredential isSuperAdminPasswordCreds, Gateway gatewayDetails) throws IamAdminServicesException { +try { +// get client +Keycloak client = TenantManagementKeycloakImpl.getClient(ServerSettings.getIamServerUrl(), "master", isSuperAdminPasswordCreds); +// create realm +RealmRepresentation newRealmDetails = new RealmRepresentation(); +newRealmDetails.setEnabled(true); +newRealmDetails.setId(gatewayDetails.getGatewayId()); + newRealmDetails.setDisplayName(gatewayDetails.getGatewayName()); +newRealmDetails.setRealm(gatewayDetails.getGatewayId()); +RealmRepresentation realmWithRoles = TenantManagementKeycloakImpl.createDefaultRoles(newRealmDetails); +client.realms().create(realmWithRoles); +return gatewayDetails; +} catch (ApplicationSettingsException ex) { +logger.error("Error getting values from property file, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error getting Iam server Url from property file, reason: " + ex.getMessage()); +throw exception; +} catch (Exception ex){ +logger.error("Error creating Realm in Keycloak Server, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error creating Realm in Keycloak Server, reason: " + ex.getMessage()); +throw exception; +} +} + +public static RealmRepresentation createDefaultRoles(RealmRepresentation realmDetails){ +List defaultRoles = new ArrayList(); +RoleRepresentation adminRole = new RoleRepresentation(); +adminRole.setName("admin"); +
[GitHub] airavata pull request #108: Identity Server Admin Services
Github user anujbhan commented on a diff in the pull request: https://github.com/apache/airavata/pull/108#discussion_r114181749 --- Diff: airavata-services/profile-service/iam-admin-services-core/src/main/java/org/apache/airavata/service/profile/iam/admin/services/core/impl/TenantManagementKeycloakImpl.java --- @@ -0,0 +1,254 @@ +/* + * + * 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 org.apache.airavata.service.profile.iam.admin.services.core.impl; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.model.credential.store.PasswordCredential; +import org.apache.airavata.model.user.UserProfile; +import org.apache.airavata.model.workspace.Gateway; +import org.apache.airavata.service.profile.iam.admin.services.core.interfaces.TenantManagementInterface; +import org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException; +import org.keycloak.admin.client.Keycloak; +import org.keycloak.admin.client.resource.UserResource; +import org.keycloak.representations.idm.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; + +public class TenantManagementKeycloakImpl implements TenantManagementInterface { + +private final static Logger logger = LoggerFactory.getLogger(TenantManagementKeycloakImpl.class); + +private static Keycloak getClient(String adminUrl, String realm, PasswordCredential AdminPasswordCreds) { + +return Keycloak.getInstance( +adminUrl, +realm, // the realm to log in to +AdminPasswordCreds.getLoginUserName(), AdminPasswordCreds.getPassword(), // the user +"admin-cli"); // admin-cli is the client ID used for keycloak admin operations. +} + +@Override +public Gateway addTenant(PasswordCredential isSuperAdminPasswordCreds, Gateway gatewayDetails) throws IamAdminServicesException { +try { +// get client +Keycloak client = TenantManagementKeycloakImpl.getClient(ServerSettings.getIamServerUrl(), "master", isSuperAdminPasswordCreds); +// create realm +RealmRepresentation newRealmDetails = new RealmRepresentation(); +newRealmDetails.setEnabled(true); +newRealmDetails.setId(gatewayDetails.getGatewayId()); + newRealmDetails.setDisplayName(gatewayDetails.getGatewayName()); +newRealmDetails.setRealm(gatewayDetails.getGatewayId()); +RealmRepresentation realmWithRoles = TenantManagementKeycloakImpl.createDefaultRoles(newRealmDetails); +client.realms().create(realmWithRoles); +return gatewayDetails; +} catch (ApplicationSettingsException ex) { +logger.error("Error getting values from property file, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error getting Iam server Url from property file, reason: " + ex.getMessage()); +throw exception; +} catch (Exception ex){ +logger.error("Error creating Realm in Keycloak Server, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error creating Realm in Keycloak Server, reason: " + ex.getMessage()); +throw exception; +} +} + +public static RealmRepresentation createDefaultRoles(RealmRepresentation realmDetails){ +List defaultRoles = new ArrayList(); +RoleRepresentation adminRole = new RoleRepresentation(); +adminRole.setName("admin"); +
[GitHub] airavata pull request #108: Identity Server Admin Services
Github user anujbhan commented on a diff in the pull request: https://github.com/apache/airavata/pull/108#discussion_r114181574 --- Diff: airavata-services/profile-service/iam-admin-services-core/src/main/java/org/apache/airavata/service/profile/iam/admin/services/core/impl/TenantManagementKeycloakImpl.java --- @@ -0,0 +1,254 @@ +/* + * + * 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 org.apache.airavata.service.profile.iam.admin.services.core.impl; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.model.credential.store.PasswordCredential; +import org.apache.airavata.model.user.UserProfile; +import org.apache.airavata.model.workspace.Gateway; +import org.apache.airavata.service.profile.iam.admin.services.core.interfaces.TenantManagementInterface; +import org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException; +import org.keycloak.admin.client.Keycloak; +import org.keycloak.admin.client.resource.UserResource; +import org.keycloak.representations.idm.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; + +public class TenantManagementKeycloakImpl implements TenantManagementInterface { + +private final static Logger logger = LoggerFactory.getLogger(TenantManagementKeycloakImpl.class); + +private static Keycloak getClient(String adminUrl, String realm, PasswordCredential AdminPasswordCreds) { + +return Keycloak.getInstance( +adminUrl, +realm, // the realm to log in to +AdminPasswordCreds.getLoginUserName(), AdminPasswordCreds.getPassword(), // the user +"admin-cli"); // admin-cli is the client ID used for keycloak admin operations. +} + +@Override +public Gateway addTenant(PasswordCredential isSuperAdminPasswordCreds, Gateway gatewayDetails) throws IamAdminServicesException { +try { +// get client +Keycloak client = TenantManagementKeycloakImpl.getClient(ServerSettings.getIamServerUrl(), "master", isSuperAdminPasswordCreds); +// create realm +RealmRepresentation newRealmDetails = new RealmRepresentation(); +newRealmDetails.setEnabled(true); +newRealmDetails.setId(gatewayDetails.getGatewayId()); + newRealmDetails.setDisplayName(gatewayDetails.getGatewayName()); +newRealmDetails.setRealm(gatewayDetails.getGatewayId()); +RealmRepresentation realmWithRoles = TenantManagementKeycloakImpl.createDefaultRoles(newRealmDetails); +client.realms().create(realmWithRoles); +return gatewayDetails; +} catch (ApplicationSettingsException ex) { +logger.error("Error getting values from property file, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error getting Iam server Url from property file, reason: " + ex.getMessage()); +throw exception; +} catch (Exception ex){ +logger.error("Error creating Realm in Keycloak Server, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error creating Realm in Keycloak Server, reason: " + ex.getMessage()); +throw exception; +} +} + +public static RealmRepresentation createDefaultRoles(RealmRepresentation realmDetails){ +List defaultRoles = new ArrayList(); +RoleRepresentation adminRole = new RoleRepresentation(); +adminRole.setName("admin"); +
[GitHub] airavata pull request #108: Identity Server Admin Services
Github user anujbhan commented on a diff in the pull request: https://github.com/apache/airavata/pull/108#discussion_r114181208 --- Diff: airavata-services/profile-service/iam-admin-services-core/src/main/java/org/apache/airavata/service/profile/iam/admin/services/core/impl/TenantManagementKeycloakImpl.java --- @@ -0,0 +1,254 @@ +/* + * + * 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 org.apache.airavata.service.profile.iam.admin.services.core.impl; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.model.credential.store.PasswordCredential; +import org.apache.airavata.model.user.UserProfile; +import org.apache.airavata.model.workspace.Gateway; +import org.apache.airavata.service.profile.iam.admin.services.core.interfaces.TenantManagementInterface; +import org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException; +import org.keycloak.admin.client.Keycloak; +import org.keycloak.admin.client.resource.UserResource; +import org.keycloak.representations.idm.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; + +public class TenantManagementKeycloakImpl implements TenantManagementInterface { + +private final static Logger logger = LoggerFactory.getLogger(TenantManagementKeycloakImpl.class); + +private static Keycloak getClient(String adminUrl, String realm, PasswordCredential AdminPasswordCreds) { + +return Keycloak.getInstance( +adminUrl, +realm, // the realm to log in to +AdminPasswordCreds.getLoginUserName(), AdminPasswordCreds.getPassword(), // the user +"admin-cli"); // admin-cli is the client ID used for keycloak admin operations. +} + +@Override +public Gateway addTenant(PasswordCredential isSuperAdminPasswordCreds, Gateway gatewayDetails) throws IamAdminServicesException { +try { +// get client +Keycloak client = TenantManagementKeycloakImpl.getClient(ServerSettings.getIamServerUrl(), "master", isSuperAdminPasswordCreds); +// create realm +RealmRepresentation newRealmDetails = new RealmRepresentation(); +newRealmDetails.setEnabled(true); +newRealmDetails.setId(gatewayDetails.getGatewayId()); + newRealmDetails.setDisplayName(gatewayDetails.getGatewayName()); +newRealmDetails.setRealm(gatewayDetails.getGatewayId()); +RealmRepresentation realmWithRoles = TenantManagementKeycloakImpl.createDefaultRoles(newRealmDetails); +client.realms().create(realmWithRoles); +return gatewayDetails; +} catch (ApplicationSettingsException ex) { +logger.error("Error getting values from property file, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error getting Iam server Url from property file, reason: " + ex.getMessage()); +throw exception; +} catch (Exception ex){ +logger.error("Error creating Realm in Keycloak Server, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error creating Realm in Keycloak Server, reason: " + ex.getMessage()); +throw exception; +} +} + +public static RealmRepresentation createDefaultRoles(RealmRepresentation realmDetails){ +List defaultRoles = new ArrayList(); +RoleRepresentation adminRole = new RoleRepresentation(); +adminRole.setName("admin"); +
[GitHub] airavata pull request #108: Identity Server Admin Services
Github user machristie commented on a diff in the pull request: https://github.com/apache/airavata/pull/108#discussion_r114060126 --- Diff: airavata-services/profile-service/iam-admin-services-core/src/main/java/org/apache/airavata/service/profile/iam/admin/services/core/impl/TenantManagementKeycloakImpl.java --- @@ -0,0 +1,254 @@ +/* + * + * 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 org.apache.airavata.service.profile.iam.admin.services.core.impl; + +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.common.utils.ServerSettings; +import org.apache.airavata.model.credential.store.PasswordCredential; +import org.apache.airavata.model.user.UserProfile; +import org.apache.airavata.model.workspace.Gateway; +import org.apache.airavata.service.profile.iam.admin.services.core.interfaces.TenantManagementInterface; +import org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException; +import org.keycloak.admin.client.Keycloak; +import org.keycloak.admin.client.resource.UserResource; +import org.keycloak.representations.idm.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; + +public class TenantManagementKeycloakImpl implements TenantManagementInterface { + +private final static Logger logger = LoggerFactory.getLogger(TenantManagementKeycloakImpl.class); + +private static Keycloak getClient(String adminUrl, String realm, PasswordCredential AdminPasswordCreds) { + +return Keycloak.getInstance( +adminUrl, +realm, // the realm to log in to +AdminPasswordCreds.getLoginUserName(), AdminPasswordCreds.getPassword(), // the user +"admin-cli"); // admin-cli is the client ID used for keycloak admin operations. +} + +@Override +public Gateway addTenant(PasswordCredential isSuperAdminPasswordCreds, Gateway gatewayDetails) throws IamAdminServicesException { +try { +// get client +Keycloak client = TenantManagementKeycloakImpl.getClient(ServerSettings.getIamServerUrl(), "master", isSuperAdminPasswordCreds); +// create realm +RealmRepresentation newRealmDetails = new RealmRepresentation(); +newRealmDetails.setEnabled(true); +newRealmDetails.setId(gatewayDetails.getGatewayId()); + newRealmDetails.setDisplayName(gatewayDetails.getGatewayName()); +newRealmDetails.setRealm(gatewayDetails.getGatewayId()); +RealmRepresentation realmWithRoles = TenantManagementKeycloakImpl.createDefaultRoles(newRealmDetails); +client.realms().create(realmWithRoles); +return gatewayDetails; +} catch (ApplicationSettingsException ex) { +logger.error("Error getting values from property file, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error getting Iam server Url from property file, reason: " + ex.getMessage()); +throw exception; +} catch (Exception ex){ +logger.error("Error creating Realm in Keycloak Server, reason: " + ex.getCause(), ex); +IamAdminServicesException exception = new IamAdminServicesException(); +exception.setMessage("Error creating Realm in Keycloak Server, reason: " + ex.getMessage()); +throw exception; +} +} + +public static RealmRepresentation createDefaultRoles(RealmRepresentation realmDetails){ +List defaultRoles = new ArrayList(); +RoleRepresentation adminRole = new RoleRepresentation(); +adminRole.setName("admin"); +
[GitHub] airavata pull request #108: Identity Server Admin Services
GitHub user anujbhan opened a pull request: https://github.com/apache/airavata/pull/108 Identity Server Admin Services Features: * Complete Gateway setup for Keycloak * User registration * Enabling user account Note: 2 Commits are repeated because of git rebase, just ignore them. You can merge this pull request into a Git repository by running: $ git pull https://github.com/anujbhan/airavata is-admin-services Alternatively you can review and apply these changes as the patch at: https://github.com/apache/airavata/pull/108.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #108 --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---