LocalLdapAuthModule.java revision 8af80418ba1ec431c8027fa9668e5678658d3611
/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: LocalLdapAuthModule.java,v 1.7 2009/01/28 05:34:52 ww203982 Exp $
*
*/
/**
* Portions Copyrighted [2011] [ForgeRock AS]
*/
public class LocalLdapAuthModule implements LoginModule {
/* Naming attribute for users */
private boolean readServerConfiguration = false;
private CallbackHandler cbHandler;
private AuthSubject subject;
private Map sharedState;
public LocalLdapAuthModule() {
// do nothing
}
this.sharedState = sharedState;
}
public boolean login() throws LoginException {
// Check if we have username and password, else get it
if (debug.messageEnabled()) {
}
// Check if we have username and password, if not send callbacks
// Request for both username and password
try {
if (debug.messageEnabled()) {
+ "Name & Password Callback");
}
} catch (UnsupportedCallbackException e) {
throw (new LoginException(e.getMessage()));
} catch (IOException ioe) {
}
}
}
// Authenticate
boolean authentication = false;
authentication = true;
}
}
return (authentication);
}
public boolean abort() throws LoginException {
return (true);
}
public boolean commit() throws LoginException {
// Add the DN to the Subject
return (true);
}
public boolean logout() throws LoginException {
return (true);
}
throws LoginException {
// LDAP connection used for authentication
// Check if organization is present in options
try {
// We need a handle on server instance so we can know the
// Connection type. If it is SSL, the connection needs to be
// accordingly created. Note: The user type does not make
// a difference, as the connection type is Server group based,
// so passing any user type for the second argument.
try {
null));
} catch (Exception e) {
}
} else {
localConn = new LDAPConnection();
}
// The 389 port number passed is overridden by the
// hostName:port
// constructed by the getHostName method. So, this is not
// a hardcoded port number.
} else {
// Throw LoginException
}
} catch (LDAPServiceException ex) {
} catch (LDAPException ex) {
}
} else {
try {
if (debug.messageEnabled()) {
}
// Get hostname
int start;
boolean useSSL = false;
useSSL = true;
} else {
}
if (end == -1) {
if (end == -1)
}
// Get port number
if (end == -1)
}
if (useSSL) {
try {
null));
if (debug.messageEnabled()) {
"created with new JSSESocetFactory");
}
} catch (Exception e) {
throw (new LoginException(e.getMessage()));
}
} else {
localConn = new LDAPConnection();
}
if (debug.messageEnabled()) {
+ ",port=" + portNumber);
}
} catch (Exception e) {
throw (new LoginException(e.getMessage()));
}
}
try {
} catch (LDAPException ex) {
} finally {
try {
} catch (LDAPException e) {
// do nothing
}
}
return (true);
}
.getString("com.iplanet.auth.invalid-username")));
}
return uid;
}
try {
// Use orgname only if it a DN, else baseDN
}
}
} catch (Exception e) {
// Ignore the exception and use the default naming attribute
}
.append(')');
try {
// Read the serverconfig.xml for LDAP information
if (!readServerConfiguration) {
}
"LocalLdapAuthModule.getDN(): lda connection is null");
throw (new LoginException("INVALID_USER_NAME"));
} else {
attrs, false);
}
} catch (LDAPException ex) {
} finally {
try {
conn.disconnect();
} catch (Exception e) {
}
}
try {
if (results.hasMoreElements()) {
}
} catch (LDAPException ex) {
}
throw (new LoginException("INVALID_USER_NAME"));
return retVal;
}
private void readServerConfig() throws LoginException {
return;
try {
readServerConfiguration = true;
} catch (LDAPServiceException ex) {
}
}
}