Search in sources :

Example 11 with UserRegistrationConfigDTO

use of org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO in project carbon-apimgt by wso2.

the class SelfSignupUtilTestCase method testGetDomainSpecificRoleNameWithWrongDomain.

@Test
public void testGetDomainSpecificRoleNameWithWrongDomain() {
    UserRegistrationConfigDTO userRegistrationConfigDTO = new UserRegistrationConfigDTO();
    userRegistrationConfigDTO.setSignUpDomain("foo.com");
    String domainSpecificRoleName = SelfSignUpUtil.getDomainSpecificUserName("bar.com/john", userRegistrationConfigDTO);
    Assert.assertEquals("FOO.COM/john", domainSpecificRoleName);
}
Also used : UserRegistrationConfigDTO(org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with UserRegistrationConfigDTO

use of org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO in project carbon-apimgt by wso2.

the class SelfSignupUtilTestCase method testGetRoleNames.

@Test
public void testGetRoleNames() {
    UserRegistrationConfigDTO userRegistrationConfigDTO = new UserRegistrationConfigDTO();
    Map<String, Boolean> roles = new HashMap();
    roles.put("subscriber", true);
    roles.put("creator", false);
    userRegistrationConfigDTO.setRoles(roles);
    userRegistrationConfigDTO.setSignUpDomain("foo.com");
    List<String> roleList = SelfSignUpUtil.getRoleNames(userRegistrationConfigDTO);
    Assert.assertEquals(2, roleList.size());
}
Also used : HashMap(java.util.HashMap) UserRegistrationConfigDTO(org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with UserRegistrationConfigDTO

use of org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO in project carbon-apimgt by wso2.

the class SelfSignupUtilTestCase method testGetDomainSpecificRoleName.

@Test
public void testGetDomainSpecificRoleName() {
    UserRegistrationConfigDTO userRegistrationConfigDTO = new UserRegistrationConfigDTO();
    userRegistrationConfigDTO.setSignUpDomain("foo.com");
    String domainSpecificRoleName = SelfSignUpUtil.getDomainSpecificUserName("john", userRegistrationConfigDTO);
    Assert.assertEquals("FOO.COM/john", domainSpecificRoleName);
}
Also used : UserRegistrationConfigDTO(org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with UserRegistrationConfigDTO

use of org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO in project carbon-apimgt by wso2.

the class UserSignUpSimpleWorkflowExecutor method complete.

@Override
public WorkflowResponse complete(WorkflowDTO workflowDTO) throws WorkflowException {
    if (log.isDebugEnabled()) {
        log.debug("User Sign Up [Complete] Workflow Invoked. Workflow ID : " + workflowDTO.getExternalWorkflowReference() + "Workflow State : " + workflowDTO.getStatus());
    }
    String tenantDomain = workflowDTO.getTenantDomain();
    try {
        UserRegistrationConfigDTO signupConfig = SelfSignUpUtil.getSignupConfiguration(tenantDomain);
        String tenantAwareUserName = MultitenantUtils.getTenantAwareUsername(workflowDTO.getWorkflowReference());
        updateRolesOfUser(tenantAwareUserName, SelfSignUpUtil.getRoleNames(signupConfig), tenantDomain);
    } catch (APIManagementException e) {
        throw new WorkflowException("Error while accessing signup configuration", e);
    } catch (Exception e) {
        throw new WorkflowException("Error while assigning role to user", e);
    }
    return new GeneralWorkflowResponse();
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) UserRegistrationConfigDTO(org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException)

Example 15 with UserRegistrationConfigDTO

use of org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO in project carbon-apimgt by wso2.

the class SelfSignUpUtil method getSignupConfigurationFromRegistry.

/**
 * load configuration from the registry
 *
 * @param tenantDomain - The Tenant Domain
 * @return - A UserRegistrationConfigDTO instance
 * @throws APIManagementException
 */
private static UserRegistrationConfigDTO getSignupConfigurationFromRegistry(String tenantDomain) throws APIManagementException {
    UserRegistrationConfigDTO config;
    try {
        String selfSighupConfig = ServiceReferenceHolder.getInstance().getApimConfigService().getSelfSighupConfig(tenantDomain);
        OMElement element = AXIOMUtil.stringToOM(selfSighupConfig);
        config = new UserRegistrationConfigDTO();
        config.setSignUpDomain(element.getFirstChildWithName(new QName(APIConstants.SELF_SIGN_UP_REG_DOMAIN_ELEM)).getText());
        config.setAdminUserName(APIUtil.replaceSystemProperty(element.getFirstChildWithName(new QName(APIConstants.SELF_SIGN_UP_REG_USERNAME)).getText()));
        String encryptedPassword = element.getFirstChildWithName(new QName(APIConstants.SELF_SIGN_UP_REG_PASSWORD)).getText();
        PasswordResolver passwordResolver = PasswordResolverFactory.getInstance();
        String resovledPassword = passwordResolver.getPassword(encryptedPassword);
        config.setAdminPassword(APIUtil.replaceSystemProperty(resovledPassword));
        config.setSignUpEnabled(Boolean.parseBoolean(element.getFirstChildWithName(new QName(APIConstants.SELF_SIGN_UP_REG_ENABLED)).getText()));
        OMElement rolesElement = element.getFirstChildWithName(new QName(APIConstants.SELF_SIGN_UP_REG_ROLES_ELEM));
        Iterator roleListIterator = rolesElement.getChildrenWithLocalName(APIConstants.SELF_SIGN_UP_REG_ROLE_ELEM);
        while (roleListIterator.hasNext()) {
            OMElement roleElement = (OMElement) roleListIterator.next();
            String tmpRole = roleElement.getFirstChildWithName(new QName(APIConstants.SELF_SIGN_UP_REG_ROLE_NAME_ELEMENT)).getText();
            boolean tmpIsExternal = Boolean.parseBoolean(roleElement.getFirstChildWithName(new QName(APIConstants.SELF_SIGN_UP_REG_ROLE_IS_EXTERNAL)).getText());
            config.getRoles().put(tmpRole, tmpIsExternal);
        }
    } catch (XMLStreamException e) {
        throw new APIManagementException("Error while parsing configuration ", e);
    }
    return config;
}
Also used : PasswordResolver(org.wso2.carbon.apimgt.api.PasswordResolver) XMLStreamException(javax.xml.stream.XMLStreamException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) UserRegistrationConfigDTO(org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO) QName(javax.xml.namespace.QName) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement)

Aggregations

UserRegistrationConfigDTO (org.wso2.carbon.apimgt.impl.dto.UserRegistrationConfigDTO)16 Test (org.junit.Test)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 HashMap (java.util.HashMap)7 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)6 Iterator (java.util.Iterator)3 QName (javax.xml.namespace.QName)3 OMElement (org.apache.axiom.om.OMElement)3 PasswordResolver (org.wso2.carbon.apimgt.api.PasswordResolver)3 XMLStreamException (javax.xml.stream.XMLStreamException)2 APIMConfigService (org.wso2.carbon.apimgt.impl.config.APIMConfigService)2 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)2 SelfSignUpUtil (org.wso2.carbon.apimgt.impl.utils.SelfSignUpUtil)1 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)1 Endpoint (org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint)1 UserRealm (org.wso2.carbon.user.core.UserRealm)1 AbstractUserStoreManager (org.wso2.carbon.user.core.common.AbstractUserStoreManager)1 RealmService (org.wso2.carbon.user.core.service.RealmService)1