Java Code Examples for org.wso2.carbon.CarbonConstants

The following examples show how to use org.wso2.carbon.CarbonConstants. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public EmailVerificationServiceClient(ServletConfig config, HttpSession session)
        throws RegistryException {

    String cookie = (String)session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
    String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
    ConfigurationContext configContext = (ConfigurationContext) config.
            getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
    epr = backendServerURL + "EmailVerificationService";

    try {
        stub = new EmailVerificationServiceStub(configContext, epr);

        ServiceClient client = stub._getServiceClient();
        Options option = client.getOptions();
        option.setManageSession(true);
        option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);

    } catch (AxisFault axisFault) {
        String msg = "Failed to initiate Add Services service client. " + axisFault.getMessage();
        log.error(msg, axisFault);
        throw new RegistryException(msg, axisFault);
    }
}
 
Example 2
/**
 * Check for internal roles and convert internal role domain names to camel case to match with predefined
 * internal role domains.
 *
 * @param roles roles to verify and update
 * @return updated role list
 */
private List<String> convertInternalRoleDomainsToCamelCase(List<String> roles) {

    List<String> updatedRoles = new ArrayList<>();

    if (roles != null) {
        // If internal roles exist, convert internal role domain names to case sensitive predefined domain names.
        for (String role : roles) {
            if (StringUtils.containsIgnoreCase(role, UserCoreConstants.INTERNAL_DOMAIN + CarbonConstants
                    .DOMAIN_SEPARATOR)) {
                updatedRoles.add(UserCoreConstants.INTERNAL_DOMAIN + CarbonConstants.DOMAIN_SEPARATOR +
                        UserCoreUtil.removeDomainFromName(role));
            } else if (StringUtils.containsIgnoreCase(role, APPLICATION_DOMAIN + CarbonConstants.DOMAIN_SEPARATOR)) {
                updatedRoles.add(APPLICATION_DOMAIN + CarbonConstants.DOMAIN_SEPARATOR + UserCoreUtil
                        .removeDomainFromName(role));
            } else if (StringUtils.containsIgnoreCase(role, WORKFLOW_DOMAIN + CarbonConstants.DOMAIN_SEPARATOR)) {
                updatedRoles.add(WORKFLOW_DOMAIN + CarbonConstants.DOMAIN_SEPARATOR + UserCoreUtil
                        .removeDomainFromName(role));
            } else {
                updatedRoles.add(role);
            }
        }
    }

    return updatedRoles;
}
 
Example 3
Source Project: carbon-identity-framework   Source File: FrameworkUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static String prependUserStoreDomainToName(String authenticatedSubject) {

        if (authenticatedSubject == null || authenticatedSubject.trim().isEmpty()) {
            throw new IllegalArgumentException("Invalid argument. authenticatedSubject : "
                                               + authenticatedSubject);
        }
        if (!authenticatedSubject.contains(CarbonConstants.DOMAIN_SEPARATOR)) {
            if (UserCoreUtil.getDomainFromThreadLocal() != null
                && !UserCoreUtil.getDomainFromThreadLocal().isEmpty()) {
                authenticatedSubject = UserCoreUtil.getDomainFromThreadLocal()
                                       + CarbonConstants.DOMAIN_SEPARATOR + authenticatedSubject;
            }
        } else if (authenticatedSubject.indexOf(CarbonConstants.DOMAIN_SEPARATOR) == 0) {
            throw new IllegalArgumentException("Invalid argument. authenticatedSubject : "
                                               + authenticatedSubject + " begins with \'" + CarbonConstants.DOMAIN_SEPARATOR
                                               + "\'");
        }
        return authenticatedSubject;
    }
 
Example 4
Source Project: attic-stratos   Source File: RegistryAdminServiceClient.java    License: Apache License 2.0 6 votes vote down vote up
public RegistryAdminServiceClient(String cookie, ServletConfig config, HttpSession session)
        throws AxisFault {
    String serverURL = CarbonUIUtil.getServerURL(config.getServletContext(),
                session);
    ConfigurationContext ctx = (ConfigurationContext) config.
                getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
    this.session = session;
    String serviceEPR = serverURL + "RegistryAdminService";
    stub = new RegistryAdminServiceStub(ctx, serviceEPR);
    ServiceClient client = stub._getServiceClient();
    Options options = client.getOptions();
    options.setManageSession(true);
    if (cookie != null) {
        options.setProperty(HTTPConstants.COOKIE_STRING, cookie);
    }
}
 
Example 5
Source Project: carbon-identity-framework   Source File: UserAdmin.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param roleName
 * @param realm
 * @return
 * @throws UserAdminException
 */
private boolean isAllowedRoleName(String roleName, UserRealm realm) throws UserAdminException {

    if (roleName == null) {
        return false;
    }

    int index;
    index = roleName.indexOf(CarbonConstants.DOMAIN_SEPARATOR);

    if (index > 0) {
        roleName = roleName.substring(index + 1);
    }

    try {
        return !realm.getRealmConfiguration().isReservedRoleName(roleName);
    } catch (UserStoreException e) {
        throw new UserAdminException(e.getMessage(), e);
    }
}
 
Example 6
private static boolean isUserAuthorizedToConfigureProfile(UserRealm realm, String currentUserName,
                                                          String targetUser, String permission)
        throws UserStoreException {
    boolean isAuthrized = false;
    if (currentUserName == null) {
        //do nothing
    } else if (currentUserName.equals(targetUser)) {
        isAuthrized = true;
    } else {
        AuthorizationManager authorizer = realm.getAuthorizationManager();
        isAuthrized = authorizer.isUserAuthorized(currentUserName,
                CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION + permission,
                "ui.execute");
    }
    return isAuthrized;
}
 
Example 7
/**
 * Trigger after adding a workflow
 *
 * @param workflowDTO
 * @param parameterList
 * @param tenantId
 * @throws WorkflowException
 */
@Override
public void doPostAddWorkflow(Workflow workflowDTO, List<Parameter> parameterList, int tenantId) throws
        WorkflowException {
    String loggedInUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
    if (StringUtils.isBlank(loggedInUser)) {
        loggedInUser = CarbonConstants.REGISTRY_SYSTEM_USERNAME;
    }

    String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    loggedInUser = UserCoreUtil.addTenantDomainToEntry(loggedInUser, tenantDomain);

    String auditData = "\"" + "Workflow Name" + "\" : \"" + workflowDTO.getWorkflowName() + "\",\""
            + "Workflow  Impl ID" + "\" : \"" + workflowDTO.getWorkflowImplId() + "\",\""
            + "Workflow ID" + "\" : \"" + workflowDTO.getWorkflowId() + "\",\""
            + "Workflow Description" + "\" : \"" + workflowDTO.getWorkflowDescription() + "\",\""
            + "Template ID" + "\" : \"" + workflowDTO.getTemplateId() + "\"";
    AUDIT_LOG.info(String.format(AUDIT_MESSAGE, loggedInUser, "Add Workflow", auditData, AUDIT_SUCCESS));
}
 
Example 8
/**
 * Trigger after adding a association
 *
 * @param associationName
 * @param workflowId
 * @param eventId
 * @param condition
 * @throws WorkflowException
 */
@Override
public void doPostAddAssociation(String associationName, String workflowId, String eventId, String condition)
        throws WorkflowException {
    String loggedInUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
    if (StringUtils.isBlank(loggedInUser)) {
        loggedInUser = CarbonConstants.REGISTRY_SYSTEM_USERNAME;
    }

    String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    loggedInUser = UserCoreUtil.addTenantDomainToEntry(loggedInUser, tenantDomain);

    String auditData = "\"" + "Association Name" + "\" : \"" + associationName+ "\",\""
            + "Workflow ID" + "\" : \"" + workflowId + "\",\""
            + "Event ID" + "\" : \"" + eventId + "\",\""
            + "Condition" + "\" : \"" + condition + "\"";
    AUDIT_LOG.info(String.format(AUDIT_MESSAGE, loggedInUser, "Add Association", auditData, AUDIT_SUCCESS));
}
 
Example 9
Source Project: carbon-commons   Source File: DeploymentSynchronizer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * This method is deprecated. Refer {@link ArtifactRepository#checkout(int, String, int)}
 * for more info.
 *
 */
@Deprecated
public boolean syncGhostMetaArtifacts() throws DeploymentSynchronizerException {
    log.info("Doing ghost meta artifacts sync up...");
    boolean hasFailed = false;
    if (autoCheckout && lastCheckoutTime == -1L) {
        log.info("Checking out...");
        // checkout with empty depth
        checkout(filePath, 2);
        // update modules and its metafiles
        update(filePath, filePath + File.separator +
                         CarbonConstants.MODULES_DEPLOYMENT_DIR, 3);
        update(filePath, filePath + File.separator +
                         CarbonConstants.MODULE_METAFILE_HOTDEPLOYMENT_DIR, 3);
        // then update only the ghost meta files
        hasFailed = update(filePath, filePath + File.separator +
                                     CarbonConstants.GHOST_METAFILE_DIR, 3);
    }
    return hasFailed;
}
 
Example 10
/**
 * Trigger after executing a workflow request
 *
 * @param workFlowRequest
 * @throws WorkflowException
 */
@Override
public void doPostExecuteWorkflow(WorkflowRequest workFlowRequest, WorkflowExecutorResult result) throws
        WorkflowException {
    String loggedInUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
    if (StringUtils.isBlank(loggedInUser)) {
        loggedInUser = CarbonConstants.REGISTRY_SYSTEM_USERNAME;
    }

    String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    loggedInUser = UserCoreUtil.addTenantDomainToEntry(loggedInUser, tenantDomain);

    String auditData = "\"" + "Operation Type" + "\" : \"" + workFlowRequest.getEventType()
            + "\",\"" + "Request parameters" + "\" : \"" + workFlowRequest.getRequestParameterAsString()
            + "\"";
    AUDIT_LOG.info(String.format(AUDIT_MESSAGE, loggedInUser, "Initiate Workflow", auditData,
            AUDIT_SUCCESS));
}
 
Example 11
Source Project: carbon-identity-framework   Source File: CaptchaUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static void setAnonAuthorization(String path, UserRealm userRealm)
        throws RegistryException {

    if (userRealm == null) {
        return;
    }

    try {
        AuthorizationManager accessControlAdmin = userRealm.getAuthorizationManager();
        String everyoneRole = CarbonConstants.REGISTRY_ANONNYMOUS_ROLE_NAME;

        accessControlAdmin.authorizeRole(everyoneRole, path, ActionConstants.GET);
        accessControlAdmin.denyRole(everyoneRole, path, ActionConstants.PUT);
        accessControlAdmin.denyRole(everyoneRole, path, ActionConstants.DELETE);
        accessControlAdmin.denyRole(everyoneRole, path, AccessControlConstants.AUTHORIZE);

    } catch (UserStoreException e) {
        String msg = "Could not set authorizations for the " + path + ".";
        log.error(msg, e);
        throw new RegistryException(msg);
    }
}
 
Example 12
Source Project: carbon-identity   Source File: FrameworkUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static String prependUserStoreDomainToName(String authenticatedSubject) {

        if (authenticatedSubject == null || authenticatedSubject.trim().isEmpty()) {
            throw new IllegalArgumentException("Invalid argument. authenticatedSubject : "
                                               + authenticatedSubject);
        }
        if (!authenticatedSubject.contains(CarbonConstants.DOMAIN_SEPARATOR)) {
            if (UserCoreUtil.getDomainFromThreadLocal() != null
                && !UserCoreUtil.getDomainFromThreadLocal().isEmpty()) {
                authenticatedSubject = UserCoreUtil.getDomainFromThreadLocal()
                                       + CarbonConstants.DOMAIN_SEPARATOR + authenticatedSubject;
            }
        } else if (authenticatedSubject.indexOf(CarbonConstants.DOMAIN_SEPARATOR) == 0) {
            throw new IllegalArgumentException("Invalid argument. authenticatedSubject : "
                                               + authenticatedSubject + " begins with \'" + CarbonConstants.DOMAIN_SEPARATOR
                                               + "\'");
        }
        return authenticatedSubject;
    }
 
Example 13
Source Project: carbon-identity   Source File: STSUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Initializes STSUtil
 *
 * @param cookie Cookie string
 * @throws Exception
 */
public STSUtil(ServletConfig config, HttpSession session, String cookie) throws Exception {
    ServiceClient client = null;
    Options option = null;
    String serverUrl = null;

    // Obtaining the client-side ConfigurationContext instance.
    configContext = (ConfigurationContext) config.getServletContext().getAttribute(
            CarbonConstants.CONFIGURATION_CONTEXT);

    // Server URL which is defined in the server.xml
    serverUrl = CarbonUIUtil.getServerURL(config.getServletContext(), session);

    this.serviceEndPoint = serverUrl + "STSAdminService";
    try {
        this.stub = new STSAdminServiceStub(configContext, serviceEndPoint);
    } catch (AxisFault e) {
        log.error("Error while creating STSAdminServiceStub", e);
        throw new Exception(e);
    }
    client = stub._getServiceClient();
    option = client.getOptions();
    option.setManageSession(true);
    option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
}
 
Example 14
Source Project: attic-stratos   Source File: UIBundleDeployer.java    License: Apache License 2.0 6 votes vote down vote up
private void processFileUploadExecutorDefinitions(Component component , String action) throws
        CarbonException{
    if (component.getFileUploadExecutorConfigs() != null
            && component.getFileUploadExecutorConfigs().length > 0) {
        FileUploadExecutorManager executorManager =
                (FileUploadExecutorManager) fileUploadExecManagerTracker.getService();
        if (executorManager == null) {
            log.error("FileUploadExecutorManager service is not available");
            return;
        }
        FileUploadExecutorConfig[] executorConfigs = component.getFileUploadExecutorConfigs();
        for (FileUploadExecutorConfig executorConfig : executorConfigs) {
            String[] mappingActions = executorConfig.getMappingActionList();
            for (String mappingAction : mappingActions) {
                if (CarbonConstants.ADD_UI_COMPONENT.equals(action)) {
                    executorManager.addExecutor(mappingAction,
                            executorConfig.getFUploadExecClass());
                } else if (CarbonConstants.REMOVE_UI_COMPONENT.equals(action)) {
                    executorManager.removeExecutor(mappingAction);
                }
            }
        }
    }
}
 
Example 15
Source Project: attic-stratos   Source File: CarbonSecuredHttpContext.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param indexPageURL
 * @return
 */
private String updateIndexPageWithHomePage(String indexPageURL) {
    // If the params in the servletcontext is null get them from the UTIL
    if (defaultHomePage == null) {
        defaultHomePage = (String) CarbonUIUtil
                .getProductParam(CarbonConstants.PRODUCT_XML_WSO2CARBON
                        + CarbonConstants.DEFAULT_HOME_PAGE);
    }

    if (defaultHomePage != null && defaultHomePage.trim().length() > 0
            && indexPageURL.contains("/carbon/admin/index.jsp")) {
        indexPageURL = defaultHomePage;
        if (!indexPageURL.startsWith("/")) {
            indexPageURL = "/" + indexPageURL;
        }
    }

    return indexPageURL;
}
 
Example 16
protected void activate(ComponentContext cxt) {
    try {
        SignedJWTAuthenticator authenticator = new SignedJWTAuthenticator();
        SignedJWTAuthenticatorServiceComponent.setBundleContext(cxt.getBundleContext());
        Hashtable<String, String> props = new Hashtable<String, String>();
        props.put(CarbonConstants.AUTHENTICATOR_TYPE, authenticator.getAuthenticatorName());
        cxt.getBundleContext().registerService(CarbonServerAuthenticator.class.getName(),
                authenticator, props);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        // throwing so that server will not start
        throw new RuntimeException("Failed to start the Signed JWT Authenticator Bundle" +
                e.getMessage(), e);
    }
    log.debug("Signed JWT Authenticator is activated");
}
 
Example 17
Source Project: carbon-commons   Source File: QpidJMSDeliveryManager.java    License: Apache License 2.0 6 votes vote down vote up
protected Properties getInitialContextProperties(String userName, String password) {

        Properties initialContextProperties = new Properties();
        QpidServerDetails qpidServerDetails = EventBrokerHolder.getInstance().getQpidServerDetails();
        initialContextProperties.put(Context.INITIAL_CONTEXT_FACTORY, QPID_ICF);
        initialContextProperties.put(CarbonConstants.REQUEST_BASE_CONTEXT, "true");
        String connectionURL = null;
        if (MB_TYPE_LOCAL.equals(this.type)) {
            connectionURL = qpidServerDetails.getTCPConnectionURL(userName, qpidServerDetails.getAccessKey());
        } else {
            connectionURL = "amqp://" + userName + ":" + this.accessKey
                    + "@" + clientID + "/" + this.virtualHostName
                    + "?brokerlist='tcp://" + this.hostName + ":" + this.qpidPort + "'";
        }
        initialContextProperties.put(CF_NAME_PREFIX + CF_NAME, connectionURL);
        return initialContextProperties;
    }
 
Example 18
Source Project: carbon-identity   Source File: IWAUIAuthenticator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param request
 * @return
 * @throws AxisFault
 */
private IWAAuthenticatorStub getIWAClient(HttpServletRequest request)
        throws AxisFault, IdentityException {

    HttpSession session = request.getSession();
    ServletContext servletContext = session.getServletContext();
    String backendServerURL = request.getParameter("backendURL");
    if (backendServerURL == null) {
        backendServerURL = CarbonUIUtil.getServerURL(servletContext, request.getSession());
    }

    ConfigurationContext configContext = (ConfigurationContext) servletContext
            .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);

    String serviceEPR = backendServerURL + "IWAAuthenticator";
    IWAAuthenticatorStub stub = new IWAAuthenticatorStub(configContext, serviceEPR);
    ServiceClient client = stub._getServiceClient();
    client.engageModule("rampart");
    Policy rampartConfig = IdentityBaseUtil.getDefaultRampartConfig();
    Policy signOnly = IdentityBaseUtil.getSignOnlyPolicy();
    Policy mergedPolicy = signOnly.merge(rampartConfig);
    Options options = client.getOptions();
    options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, mergedPolicy);
    options.setManageSession(true);
    return stub;
}
 
Example 19
Source Project: carbon-commons   Source File: CommonUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static void setAnonAuthorization(String path, UserRealm userRealm)
        throws RegistryException {

    if (userRealm == null) {
        return;
    }

    try {
        AuthorizationManager accessControlAdmin = userRealm.getAuthorizationManager();
        String everyoneRole = CarbonConstants.REGISTRY_ANONNYMOUS_ROLE_NAME;

        accessControlAdmin.authorizeRole(everyoneRole, path, ActionConstants.GET);
        accessControlAdmin.denyRole(everyoneRole, path, ActionConstants.PUT);
        accessControlAdmin.denyRole(everyoneRole, path, ActionConstants.DELETE);
        accessControlAdmin.denyRole(everyoneRole, path, AccessControlConstants.AUTHORIZE);

    } catch (UserStoreException e) {
        String msg = "Could not set authorizations for the " + path + ".";
        log.error(msg, e);
        throw new RegistryException(msg);
    }
}
 
Example 20
Source Project: carbon-commons   Source File: CompositeReportProcessor.java    License: Apache License 2.0 6 votes vote down vote up
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws
        Exception {
    String webContext = (String) request.getAttribute(CarbonConstants.WEB_CONTEXT);
    HttpSession session = request.getSession();
    String serverURL = CarbonUIUtil.getServerURL(getServletContext(), session);
    ConfigurationContext configContext =
            (ConfigurationContext) getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);

    ReportTemplateClient client;
    String errorString = "";

    client = new ReportTemplateClient(configContext, serverURL, cookie);
    String reportname = request.getParameter("reportName");
    String[] reports = getSubReportsName(request);

    if (reports != null) {
        client.addNewCompositeReport(reports, reportname);
        response.sendRedirect("../reporting_custom/list-reports.jsp?region=region5&item=reporting_list");
    } else {
        errorString = "No reports was sleected to form the composite report";
        request.setAttribute("errorString", errorString);
        response.sendRedirect("../reporting-template/add-composite-report.jsp");
    }
}
 
Example 21
Source Project: carbon-identity   Source File: WorkflowImplAuditLogger.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Trigger after adding new BPS profile
 *
 * @param bpsProfileDTO
 * @param tenantId
 * @throws WorkflowImplException
 */
@Override
public void doPostAddBPSProfile(BPSProfile bpsProfileDTO, int tenantId) throws WorkflowImplException {
    String loggedInUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
    if (StringUtils.isBlank(loggedInUser)) {
        loggedInUser = CarbonConstants.REGISTRY_SYSTEM_USERNAME;
    }
    String auditData = "\"" + "Profile Name" + "\" : \"" + bpsProfileDTO.getProfileName()
            + "\",\"" + "Manager Host URL" + "\" : \"" + bpsProfileDTO.getManagerHostURL()
            + "\",\"" + "Worker Host URL" + "\" : \"" + bpsProfileDTO.getWorkerHostURL()
            + "\",\"" + "User" + "\" : \"" + bpsProfileDTO.getUsername()
            + "\"";
    AUDIT_LOG.info(String.format(AUDIT_MESSAGE, loggedInUser, "Add BPS Profile", auditData, AUDIT_SUCCESS));
}
 
Example 22
protected String getUserStoreAppendedName(String userName) {
    if (!userName.contains(CarbonConstants.DOMAIN_SEPARATOR) && UserCoreUtil.getDomainFromThreadLocal() != null
        && !"".equals(UserCoreUtil.getDomainFromThreadLocal())) {
        userName = UserCoreUtil.getDomainFromThreadLocal() + CarbonConstants.DOMAIN_SEPARATOR + userName;
    }
    return userName;
}
 
Example 23
private String removeDomainFromUserName(String username) {
    int index;
    if ((index = username.indexOf(CarbonConstants.DOMAIN_SEPARATOR)) >= 0) {
        // remove domain name if exist
        username = username.substring(index + 1);
    }
    return username;
}
 
Example 24
/**
 * To check whether the application owner is valid by validating user existence and permissions.
 *
 * @param serviceProvider service provider
 * @return true if the application owner is valid.
 * @throws IdentityApplicationManagementException when an error occurs while validating the user.
 */
public static boolean isValidApplicationOwner(ServiceProvider serviceProvider)
        throws IdentityApplicationManagementException {

    try {
        String userName;
        String userNameWithDomain;
        if (serviceProvider.getOwner() != null) {
            userName = serviceProvider.getOwner().getUserName();
            if (StringUtils.isEmpty(userName) || CarbonConstants.REGISTRY_SYSTEM_USERNAME.equals(userName)) {
                return false;
            }
            String userStoreDomain = serviceProvider.getOwner().getUserStoreDomain();
            userNameWithDomain = IdentityUtil.addDomainToName(userName, userStoreDomain);

            org.wso2.carbon.user.api.UserRealm realm = CarbonContext.getThreadLocalCarbonContext().getUserRealm();
            if (realm == null || StringUtils.isEmpty(userNameWithDomain)) {
                return false;
            }
            boolean isUserExist = realm.getUserStoreManager().isExistingUser(userNameWithDomain);
            if (!isUserExist) {
                throw new IdentityApplicationManagementException("User validation failed for owner update in the " +
                        "application: " +
                        serviceProvider.getApplicationName() + " as user is not existing.");
            }
        } else {
            return false;
        }
    } catch (UserStoreException | IdentityApplicationManagementException e) {
        throw new IdentityApplicationManagementException("User validation failed for owner update in the " +
                "application: " +
                serviceProvider.getApplicationName(), e);
    }
    return true;
}
 
Example 25
/**
 * Remove domain from user name.
 *
 * @param username Username
 * @return
 */
public static String getUsernameWithoutDomain(String username) {
    int index = username.indexOf(CarbonConstants.DOMAIN_SEPARATOR);
    if (index < 0) {
        return username;
    }
    return username.substring(index + 1, username.length());
}
 
Example 26
private boolean isOwnerUpdateRequest(User storedAppOwner, User updatedAppOwner) {

        if (updatedAppOwner != null) {
            boolean isValidAppOwnerInUpdateRequest = StringUtils.isNotEmpty(updatedAppOwner.getUserName())
                    && !CarbonConstants.REGISTRY_SYSTEM_USERNAME.equals(updatedAppOwner.getUserName());
            boolean isOwnerChanged = !storedAppOwner.equals(updatedAppOwner);

            return isValidAppOwnerInUpdateRequest && isOwnerChanged;
        } else {
            // There is no app owner defined in the update request. Nothing to do there.
            return false;
        }
    }
 
Example 27
Source Project: carbon-identity   Source File: WorkflowAuditLogger.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Trigger after adding a association
 *
 * @param associationName
 * @param workflowId
 * @param eventId
 * @param condition
 * @throws WorkflowException
 */
@Override
public void doPostAddAssociation(String associationName, String workflowId, String eventId, String condition)
        throws WorkflowException {
    String loggedInUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
    if (StringUtils.isBlank(loggedInUser)) {
        loggedInUser = CarbonConstants.REGISTRY_SYSTEM_USERNAME;
    }
    String auditData = "\"" + "Association Name" + "\" : \"" + associationName+ "\",\""
            + "Workflow ID" + "\" : \"" + workflowId + "\",\""
            + "Event ID" + "\" : \"" + eventId + "\",\""
            + "Condition" + "\" : \"" + condition + "\"";
    AUDIT_LOG.info(String.format(AUDIT_MESSAGE, loggedInUser, "Add Association", auditData, AUDIT_SUCCESS));
}
 
Example 28
private String getUserStoreDomainName(String userName) {
    String userNameWithoutDomain = userName;
    int index;
    if ((index = userName.indexOf(CarbonConstants.DOMAIN_SEPARATOR)) >= 0) {
        // remove domain name if exist
        userNameWithoutDomain = userName.substring(0, index);
    }
    return userNameWithoutDomain;
}
 
Example 29
Source Project: carbon-identity-framework   Source File: Utils.java    License: Apache License 2.0 5 votes vote down vote up
public static String getUserStoreDomainName(String userName) {
    int index;
    String userDomain;
    if ((index = userName.indexOf(CarbonConstants.DOMAIN_SEPARATOR)) >= 0) {
        // remove domain name if exist
        userDomain = userName.substring(0, index);
    } else {
        userDomain = UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME;
    }
    return userDomain;
}
 
Example 30
Source Project: carbon-identity-framework   Source File: UserRealmInfo.java    License: Apache License 2.0 5 votes vote down vote up
public UserStoreInfo getUserStoreInfoForUser(String userName) {

        if (userName.contains(CarbonConstants.DOMAIN_SEPARATOR)) {
            String domainName = userName.substring(0, userName.indexOf(CarbonConstants.DOMAIN_SEPARATOR));
            for (UserStoreInfo info : userStoresInfo) {
                if (domainName != null && domainName.equalsIgnoreCase(info.getDomainName())) {
                    return info;
                }
            }
        }

        return primaryUserStoreInfo;
    }