Typically the ODSM (Oracle Directory Services Manager) allows the user to change the passwords using the url http://hostname:7005/odsm . There are situations where one needs to change the password via a Java Web Service. This Post uses the OID (Oracle Internet Directory) Java API to reset password information.
import java.io.InputStream;
import java.util.Hashtable;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.InitialDirContext;
import javax.naming.ldap.InitialLdapContext;
import oracle.ldap.util.AuthFailureException;
import oracle.ldap.util.LDIF;
import oracle.ldap.util.ModPropertySet;
import oracle.ldap.util.RootOracleContext;
import oracle.ldap.util.User;
import oracle.ldap.util.Util;
import oracle.ldap.util.UtilException;
import oracle.ldap.util.Subscriber;
public class OIDAuthenticate implements OIDConstants {
public OIDAuthenticate() {
super();
}
public String oidResetPassword(String userId,
String password) throws OIDException {
InitialDirContext ctx = null;
try {
ctx = getOIDConnection();
RootOracleContext roc = null;
Subscriber sub = null;
User user = null;
roc = new RootOracleContext(ctx);
try {
sub = roc.getSubscriber(ctx,util.IDTYPE_DEFAULT,
null, new String[] { "*" });
} catch (UtilException ue) {
OIDException le =
new OIDException(ue.getLDAPErrorCode() + "",
ue.getMessage());
le.printStackTrace();
} try {
user =
sub.getUser(ctx, Util.IDTYPE_SIMPLE,
userId, new String[] { "*" });
} catch (UtilException e) {
OIDException le =
new OIDException(e.getLDAPErrorCode() + "",
e.getMessage());
le.printStackTrace();
}
ModPropertySet mps = new ModPropertySet();
mps.addProperty(LDIF.ATTRIBUTE_CHANGE_TYPE_REPLACE,
"userpassword",password);
user.setProperties(ctx, mps);
return STR_SUCCESS;
} catch (Exception e) {
System.out.println("Problem resetting password: ");
e.printStackTrace();
return "EXCEPTION_OCCURED";
}finally
{
try {
if(ctx!=null) ctx.close();
} catch (NamingException ue) {
throw new OIDException("ERR", ue.getMessage());
}
}
}
public InitialDirContext getOIDConnection() throws OIDException{
InitialDirContext ctx;
try {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=orcladmin");
env.put(Context.SECURITY_CREDENTIALS, "password1");
env.put(Context.PROVIDER_URL,
"ldap://hostname:3060/");
env.put(Context.REFERRAL, "follow");
ctx = new InitialLdapContext(env, null);
return ctx;
} catch (NamingException ne) {
throw new OIDException("EXCEPTION_!",
ne.getMessage());
}
}
}
For questions, comments and feedback, please contact:
Harvinder Singh Saluja
This BLOG focuses on "hands on approach" around AWS, OCI Oracle Cloud Infrastructure, Dev/Ops, MicroServices, OKTA, Oracle Fusion Middleware, Oracle Service Bus, Oracle AIA, Oracle SOA Suite, Oracle SOA Cloud/Developer Cloud, Oracle Identity Management including OID, OAM, OIM, OSSO, Oracle Big Data, WLST Scripts and Oracle Edifecs B2B Engine for HIPAA/HL7/X12/EDIFACT EDI., Kafka, Spark, Spring Boot, DevOps, AWS, GCP and Oracle Cloud
Amazon Bedrock and AWS Rekognition comparison for Image Recognition
Both Amazon Bedrock and AWS Rekognition are services provided by AWS, but they cater to different use cases, especially when it comes to ...
-
Oracle Service Bus 11g 11.1.1.8 : How to export an OSB project from OSB console and import it in OEPE 1.) On the Right Hand Side pane, sel...
-
Oracle Cloud Infrastructure (OCI) provides a comprehensive set of infrastructure services that enable you to build and run a wide range of...
-
Healthcare Information Extraction Using Amazon Bedrock Client : Leading Healthcare Provider Project Overview : This project was developed fo...