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);
}
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());
}
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);
}
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();
}
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;
}
Aggregations