01: /*
02: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05:
06: package com.sun.portal.providers.userinfo;
07:
08: import com.sun.portal.providers.userinfo.tag.AttributeTag;
09: import com.sun.portal.providers.userinfo.tag.TagException;
10: import com.sun.portal.providers.userinfo.tag.UnhandledTagException;
11: import com.sun.portal.providers.userinfo.tag.ReadTag;
12: import com.sun.portal.providers.userinfo.tag.WriteTag;
13: import com.sun.portal.providers.context.ProviderContext;
14:
15: import com.sun.identity.security.EncryptAction;
16:
17: import java.security.AccessController;
18:
19: import javax.servlet.http.HttpServletRequest;
20:
21: /*
22: * this class handles setting the tag sunPortalNetmailIMAPPassword only.
23: */
24:
25: public class IMAPPWTag implements ReadTag, WriteTag {
26:
27: private AttributeTag attributeTag = null;
28:
29: public void init(String channel, ProviderContext context,
30: HttpServletRequest req) throws TagException {
31: attributeTag = new AttributeTag();
32: attributeTag.init(channel, context, req);
33: }
34:
35: public String get(String key) throws TagException {
36: if (!key.equals("sunPortalNetmailIMAPPassword")) {
37: throw new UnhandledTagException("unhandled tag=" + key);
38: }
39:
40: String val = attributeTag.get(key);
41:
42: return getDummyString(val);
43: }
44:
45: public void set(String tag, String newValue) throws TagException {
46: if (!tag.equals("sunPortalNetmailIMAPPassword")) {
47: throw new UnhandledTagException("unhandled tag=" + tag);
48: }
49: if (newValue != null) {
50: String origValue = getDummyString(attributeTag.get(tag));
51: if (origValue != null) {
52: if (!origValue.equals(newValue)) {
53: if (newValue.trim().equals("")) {
54: attributeTag.set(tag, "");
55: } else {
56: attributeTag.set(tag, (String) AccessController
57: .doPrivileged(new EncryptAction(
58: newValue)));
59: }
60: }
61: }
62: }
63: }
64:
65: private String getDummyString(String s) {
66: StringBuffer dummy = new StringBuffer();
67: int len = s.length();
68: for (int i = 0; i < len; i++) {
69: dummy.append("*");
70: }
71:
72: return dummy.toString();
73: }
74: }
|