-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from Vathsan/master
Add operation to rename CN
- Loading branch information
Showing
8 changed files
with
221 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* WSO2 Inc. licenses this file to you 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.connector.ldap; | ||
|
||
import org.apache.axiom.om.OMAbstractFactory; | ||
import org.apache.axiom.om.OMElement; | ||
import org.apache.axiom.om.OMFactory; | ||
import org.apache.axiom.om.OMNamespace; | ||
import org.apache.synapse.MessageContext; | ||
import org.apache.synapse.SynapseException; | ||
import org.wso2.carbon.connector.core.AbstractConnector; | ||
|
||
import javax.naming.NamingException; | ||
import javax.naming.directory.DirContext; | ||
|
||
public class Rename extends AbstractConnector { | ||
|
||
@Override | ||
public void connect(MessageContext messageContext) { | ||
|
||
String oldName = (String) getParameter(messageContext, LDAPConstants.OLD_NAME); | ||
String newName = (String) getParameter(messageContext, LDAPConstants.NEW_NAME); | ||
|
||
OMFactory factory = OMAbstractFactory.getOMFactory(); | ||
OMNamespace ns = factory.createOMNamespace(LDAPConstants.CONNECTOR_NAMESPACE, LDAPConstants.NAMESPACE); | ||
OMElement result = factory.createOMElement(LDAPConstants.RESULT, ns); | ||
OMElement message = factory.createOMElement(LDAPConstants.MESSAGE, ns); | ||
|
||
try { | ||
DirContext context = LDAPUtils.getDirectoryContext(messageContext); | ||
context.rename(oldName, newName); | ||
message.setText(LDAPConstants.SUCCESS); | ||
result.addChild(message); | ||
LDAPUtils.preparePayload(messageContext, result); | ||
} catch (NamingException e) { | ||
log.error("Failed to update ldap Common Name (CN) ", e); | ||
LDAPUtils.handleErrorResponse(messageContext, LDAPConstants.ErrorConstants.RENAME_ERROR, e); | ||
throw new SynapseException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright (c) 2021, WSO2 Inc. (http://wso2.com) All Rights Reserved. | ||
~ | ||
~ WSO2 Inc. licenses this file to you 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. | ||
--> | ||
<template name="updateName" xmlns="http://ws.apache.org/ns/synapse"> | ||
<parameter name="oldName" description="Fully qualified old name"/> | ||
<parameter name="newName" description="Fully qualified new name"/> | ||
<sequence> | ||
<property expression="$func:oldName" name="oldName" scope="default" type="STRING"/> | ||
<property expression="$func:newName" name="newName" scope="default" type="STRING"/> | ||
<class name="org.wso2.carbon.connector.ldap.Rename"/> | ||
</sequence> | ||
</template> |
82 changes: 82 additions & 0 deletions
82
src/test/java/org/wso2/carbon/connector/unit/test/ldap/RenameTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* WSO2 Inc. licenses this file to you 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.connector.unit.test.ldap; | ||
|
||
import org.apache.synapse.MessageContext; | ||
import org.apache.synapse.mediators.template.TemplateContext; | ||
import org.testng.Assert; | ||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
import org.wso2.carbon.connector.ldap.Init; | ||
import org.wso2.carbon.connector.ldap.LDAPConstants; | ||
import org.wso2.carbon.connector.ldap.Rename; | ||
|
||
import java.util.Stack; | ||
|
||
public class RenameTest { | ||
|
||
private Rename rename; | ||
private Init init; | ||
private TemplateContext templateContext; | ||
private MessageContext messageContext; | ||
private Stack functionStack; | ||
private LdapServerSetup ldap; | ||
|
||
@BeforeMethod | ||
public void setUp() throws Exception { | ||
ldap = new LdapServerSetup(); | ||
rename = new Rename(); | ||
init = new Init(); | ||
ldap.initializeProperties(); | ||
if (ldap.useEmbeddedLDAP) { | ||
ldap.initializeEmbeddedLDAPServer(); | ||
} | ||
messageContext = ldap.createMessageContext(); | ||
messageContext.setProperty(LDAPConstants.SECURE_CONNECTION, "false"); | ||
messageContext.setProperty(LDAPConstants.DISABLE_SSL_CERT_CHECKING, "false"); | ||
templateContext = new TemplateContext("rename", null); | ||
templateContext.getMappedValues().put(LDAPConstants.PROVIDER_URL, "ldap://localhost:10389/"); | ||
templateContext.getMappedValues().put(LDAPConstants.SECURITY_PRINCIPAL, "cn=admin,dc=wso2,dc=com"); | ||
templateContext.getMappedValues().put(LDAPConstants.SECURITY_CREDENTIALS, "19902"); | ||
templateContext.getMappedValues().put(LDAPConstants.OLD_NAME, "uid=john004,ou=People,dc=wso2,dc=com"); | ||
templateContext.getMappedValues().put(LDAPConstants.NEW_NAME, "uid=john005,ou=People,dc=wso2,dc=com"); | ||
functionStack = new Stack(); | ||
} | ||
|
||
@Test | ||
public void testRename() throws Exception { | ||
ldap.createSampleEntity(); | ||
try { | ||
functionStack.push(templateContext); | ||
messageContext.setProperty("_SYNAPSE_FUNCTION_STACK", functionStack); | ||
init.connect(messageContext); | ||
rename.connect(messageContext); | ||
Assert.assertEquals((messageContext.getEnvelope().getBody().getFirstElement()).getFirstElement().getText(), "Success"); | ||
} finally { | ||
ldap.deleteSampleEntry(); | ||
} | ||
} | ||
|
||
@AfterMethod | ||
protected void cleanup() { | ||
ldap.cleanup(); | ||
} | ||
} |