Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add security codes migration service from old soap service to compatible with new Rest service. #53

Merged
merged 3 commits into from
Aug 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ Licensed 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<parent>
<groupId>org.wso2</groupId>
<artifactId>wso2</artifactId>
<version>1</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<groupId>org.wso2.sample</groupId>
<artifactId>org.wso2.carbon.identity.securitycode.migration</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Carbon - Identity Security Code Migration</name>
<version>1.0.1-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.core</artifactId>
<version>${carbon.identity.framework.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.idp.mgt</artifactId>
<version>${carbon.identity.framework.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.application.common</artifactId>
<version>${carbon.identity.framework.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.governance</groupId>
<artifactId>org.wso2.carbon.identity.recovery</artifactId>
<version>${identity.governance.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.core</artifactId>
<version>${carbon.kernel.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.utils</artifactId>
<version>${carbon.kernel.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.logging</artifactId>
<version>${carbon.kernel.version}</version>
</dependency>

<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.ds-annotations</artifactId>
<version>${felix.scr.annotations.version}</version>
</dependency>
</dependencies>


<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin}</version>
<inherited>true</inherited>
<configuration>
<encoding>UTF-8</encoding>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<version>${maven.scr.plugin.version}</version>
<executions>
<execution>
<id>generate-scr-scrdescriptor</id>
<goals>
<goal>scr</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>${maven.bundle.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>
${project.artifactId}
</Bundle-SymbolicName>
<Private-Package>
org.wso2.carbon.identity.securitycode.migration.internal
</Private-Package>
<Export-Package>
org.wso2.carbon.identity.securitycode.migration.*;
version="${identity.code.migration.exp.pkg.version}",
!org.wso2.carbon.identity.securitycode.migration
</Export-Package>
<Import-Package>
org.osgi.framework; version="${osgi.framework.imp.pkg.version.range}",
org.osgi.service.component; version="${osgi.service.component.imp.pkg.version.range}",
org.wso2.carbon.identity.application.common.*;version="${carbon.identity.framework.version.range}",
org.apache.commons.logging.*; version="${commons-logging.osgi.version.range}",
</Import-Package>
<DynamicImport-Package>*</DynamicImport-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>


<properties>

<!--Carbon Identity Framework Version-->
<carbon.identity.framework.version>5.11.10</carbon.identity.framework.version>
<carbon.identity.framework.version.range>[5.0.0, 6.0.0]</carbon.identity.framework.version.range>
<identity.code.migration.exp.pkg.version>${project.version}</identity.code.migration.exp.pkg.version>
<osgi.framework.imp.pkg.version.range>[1.7.0, 2.0.0)</osgi.framework.imp.pkg.version.range>
<osgi.service.component.imp.pkg.version.range>[1.2.0, 2.0.0)</osgi.service.component.imp.pkg.version.range>
<commons-logging.osgi.version.range>[1.2,2.0)</commons-logging.osgi.version.range>
<felix.scr.annotations.version>1.2.4</felix.scr.annotations.version>
<carbon.kernel.version>4.4.23</carbon.kernel.version>
<maven.compiler.plugin>3.7.0</maven.compiler.plugin>
<maven.bundle.plugin.version>2.4.0</maven.bundle.plugin.version>
<maven.scr.plugin.version>1.22.0</maven.scr.plugin.version>
<identity.governance.version>1.0.37</identity.governance.version>
<identity.governance.version.range>[1.0.0, 2.0.0]</identity.governance.version.range>
</properties>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed 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 und
*/
package org.wso2.carbon.identity.securitycode.migration;

/**
* This class is used to define the constants used in security code migration.
*/
public class MigrationConstants {

public static final String CONFIRMATION_REGISTRY_RESOURCE_PATH = "/repository/components/org.wso2.carbon" +
".identity.mgt/data/";
public static final String EXPIRE_TIME_PROPERTY = "expireTime";
public static final String USER_ID_PROPERTY = "userId";
public static final String SELF_SIGN_UP_CODE_DELIMITER = "1";
public static final String PW_RESET_CODE_DELIMITER = "2";
public static final String REG_DELIMITER = "___";
public static final String TENANT_DELIMITER = ":";
public static final String SYSTEM_PROPERTY_MIGRATE = "migrateSecurityCode";
public static final String SYSTEM_PROPERTY_MIGRATE_TENANTS = "migrateTenants";
public static final String SYSTEM_PROPERTY_MIGRATE_TENANT_RANGE = "migrateTenantRange";
public static final String SYSTEM_PROPERTY_START_TENANT = "tenantStartNo";
public static final String SYSTEM_PROPERTY_TENANT_COUNT = "tenantCount";


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/*
* Copyright (c) 2018, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed 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.identity.securitycode.migration.internal;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.wso2.carbon.identity.core.util.IdentityCoreInitializedEvent;
import org.wso2.carbon.identity.securitycode.migration.service.SecurityCodeMigrationService;
import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.user.core.service.RealmService;

import static org.apache.commons.lang.StringUtils.isBlank;
import static org.apache.commons.lang.StringUtils.isNotBlank;
import static org.wso2.carbon.identity.securitycode.migration.MigrationConstants.SYSTEM_PROPERTY_MIGRATE;
import static org.wso2.carbon.identity.securitycode.migration.MigrationConstants.SYSTEM_PROPERTY_MIGRATE_TENANTS;
import static org.wso2.carbon.identity.securitycode.migration.MigrationConstants.SYSTEM_PROPERTY_MIGRATE_TENANT_RANGE;
import static org.wso2.carbon.identity.securitycode.migration.MigrationConstants.SYSTEM_PROPERTY_START_TENANT;
import static org.wso2.carbon.identity.securitycode.migration.MigrationConstants.SYSTEM_PROPERTY_TENANT_COUNT;
import static org.wso2.carbon.identity.securitycode.migration.MigrationConstants.TENANT_DELIMITER;

@Component(
name = "IdentityCodeMigrationServiceComponent",
immediate = true
)
public class IdentityCodeMigrationServiceComponent {

private static Log log = LogFactory.getLog(IdentityCodeMigrationServiceComponent.class);

@Activate
protected void activate(ComponentContext context) {

if (log.isDebugEnabled()) {
log.debug("Security code migration bundle is activated");
}

SecurityCodeMigrationService securityCodeMigrationService = new SecurityCodeMigrationService();
String migrateCode = System.getProperty(SYSTEM_PROPERTY_MIGRATE);
String tenantsToMigrate = System.getProperty(SYSTEM_PROPERTY_MIGRATE_TENANTS);
String tenantRangeMigrate = System.getProperty(SYSTEM_PROPERTY_MIGRATE_TENANT_RANGE);
String startTenant = System.getProperty(SYSTEM_PROPERTY_START_TENANT);
String tenantCount = System.getProperty(SYSTEM_PROPERTY_TENANT_COUNT);

if (log.isDebugEnabled()) {
log.debug("MigrateCode: " + migrateCode);
log.debug("All tenant Migrate: " + tenantsToMigrate);
log.debug ("Tenant range Migrate: " + tenantRangeMigrate);
log.debug ("Tenant Start Count: " + tenantCount);
}

try {
if (Boolean.parseBoolean(migrateCode) && isNotBlank(tenantsToMigrate)) {
String[] tenantDomains = tenantsToMigrate.split(TENANT_DELIMITER);
securityCodeMigrationService.migrateTenants(tenantDomains);
} else if (Boolean.parseBoolean(migrateCode)) {
if (Boolean.parseBoolean(tenantRangeMigrate)) {
if (log.isDebugEnabled()) {
log.debug("Migrating security codes of a given tenant range started");
}
securityCodeMigrationService.migrateTenantRange(Integer.parseInt(startTenant),
Integer.parseInt(tenantCount));

} else if(isBlank(tenantsToMigrate)) {
if (log.isDebugEnabled()) {
log.debug("Migrating security codes of all tenants started");
}
securityCodeMigrationService.migrateAllTenants();
if (log.isDebugEnabled()) {
log.debug("Migrating security codes of all tenants ended");
}
}

}
} catch (Throwable throwable) {
log.error(throwable);
}
}

protected void deactivate(ComponentContext context) {

if (log.isDebugEnabled()) {
log.debug("Security code migration bundle is de-activated");
}
}

@Reference(
name = "realm.service",
service = RealmService.class,
cardinality = ReferenceCardinality.MANDATORY,
policy = ReferencePolicy.DYNAMIC,
unbind = "unsetRealmService"
)
protected void setRealmService(RealmService realmService) {

log.debug("Setting the Realm Service");
IdentityCodeMigrationServiceDataHolder.setRealmService(realmService);
}

protected void unsetRealmService(RealmService realmService) {

log.debug("UnSetting the Realm Service");
IdentityCodeMigrationServiceDataHolder.setRealmService(null);
}

@Reference(
name = "registry.service",
service = RegistryService.class,
cardinality = ReferenceCardinality.MANDATORY,
policy = ReferencePolicy.DYNAMIC,
unbind = "unsetRegistryService"
)
protected void setRegistryService(RegistryService registryService) {

log.debug("Setting the Registry Service");
IdentityCodeMigrationServiceDataHolder.setRegistryService(registryService);
}

protected void unsetRegistryService(RegistryService registryService) {

log.debug("UnSetting the Registry Service");
IdentityCodeMigrationServiceDataHolder.setRegistryService(null);
}

@Reference(
name = "identityCoreInitializedEventService",
service = IdentityCoreInitializedEvent.class,
cardinality = ReferenceCardinality.MANDATORY,
policy = ReferencePolicy.DYNAMIC,
unbind = "unsetIdentityCoreInitializedEventService"
)
protected void setIdentityCoreInitializedEventService(IdentityCoreInitializedEvent identityCoreInitializedEvent) {
/* reference IdentityCoreInitializedEvent service to guarantee that this component will wait until identity core
is started */
}

protected void unsetIdentityCoreInitializedEventService(IdentityCoreInitializedEvent identityCoreInitializedEvent) {
/* reference IdentityCoreInitializedEvent service to guarantee that this component will wait until identity core
is started */
}

private boolean migrateAll(String migrateCode, String tenantsToMigrate) {

return Boolean.parseBoolean(migrateCode) && isBlank(tenantsToMigrate);
}
}

Loading