我有一个使用LDAP和简单数据库身份验证的应用程序来记录用户.只有当用户在LDAP上下文中不存在时,应用程序才会检查他是否存在于数据库中.所以我需要一种方法来检查用户是否存在于LDAP中,而不知道密码.我提到用户名是唯一的.
我使用此代码,如果我有正确的用户名和密码,它可以工作.如果密码或用户名错误,我会得到一个例外.如果我能得到不同的例外,那将是理想的,如果用户名不存在,则为1,如果提供的密码错误则为其他例外.
String username = "test";
String password = "pass";
Hashtable<String, String> environment = new Hashtable<String, String>();
environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
environment.put(Context.PROVIDER_URL, "ldap://server.example.com:389");
environment.put(Context.SECURITY_AUTHENTICATION, "simple");
String user = username + "@example.com";
environment.put(Context.SECURITY_PRINCIPAL, user );
environment.put(Context.SECURITY_CREDENTIALS, password);
try
{
DirContext context = new InitialDirContext(environment);
String searchBase = "DC=server,DC=example,DC=COM";
String FILTER = "(&(objectClass=user)(objectCategory=person)((sAMAccountName=" + username + ")))";
SearchControls ctls = new SearchControls();
ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration<SearchResult> answer = context.search(searchBase, FILTER, ctls);
SearchResult result = answer.next();
Attribute email = result.getAttributes().get("mail");
Attribute cn = result.getAttributes().get("cn");
System.out.println(cn + " …Run Code Online (Sandbox Code Playgroud) 我想要一个简单的方法将JList放在JTable的列中.我已经有了JLists和表,但是当放入表中时,Jlists显示为Strings,这是正常的,因为我使用DefaultTableModel.我已经将getColumnClass()重写为:
public Class<? extends Object> getColumnClass(int c)
{
return getValueAt(0, c).getClass();
}
Run Code Online (Sandbox Code Playgroud)
但这只是格式化整数和浮点值.
我想也应该覆盖setValueAt()和getValueAt(),以便在调用JList.getSelectedValues()时返回字符串数组,但我无法弄清楚如何.
我还希望单元格可以编辑,因此用户可以从JList中选择一个或多个选项.编辑一行后,我使用Save按钮将更改保存在数据库中,所以我认为我不需要ListSelectionListener,JList.getSelectedValues()可以正常工作.
我知道这是一个常见问题,但我在这里找不到答案.如果这是重复,请告诉我,我将删除它.
我有一个创建和声明不同类型的过程.但每次我写'创建类型'或'声明类型'我都会收到此错误:
ERROR第4行,第10栏,结尾第4行,结尾_col 18,找到'收件人',期待:(.@或%或..:= DEFAULT NOT NULL或;
我使用的是Oracle 10,这些是程序的第一行.错误
CREATE OR REPLACE PROCEDURE ACTIVITE_PROD.NOTIF_NEW_HOLIDAY(v_USER_ID INTEGER, v_DURATION NUMBER, v_WEEK INTEGER, v_YEAR INTEGER) IS
-- this line causes the error
create type recipient as object (firstname varchar2, lastname varchar2, email varchar2);
-- this line also causes an error if modified and set first
declare
type recipients_list is table of recipient;
admins recipients_list := recipients_list();
Run Code Online (Sandbox Code Playgroud)
我的代码出了什么问题?
我希望有一个嵌套表来保存自定义对象,通过从多个游标逐个添加它们.但我不想在表格中有重复.我怎样才能做到这一点?
以下是我向表中添加元素的方法:
create type recipient as object (firstname varchar2, lastname varchar2, email varchar2);
declare type recipients_list is table of recipient;
rec recipients_list := recipients_list();
cursor admins is
select firstname, lastname, email
from users
where profile_id = 1;
cursor operators is
select firstname, lastname, email
from users
where operator = 1;
-- an user may be both admin and operator
....
for to_email in admins
loop
rec.extend;
rec(rec.last) := recipient(to_email.firstname, to_email.lastname, to_email.email);
end loop;
for to_email in operators
loop
rec.extend;
rec(rec.last) …Run Code Online (Sandbox Code Playgroud)