From 4a4349382a317255a1fffb9345499597dc7d7180 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Tue, 19 May 2015 20:45:12 +0530 Subject: [PATCH] Adding the user core changes --- .../mgt/common/PolicyVerficationPoint.java | 25 ++++++++ .../common/PolicyVerificationException.java | 57 +++++++++++++++++++ .../pom.xml | 1 + .../device/mgt/user/core/UserManagerImpl.java | 42 ++++++++++---- 4 files changed, 115 insertions(+), 10 deletions(-) create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyVerficationPoint.java create mode 100644 components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyVerificationException.java diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyVerficationPoint.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyVerficationPoint.java new file mode 100644 index 00000000000..6f2eb186df6 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyVerficationPoint.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. 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.wso2.carbon.policy.mgt.common; + +public interface PolicyVerficationPoint { + + boolean verifyPolicyOfDevice(); +} diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyVerificationException.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyVerificationException.java new file mode 100644 index 00000000000..f0a25966c12 --- /dev/null +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyVerificationException.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. 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.wso2.carbon.policy.mgt.common; + +public class PolicyVerificationException extends Exception { + + private String policyVerificationErrorMessage; + + public String getPolicyVerificationErrorMessage() { + return policyVerificationErrorMessage; + } + + public void setPolicyVerificationErrorMessage(String policyVerificationErrorMessage) { + this.policyVerificationErrorMessage = policyVerificationErrorMessage; + } + + public PolicyVerificationException(String message) { + super(message); + setPolicyVerificationErrorMessage(message); + } + + public PolicyVerificationException(String message, Exception ex) { + super(message, ex); + setPolicyVerificationErrorMessage(message); + } + + public PolicyVerificationException(String message, Throwable cause) { + super(message, cause); + setPolicyVerificationErrorMessage(message); + } + + public PolicyVerificationException() { + super(); + } + + public PolicyVerificationException(Throwable cause) { + super(cause); + } + +} diff --git a/components/user-mgt/org.wso2.carbon.device.mgt.user.core/pom.xml b/components/user-mgt/org.wso2.carbon.device.mgt.user.core/pom.xml index df5431c6662..ab732588c0e 100644 --- a/components/user-mgt/org.wso2.carbon.device.mgt.user.core/pom.xml +++ b/components/user-mgt/org.wso2.carbon.device.mgt.user.core/pom.xml @@ -56,6 +56,7 @@ org.wso2.carbon.device.mgt.user.common.*, org.wso2.carbon.user.core.*, + org.wso2.carbon.user.core, org.apache.commons.logging.*, org.osgi.framework.*, org.osgi.service.component.*, diff --git a/components/user-mgt/org.wso2.carbon.device.mgt.user.core/src/main/java/org/wso2/carbon/device/mgt/user/core/UserManagerImpl.java b/components/user-mgt/org.wso2.carbon.device.mgt.user.core/src/main/java/org/wso2/carbon/device/mgt/user/core/UserManagerImpl.java index e5ec26aeae3..65656401ffa 100644 --- a/components/user-mgt/org.wso2.carbon.device.mgt.user.core/src/main/java/org/wso2/carbon/device/mgt/user/core/UserManagerImpl.java +++ b/components/user-mgt/org.wso2.carbon.device.mgt.user.core/src/main/java/org/wso2/carbon/device/mgt/user/core/UserManagerImpl.java @@ -24,11 +24,13 @@ import org.wso2.carbon.device.mgt.user.common.Role; import org.wso2.carbon.device.mgt.user.common.User; import org.wso2.carbon.device.mgt.user.common.UserManagementException; import org.wso2.carbon.device.mgt.user.core.internal.DeviceMgtUserDataHolder; +import org.wso2.carbon.user.api.Claim; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreManager; import org.wso2.carbon.user.core.UserCoreConstants; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -59,9 +61,9 @@ public class UserManagerImpl implements UserManager { public static final String IDENTITY_CLAIM_URI = UserCoreConstants.ClaimTypeURIs.IDENTITY_CLAIM_URI; public static final String TEMPORARY_EMAIL_ADDRESS = UserCoreConstants.ClaimTypeURIs.TEMPORARY_EMAIL_ADDRESS; - public static final String[] DEFAULT_CLAIM_ARR = new String[]{GIVEN_NAME,EMAIL_ADDRESS,SURNAME,STREET_ADDRESS, - LOCALITY,REGION,REGION,POSTAL_CODE,COUNTRY,HONE,IM,ORGANIZATION,URL,TITLE,ROLE,MOBILE,NICKNAME, - DATE_OF_BIRTH,GENDER,ACCOUNT_STATUS,CHALLENGE_QUESTION_URI,IDENTITY_CLAIM_URI,TEMPORARY_EMAIL_ADDRESS}; +// public static final String[] DEFAULT_CLAIM_ARR = new String[]{GIVEN_NAME,EMAIL_ADDRESS,SURNAME,STREET_ADDRESS, +// LOCALITY,REGION,REGION,POSTAL_CODE,COUNTRY,HONE,IM,ORGANIZATION,URL,TITLE,ROLE,MOBILE,NICKNAME, +// DATE_OF_BIRTH,GENDER,ACCOUNT_STATUS,CHALLENGE_QUESTION_URI,IDENTITY_CLAIM_URI,TEMPORARY_EMAIL_ADDRESS}; // private static final String CLAIM_URL_ @@ -80,8 +82,14 @@ public class UserManagerImpl implements UserManager { User newUser; for (String userName : userNames) { newUser = new User(userName); - setUserClaims(newUser, userStoreManager.getUserClaimValues(userName, DEFAULT_CLAIM_ARR, - UserCoreConstants.DEFAULT_PROFILE)); + Claim[] claims = userStoreManager.getUserClaimValues(userName, null); + Map claimMap = new HashMap(); + for(Claim claim:claims){ + String claimURI = claim.getClaimUri(); + String value = claim.getValue(); + claimMap.put(claimURI, value); + } + setUserClaims(newUser, claimMap); usersList.add(newUser); } } catch (UserStoreException userStoreEx) { @@ -129,12 +137,18 @@ public class UserManagerImpl implements UserManager { userStoreManager = DeviceMgtUserDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId) .getUserStoreManager(); - userNames = userStoreManager.listUsers("",-1); + userNames = userStoreManager.listUsers("", -1); User newUser; for (String userName : userNames) { newUser = new User(userName); - setUserClaims(newUser, userStoreManager.getUserClaimValues(userName, DEFAULT_CLAIM_ARR, - UserCoreConstants.DEFAULT_PROFILE)); + Claim[] claims = userStoreManager.getUserClaimValues(userName, null); + Map claimMap = new HashMap(); + for(Claim claim:claims){ + String claimURI = claim.getClaimUri(); + String value = claim.getValue(); + claimMap.put(claimURI, value); + } + setUserClaims(newUser, claimMap); usersList.add(newUser); } } catch (UserStoreException userStoreEx) { @@ -153,8 +167,16 @@ public class UserManagerImpl implements UserManager { userStoreManager = DeviceMgtUserDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId) .getUserStoreManager(); user = new User(username); - setUserClaims(user, userStoreManager - .getUserClaimValues(username, DEFAULT_CLAIM_ARR, UserCoreConstants.DEFAULT_PROFILE)); + + Claim[] claims = userStoreManager.getUserClaimValues(username, null); + Map claimMap = new HashMap(); + for(Claim claim:claims){ + String claimURI = claim.getClaimUri(); + String value = claim.getValue(); + claimMap.put(claimURI, value); + } + + setUserClaims(user, claimMap); } catch (UserStoreException userStoreEx) { String errorMsg = "User store error in fetching user " + username; log.error(errorMsg, userStoreEx);