Revision 48:b770dc1cc257

View differences:

pom.xml
334 334
		<dependency>
335 335
		    <groupId>org.springframework.ldap</groupId>
336 336
		    <artifactId>spring-ldap-core</artifactId>
337
		    <version>1.3.1.RELEASE</version>
338
		</dependency>
339
		<dependency>
340
		    <groupId>org.springframework.ldap</groupId>
341
		    <artifactId>spring-ldap-ldif-core</artifactId>
342
		    <version>1.3.1.RELEASE</version>
337
		    <version>1.3.0.RELEASE</version>
343 338
		</dependency>
344 339
		<dependency>
345 340
			<groupId>org.slf4j</groupId>
src/main/java/my/com/upass/services/VerifyStaticPasswordService.java
18 18
import my.com.upass.ConfigBean;
19 19
import my.com.upass.MinimalConstants;
20 20
import my.com.upass.MinimalUPassControllerV2;
21
import my.com.upass.UPassException;
21 22
import my.com.upass.UPassParameters;
22 23
import my.com.upass.dao.MinimalDAOFactory;
23 24
import my.com.upass.dao.UserDAO;
......
235 236
			if (!lrc) {
236 237
				ret.code = MinimalConstants.ERR_SYSTEM_NOT_READY;
237 238
			}
239
			
240
		} catch (UPassException e) {
241
			e.printStackTrace();
242
			ret.code = e.getErrorCode();
243

  
238 244
		} catch (Exception e) {
239 245
			e.printStackTrace();
240 246
			ret.code = MinimalConstants.ERR_SYSTEM_NOT_READY;
241
			return ret;
242 247
		}
243 248
		return ret;
244 249
	}
src/main/java/my/com/upass/spring/ldap/CollectingAuthenticationErrorCallback.java
1
package my.com.upass.spring.ldap;
2

  
3
import org.springframework.ldap.core.AuthenticationErrorCallback;
4

  
5
public final class CollectingAuthenticationErrorCallback implements AuthenticationErrorCallback {
6
	private Exception error;
7

  
8
	public void execute(Exception e) {
9
		this.error = e;
10
	}
11

  
12
	public Exception getError() {
13
		return error;
14
	}
15
}
src/main/java/my/com/upass/spring/ldap/MaybankLdapDAO.java
4 4

  
5 5
import my.com.upass.UPassException;
6 6

  
7
public interface MaybankLdapDAO {
7 8

  
8
public interface MaybankLdapDAO {
9
	
10 9
	public boolean isUserExist(String mbbuserid);
11
	
12
	public boolean authenticate(String mbbuserid, String password);
13
	
14
	public void updateUser(String mbbuserid, Map/*<String, String>*/ attributesMap) throws UPassException;
10

  
11
	public boolean authenticate(String mbbuserid, String password) throws UPassException;
12

  
13
	public void updateUser(String mbbuserid, Map/* <String, String> */attributesMap) throws UPassException;
15 14
}
src/main/java/my/com/upass/spring/ldap/MaybankLdapDAOImpl.java
17 17
import org.springframework.ldap.core.DistinguishedName;
18 18
import org.springframework.ldap.core.LdapTemplate;
19 19

  
20
public class MaybankLdapDAOImpl implements MaybankLdapDAO{
20
public class MaybankLdapDAOImpl implements MaybankLdapDAO {
21 21

  
22 22
	private Log logger = LogFactory.getLog(MaybankLdapDAOImpl.class);
23 23
	private LdapTemplate ldapTemplate = null;
24 24
	private String base;
25 25
	private String usernameAttrName;
26
	
26

  
27 27
	public boolean isUserExist(String mbbuserid) {
28 28
		Object person = null;
29
		
29

  
30 30
		try {
31 31
			person = ldapTemplate.lookup(buildDn(mbbuserid));
32 32
		} catch (NameNotFoundException e) {
33
			//not found
33
			// not found
34 34
		}
35
		
36
		if(person != null){
35

  
36
		if (person != null) {
37 37
			return true;
38 38
		}
39
		
39

  
40 40
		return false;
41 41
	}
42
	
43
	public boolean authenticate(String mbbuserid, String password) {
42

  
43
	public boolean authenticate(String mbbuserid, String password) throws UPassException {
44 44
		boolean result = false;
45
		CollectingAuthenticationErrorCallback errorCallback = new CollectingAuthenticationErrorCallback();
46
		
47 45
		try {
48
			result = ldapTemplate.authenticate(base, "("+usernameAttrName+"="+mbbuserid+")", password, errorCallback);
46
			result = ldapTemplate.authenticate(base, "(" + usernameAttrName + "=" + mbbuserid + ")", password);
47

  
49 48
		} catch (NameNotFoundException e) {
50
			logger.warn("LDAP Error code:"+LdapStatusCodeParser.getCode(e.getExplanation()) + " - " + e.getExplanation());
49
			logger.warn("LDAP Error code:" + LdapStatusCodeParser.getCode(e.getExplanation())
50
					+ " - " + e.getExplanation());
51
			throw new UPassException(MinimalConstants.ERR_LDAP);
51 52
		}
52
		
53
		if (!result && errorCallback.getError() != null) {
54
			AuthenticationException e = (AuthenticationException)errorCallback.getError();
55
			logger.info("LDAP Error code:"+LdapStatusCodeParser.getCode(e.getExplanation()) + " - " + e.getExplanation());
53
		if (!result) {
54
			logger.info("LDAP authentication failed!");
56 55
		}
57
		
58 56
		return result;
59 57
	}
60 58

  
61
	public void updateUser(String mbbuserid, Map/*<String, String>*/ attributesMap) throws UPassException{
59
	public void updateUser(String mbbuserid, Map/* <String, String> */attributesMap) throws UPassException {
62 60
		Name dn = buildDn(mbbuserid);
63 61
		DirContextOperations context = ldapTemplate.lookupContext(dn);
64 62
		mapToContext(attributesMap, context);
65
		
63

  
66 64
		try {
67 65
			ldapTemplate.modifyAttributes(context);
66

  
68 67
		} catch (NamingException e) {
69
			logger.warn("LDAP Error code:"+LdapStatusCodeParser.getCode(e.getExplanation()) + " - " + e.getExplanation());
68
			logger.warn("LDAP Error code:" + LdapStatusCodeParser.getCode(e.getExplanation()) + " - "
69
					+ e.getExplanation());
70 70
			throw new UPassException(MinimalConstants.ERR_LDAP);
71 71
		}
72 72
	}
73
	
74
	protected void mapToContext(Map/*<String, String>*/ attributesMap, DirContextOperations context) {
73

  
74
	protected void mapToContext(Map/* <String, String> */attributesMap, DirContextOperations context) {
75 75
		Iterator it = attributesMap.entrySet().iterator();
76
	    while (it.hasNext()) {
77
	        Map.Entry pairs = (Map.Entry)it.next();
78
	        context.setAttributeValue((String)pairs.getKey(), pairs.getValue());
79
	        it.remove();
80
	    }
76
		while (it.hasNext()) {
77
			Map.Entry pairs = (Map.Entry) it.next();
78
			context.setAttributeValue((String) pairs.getKey(), pairs.getValue());
79
			it.remove();
80
		}
81 81
	}
82
	
82

  
83 83
	protected Name buildDn(String mbbuserid) {
84 84
		DistinguishedName dn = new DistinguishedName(base);
85 85
		dn.add("mbbuserid", mbbuserid);

Also available in: Unified diff