LDAP does not return the password that it is encrypted in LDAP, you have to make a connection via LDAP can use this jar CLICK HERE and after making the connection you run a command that returns the password of a user
Example.:
code:
package br.com.tpd.sigresunificado.SSHLDAPConnection;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session;
import ch.ethz.ssh2.StreamGobbler;
/**
* Class for connecting to an LDAP server using SSH protocol
*
* @author MaurĂcio Cababe
*
*/
public class SSHLDAPConnection
{
/**
* Return the user's password
*
* @param server
* The LDAP server to connect to
* @param authenticationUser
* The LDAP authentication user
* @param authenticationPassword
* The LDAP authentication password
* @param port
* The port to connect to
* @param user
* The user whose password will be retrieved
* @param timeout
* The timeout value in milliseconds for the server response
* @return
* @throws SSHLDAPException
*/
public static String getUserPassword(String server,
String authenticationUser, String authenticationPassword,
Integer port, String user, Integer timeout, Map configurations) throws SSHLDAPException
{
String cn = configurations.get("cn").toString();
String ou = configurations.get("ou").toString();
String o = configurations.get("o").toString();
String pwd = "-w " + configurations.get("pwd").toString();
String command = "idsldapsearch -b cn=" + cn + ",ou=" + ou + ","
+ "o=" + o + " -D cn=root " + pwd + " \"uid=" + user
+ "\" | grep user";
// Default timeout and port values
if(timeout == null)
{
timeout = new Integer(15000);
}
if(port == null)
{
port = new Integer(22);
}
// Create a new connection
Connection connection = new Connection(server, port.intValue());
if(connection == null)
{
throw new SSHLDAPException("Not able to connect to server "
+ server + " at port " + port.intValue(),
SSHLDAPException.ERROR_CODE_CONNECTION);
}
try
{
boolean authenticated = false;
Session session = null;
// Connect and authenticate
connection.connect();
authenticated = connection.authenticateWithPassword(
authenticationUser, authenticationPassword);
if(!authenticated)
{
throw new SSHLDAPException("Not able to authenticate user "
+ authenticationUser + " on server " + server,
SSHLDAPException.ERROR_CODE_AUTHENTICATION);
}
// Open a session and execute the command
session = connection.openSession();
System.out.println("command: " + command);
session.execCommand(command);
// Get the response
String response = "";
InputStream stdout = new StreamGobbler(session.getStdout());
BufferedReader br = new BufferedReader(
new InputStreamReader(stdout));
while(true)
{
String line = br.readLine();
response += line;
if(line == null)
{
break;
}
}
System.out.println("response: " + response);
// Close the session
session.close();
// Close the connection
session.close();
// Get the password from the response
try
{
String password = response.substring(13, response.length() - 4);
return password;
}
catch(Exception e)
{
throw new SSHLDAPException(
"An unknown error occured when executing the command",
SSHLDAPException.ERROR_CODE_UNKNOWN);
}
}
catch(IOException e)
{
throw new SSHLDAPException(e.getMessage(),
SSHLDAPException.ERROR_CODE_IO);
}
finally
{
connection.close();
}
}
public static void main(String[] args)
{
System.out.println("testing password...");
testPassword();
}
private static void testPassword()
{
String server = "***.***.***.***";
String authenticationUser = "idsldap";
String authenticationPassword = "ldapprs@2";
Integer port = new Integer("222222");
String user = "administrador";
Integer timeout = new Integer("5000000");
Map configurations = new HashMap();
configurations.put("cn", "pr");
configurations.put("ou", "portal");
configurations.put("o", "blablabla");
configurations.put("pwd", "tabajara");
try
{
System.out.println("Resposta: "
+ SSHLDAPConnection.getUserPassword(server,
authenticationUser, authenticationPassword, port,
user, timeout, configurations));
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Click here to View more...
Get User password from LDAP using PUMA
Labels: PUMA
WebSphere Portal PUMA API
WPS 5.1 has introduced Puma SPI (Service Provider Interface) for accessing the information about the WPS users and groups. The PUMA SPI provides interfaces for accessing the profiles of a portal user or group. You can use it to find, create, modify, and delete users and groups, as well as profile information about the currently logged-in user.
You can download the Javadoc of the complete SPI from here.
The details of our WebSphere Portal users are stored in IBM Tivoli LDAP server. This code prints what attributes of users are actually available and enables us to show them in a theme JSP. So our JSR 168 portlets have to further rely on IBM-specific code. Portability is really a lost cause.
try{
javax.naming.Context ctx = new javax.naming.InitialContext();
com.ibm.portal.um.PumaHome home = (com.ibm.portal.um.PumaHome)
ctx.lookup(”portal:service/usermanagement/Puma”);
PumaProfile profile = home.getProfile( request );
List attributes = profile.getDefinedUserAttributeNames();
User user = profile.getCurrentUser();
Map map = profile.getAttributes(user, attributes);
Iterator iterator = attributes.iterator();
while (iterator.hasNext()) {
String attribute = (String)iterator.next();
System.out.println(”["+ attribute +"][" +
map.get(attribute) + "]“);
}
}catch( PumaSystemException pse ){
System.out.println( “PumaSystemException” );
}catch( PumaModelException pme ){
System.out.println( “PumaModelException” );
}catch( PumaMissingAccessRightsException pmare ){
System.out.println( “PumaMissingAccessRightsException” );
}catch( Exception e ){
System.out.println( “Exception” );
}
Portal User Management Architecture (PUMA)
This technote covers collecting data for Portal User Management Architecture (PUMA) with IBM® WebSphere® Portal 6.1. Gathering this MustGather information before calling IBM Support will help to understand the problem and save time analyzing the data.
The PUMA SPI provides interfaces for accessing the profiles of a portal User or Group. It is used to find, create, modify, and delete users and groups. While it is implemented by administration portlets such as Manage Users and Manage Groups, it can also be used in custom themes and portlets.
Collecting PUMA specific information
1. Provide the following details about the problem:
- Version information for products involved:
- WebSphere Portal
- WebSphere Application Server
- LDAP (if configured)
- Database
- Code sample if using PUMA SPI
Recommendation: If you do not wish to manually collect configuration files and tracing, you can skip the remaining sections of this MustGather by using the IBM Support Assistant Lite for WebSphere Portal Tool (WebSphere Portal->Security and Administration->Puma User Management Architecture Problem option) to gather the requested information and provide it to IBM Support.
2. Enable PUMA trace logging by setting the following trace settings in accordance with the instructions documented in the topic "Trace Logging" in the WebSphere Portal Information Center:
com.ibm.wps.engine.*=all:com.ibm.wps.puma.*=all:
com.ibm.wps.services.puma.*=all:com.ibm.wps.command.puma.*=all:
com.ibm.wps.um.*=all:com.ibm.ws.wim.*=all:com.ibm.websphere.wim.*=all:
com.ibm.wsspi.wim.*=all
Note: Depending on how much traffic is hitting your server during trace collection, you may need to either increase the "Maximum File Size" or "Maximum Number of Historical Files" or both so that your applicable tracing does not get overwritten.
For more information regarding logging and tracing in the portal, refer to the topic "Logging and Tracing" in the WebSphere Portal Information Center.
3. Collect the following files from the server during the time period that the problem occurs:
/logs/WebSphere_Portal/SystemOut.log /logs/WebSphere_Portal/SystemErr.log /logs/WebSphere_Portal/trace.log /config/cells/ /security.xml /config/cells/ /nodes/ /servers/WebSphere_Portal/resources.xml (located in /clusters/ for clustered server) /config/cells/ /wim (including sub-directories) /config/cells/ /fileRegistry.xml
Be certain to indicate the relevant details (date and time, test case, user ID, etc) to IBM Support in your communications, and use specific entries from the log to illustrate the problem reported if possible. Click here to View more...
Labels: IBM WebSphere Portal v6.1, PUMA