Search in sources :

Example 16 with Claim

use of org.wso2.carbon.user.core.claim.Claim in project airavata by apache.

the class MigrationManager method getUserProfilesFromWso2IS.

/* Method used to fetch all the user profiles from the registered tenants */
public List<UserProfileDAO> getUserProfilesFromWso2IS() {
    ArrayList<UserProfileDAO> userProfileList = new ArrayList<UserProfileDAO>();
    for (Wso2ISLoginCredentialsDAO creds : adminCredentials) {
        RemoteUserStoreManagerServiceStub isClient = Wso2IdentityServerClient.getAdminServiceClient(creds.getLoginUserName(), creds.getLoginPassword(), "RemoteUserStoreManagerService");
        String[] userList;
        System.out.println("Fetching User Profiles for " + creds.getGateway() + " tenant ...");
        try {
            userList = isClient.getUserList("http://wso2.org/claims/givenname", "*", "default");
            System.out.println("FirstName\tLastName\tEmail\t\t\tuserName\tCountry\tOrganization\tphone\tRoles");
            String[] claims = { "http://wso2.org/claims/givenname", "http://wso2.org/claims/lastname", "http://wso2.org/claims/emailaddress", "http://wso2.org/claims/country", "http://wso2.org/claims/organization", "http://wso2.org/claims/mobile", "http://wso2.org/claims/telephone", "http://wso2.org/claims/streetaddress", "http://wso2.org/claims/role", "http://wso2.org/claims/identity/accountLocked" };
            for (String user : userList) {
                UserProfileDAO userProfile = new UserProfileDAO();
                ClaimValue[] retrievedClaimValues = isClient.getUserClaimValuesForClaims(user, claims, null);
                List<String> phones = new ArrayList<String>();
                for (ClaimValue claim : retrievedClaimValues) {
                    if (claim.getClaimURI().equals(claims[0])) {
                        userProfile.setFirstName(claim.getValue());
                    } else if (claim.getClaimURI().equals(claims[1])) {
                        userProfile.setLastName(claim.getValue());
                    } else if (claim.getClaimURI().equals(claims[2])) {
                        userProfile.setEmail(claim.getValue());
                    } else if (claim.getClaimURI().equals(claims[3])) {
                        userProfile.setCountry(claim.getValue());
                    } else if (claim.getClaimURI().equals(claims[4])) {
                        userProfile.setOrganization(claim.getValue());
                    } else if (claim.getClaimURI().equals(claims[5]) || claim.getClaimURI().equals(claims[6])) {
                        phones.add(claim.getValue());
                    } else if (claim.getClaimURI().equals(claims[7])) {
                        userProfile.setAddress(claim.getValue());
                    } else if (claim.getClaimURI().equals(claims[8])) {
                        userProfile.setRoles(convertCommaSeparatedRolesToList(claim.getValue()));
                    } else if (claim.getClaimURI().equals(claims[9])) {
                        userProfile.setAccountLocked(claim.getValue().equals("true"));
                    }
                }
                // Lowercase all usernames as required by Keycloak and User Profile service
                userProfile.setUserName(user.toLowerCase());
                userProfile.setGatewayID(creds.getGateway());
                userProfile.setPhones(phones);
                if (!userProfile.isAccountLocked()) {
                    System.out.println(userProfile.getFirstName() + "\t" + userProfile.getLastName() + "\t" + userProfile.getUserName() + "\t" + userProfile.getEmail() + "\t" + userProfile.getCountry() + "\t" + userProfile.getOrganization() + "\t" + userProfile.getAddress() + "\t" + userProfile.getRoles());
                    userProfileList.add(userProfile);
                } else {
                    System.out.println("Skipping locked account for user " + user + "!");
                }
            }
        } catch (RemoteException e) {
            System.out.println(e.getMessage());
            System.out.println(e.getCause());
            e.printStackTrace();
        } catch (RemoteUserStoreManagerServiceUserStoreExceptionException e) {
            System.out.println(e.getMessage());
            System.out.println(e.getCause());
            e.printStackTrace();
        }
    }
    System.out.println("User profiles from all the tenant are retrieved ...");
    return userProfileList;
}
Also used : ClaimValue(org.wso2.carbon.um.ws.api.stub.ClaimValue) RemoteUserStoreManagerServiceStub(org.wso2.carbon.um.ws.api.stub.RemoteUserStoreManagerServiceStub) RemoteException(java.rmi.RemoteException) RemoteUserStoreManagerServiceUserStoreExceptionException(org.wso2.carbon.um.ws.api.stub.RemoteUserStoreManagerServiceUserStoreExceptionException)

Example 17 with Claim

use of org.wso2.carbon.user.core.claim.Claim in project carbon-business-process by wso2.

the class TaskOperationsImpl method claim.

/**
 * Claim responsibility for a task, i.e. set the task to status Reserved
 * @param taskIdURI : task identifier
 * @throws IllegalStateFault
 * @throws IllegalOperationFault
 * @throws IllegalArgumentFault
 * @throws IllegalAccessFault
 */
public void claim(final URI taskIdURI) throws IllegalStateFault, IllegalOperationFault, IllegalArgumentFault, IllegalAccessFault {
    try {
        final Long taskId = validateTaskId(taskIdURI);
        HumanTaskServiceComponent.getHumanTaskServer().getTaskEngine().getScheduler().execTransaction(new Callable<Object>() {

            public Object call() throws Exception {
                HumanTaskCommand claim = new Claim(getCaller(), taskId);
                claim.execute();
                return null;
            }
        });
    } catch (Exception ex) {
        handleException(ex);
    }
}
Also used : HumanTaskCommand(org.wso2.carbon.humantask.core.engine.HumanTaskCommand) HumanTaskIllegalArgumentException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) HumanTaskIllegalStateException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException) HumanTaskIllegalOperationException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) HumanTaskException(org.wso2.carbon.humantask.core.engine.HumanTaskException) HumanTaskIllegalAccessException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException) HumanTaskRuntimeException(org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException) Claim(org.wso2.carbon.humantask.core.engine.commands.Claim)

Example 18 with Claim

use of org.wso2.carbon.user.core.claim.Claim in project carbon-business-process by wso2.

the class UserSubstitutionUtils method handleScheduledEventByTenant.

public static synchronized boolean handleScheduledEventByTenant(int tenantId) {
    boolean result = true;
    TransitivityResolver resolver = SubstitutionDataHolder.getInstance().getTransitivityResolver();
    ActivitiDAO activitiDAO = SubstitutionDataHolder.getInstance().getActivitiDAO();
    if (SubstitutionDataHolder.getInstance().isTransitivityEnabled()) {
        // update transitives, only the map is updated here
        result = resolver.resolveTransitiveSubs(true, tenantId);
    } else {
        resolver.subsMap = activitiDAO.selectActiveSubstitutesByTenant(tenantId, new Date(System.currentTimeMillis()));
    }
    // flush into db
    for (Map.Entry<String, SubstitutesDataModel> entry : resolver.subsMap.entrySet()) {
        // go through the updated map
        SubstitutesDataModel model = entry.getValue();
        try {
            // set carbon context
            PrivilegedCarbonContext.startTenantFlow();
            PrivilegedCarbonContext context = PrivilegedCarbonContext.getThreadLocalCarbonContext();
            context.setUsername(model.getUser());
            context.setTenantId(tenantId, true);
            if (SubstitutionDataHolder.getInstance().isTransitivityEnabled()) {
                activitiDAO.updateSubstituteInfo(model);
            }
            if (!BPMNConstants.BULK_REASSIGN_PROCESSED.equals(model.getTaskList())) {
                // active substitution, not yet bulk reassigned
                String sub = getActualSubstitute(model);
                if (model.getTaskList() == null) {
                    // reassign all
                    if (sub != null) {
                        bulkReassign(model.getUser(), sub, null);
                    } else {
                        // transitivity undefined, assign to task owner or un-claim
                        assignToTaskOwner(model.getUser(), null);
                    }
                } else {
                    List<String> taskList = getTaskListFromString(model.getTaskList());
                    if (sub != null) {
                        bulkReassign(model.getUser(), sub, taskList);
                    } else {
                        // transitivity undefined, assign to task owner or un-claim
                        assignToTaskOwner(model.getUser(), taskList);
                    }
                }
                model.setTaskList(BPMNConstants.BULK_REASSIGN_PROCESSED);
                activitiDAO.updateSubstituteInfo(model);
            }
        } finally {
            PrivilegedCarbonContext.endTenantFlow();
            PrivilegedCarbonContext.destroyCurrentContext();
        }
    }
    // disable expired records
    disableExpiredRecords(tenantId);
    return result;
}
Also used : PaginatedSubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.PaginatedSubstitutesDataModel) SubstitutesDataModel(org.wso2.carbon.bpmn.core.mgt.model.SubstitutesDataModel) ActivitiDAO(org.wso2.carbon.bpmn.core.mgt.dao.ActivitiDAO) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext)

Example 19 with Claim

use of org.wso2.carbon.user.core.claim.Claim in project carbon-business-process by wso2.

the class BPSUserIdentityManager method transformQueryToClaim.

private List<Claim> transformQueryToClaim(UserQueryImpl userQuery) {
    List<Claim> claimList = new ArrayList<Claim>();
    if (userQuery.getEmail() != null) {
        Claim claim = new Claim();
        claim.setClaimUri(EMAIL_CLAIM_URI);
        claim.setValue(userQuery.getEmail());
        claimList.add(claim);
    }
    if (userQuery.getEmailLike() != null) {
        Claim claim = new Claim();
        claim.setClaimUri(EMAIL_CLAIM_URI);
        claim.setValue("*" + userQuery.getEmailLike() + "*");
        claimList.add(claim);
    }
    if (userQuery.getFirstName() != null) {
        Claim claim = new Claim();
        claim.setClaimUri(FIRST_NAME_CLAIM_URI);
        claim.setValue(userQuery.getFirstName());
        claimList.add(claim);
    }
    if (userQuery.getFirstNameLike() != null) {
        Claim claim = new Claim();
        claim.setClaimUri(FIRST_NAME_CLAIM_URI);
        claim.setValue("*" + userQuery.getFirstNameLike() + "*");
        claimList.add(claim);
    }
    if (userQuery.getFullNameLike() != null) {
        Claim claim = new Claim();
        claim.setClaimUri(FULL_NAME_CLAIM_URI);
        claim.setValue("*" + userQuery.getFullNameLike() + "*");
        claimList.add(claim);
    }
    if (userQuery.getGroupId() != null) {
        Claim claim = new Claim();
        claim.setClaimUri(ROLE_CLAIM_URI);
        claim.setValue(userQuery.getGroupId());
        claimList.add(claim);
    }
    if (userQuery.getId() != null) {
        Claim claim = new Claim();
        claim.setClaimUri(ID_CLAIM_URI);
        claim.setValue(userQuery.getId());
        claimList.add(claim);
    }
    if (userQuery.getLastName() != null) {
        Claim claim = new Claim();
        claim.setClaimUri(LAST_NAME_CLAIM_URI);
        claim.setValue(userQuery.getLastName());
        claimList.add(claim);
    }
    if (userQuery.getLastNameLike() != null) {
        Claim claim = new Claim();
        claim.setClaimUri(LAST_NAME_CLAIM_URI);
        claim.setValue("*" + userQuery.getLastNameLike() + "*");
        claimList.add(claim);
    }
    return claimList;
}
Also used : ArrayList(java.util.ArrayList) Claim(org.wso2.carbon.user.core.claim.Claim)

Example 20 with Claim

use of org.wso2.carbon.user.core.claim.Claim in project identity-outbound-auth-sms-otp by wso2-extensions.

the class SMSOTPAuthenticator method initiateAuthenticationRequest.

/**
 * Initiate the authentication request.
 */
@Override
protected void initiateAuthenticationRequest(HttpServletRequest request, HttpServletResponse response, AuthenticationContext context) throws AuthenticationFailedException {
    try {
        String username;
        AuthenticatedUser authenticatedUser;
        String mobileNumber;
        String tenantDomain = context.getTenantDomain();
        context.setProperty(SMSOTPConstants.AUTHENTICATION, SMSOTPConstants.AUTHENTICATOR_NAME);
        if (!tenantDomain.equals(SMSOTPConstants.SUPER_TENANT)) {
            IdentityHelperUtil.loadApplicationAuthenticationXMLFromRegistry(context, getName(), tenantDomain);
        }
        FederatedAuthenticatorUtil.setUsernameFromFirstStep(context);
        username = String.valueOf(context.getProperty(SMSOTPConstants.USER_NAME));
        authenticatedUser = (AuthenticatedUser) context.getProperty(SMSOTPConstants.AUTHENTICATED_USER);
        // find the authenticated user.
        if (authenticatedUser == null) {
            if (log.isDebugEnabled()) {
                log.debug("Authentication failed: Could not find the authenticated user. ");
            }
            throw new AuthenticationFailedException("Authentication failed: Cannot proceed further without identifying the user. ");
        }
        boolean isSMSOTPMandatory = SMSOTPUtils.isSMSOTPMandatory(context, getName());
        boolean isUserExists = FederatedAuthenticatorUtil.isUserExistInUserStore(username);
        String queryParams = FrameworkUtils.getQueryStringWithFrameworkContextId(context.getQueryParams(), context.getCallerSessionKey(), context.getContextIdentifier());
        String errorPage = getErrorPage(context);
        // SMS OTP authentication is mandatory and user doesn't disable SMS OTP claim in user's profile.
        if (isSMSOTPMandatory) {
            if (log.isDebugEnabled()) {
                log.debug("SMS OTP is mandatory. Hence processing in mandatory path");
            }
            processSMSOTPMandatoryCase(context, request, response, queryParams, username, isUserExists);
        } else if (isUserExists && !SMSOTPUtils.isSMSOTPDisableForLocalUser(username, context, getName())) {
            if (context.isRetrying() && !Boolean.parseBoolean(request.getParameter(SMSOTPConstants.RESEND))) {
                checkStatusCode(response, context, queryParams, errorPage);
            } else {
                mobileNumber = getMobileNumber(request, response, context, username, tenantDomain, queryParams);
                if (StringUtils.isNotEmpty(mobileNumber)) {
                    proceedWithOTP(response, context, errorPage, mobileNumber, queryParams, username);
                }
            }
        } else {
            processFirstStepOnly(authenticatedUser, context);
        }
    } catch (SMSOTPException e) {
        throw new AuthenticationFailedException("Failed to get the parameters from authentication xml fie. ", e);
    } catch (UserStoreException e) {
        throw new AuthenticationFailedException("Failed to get the user from User Store. ", e);
    }
}
Also used : AuthenticationFailedException(org.wso2.carbon.identity.application.authentication.framework.exception.AuthenticationFailedException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) SMSOTPException(org.wso2.carbon.identity.authenticator.smsotp.exception.SMSOTPException) AuthenticatedUser(org.wso2.carbon.identity.application.authentication.framework.model.AuthenticatedUser)

Aggregations

UserRealm (org.wso2.carbon.user.core.UserRealm)5 UserStoreManager (org.wso2.carbon.user.core.UserStoreManager)5 ArrayList (java.util.ArrayList)4 XSString (org.opensaml.core.xml.schema.XSString)4 RealmService (org.wso2.carbon.user.core.service.RealmService)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Assertion (org.opensaml.saml.saml2.core.Assertion)3 Response (org.opensaml.saml.saml2.core.Response)3 Subject (org.opensaml.saml.saml2.core.Subject)3 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)3 AuthenticatorsConfiguration (org.wso2.carbon.core.security.AuthenticatorsConfiguration)3 UserStoreException (org.wso2.carbon.user.api.UserStoreException)3 UserStoreException (org.wso2.carbon.user.core.UserStoreException)3 Claim (org.wso2.carbon.user.core.claim.Claim)3 RemoteException (java.rmi.RemoteException)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2