Project

General

Profile

« Previous | Next » 

Revision 8476

Added by Jing Tao almost 11 years ago

Add the getUserInfo method.

View differences:

src/edu/ucsb/nceas/metacat/AuthInterface.java
44 44
    public static final short USERORGUNITINDEX = 3;
45 45
    public static final short USEREMAILINDEX = 4;
46 46
    public static final short GROUPNAMEINDEX = 0;
47
    public static final short GROUPDESINDEX =1;
47
    public static final short GROUPDESINDEX = 1;
48
    public static final short USERINFOCNINDEX = 0;
49
    public static final short USERINFOORGANIDEX = 1;
50
    public static final short USERINFOEMAILINDEX = 2;
48 51

  
49 52
  /**
50 53
   * Determine if a user/password are valid according to the authentication
src/edu/ucsb/nceas/metacat/authentication/AuthFile.java
79 79
 *
80 80
 */
81 81
public class AuthFile implements AuthInterface {
82
    private static final String ORGANIZATION = "UNkown";
82
    private static final String ORGANIZATIONNAME = "UNkown";
83
    private static final String ORGANIZATION = "organization";
83 84
    private static final String NAME = "name";
84 85
    private static final String DN = "dn";
85 86
    private static final String DESCRIPTION = "description";
......
206 207
        if(users != null && users.size() > 0) {
207 208
            String[][] usersArray = new String[users.size()][5];
208 209
            for(int i=0; i<users.size(); i++) {
209
                User aUser = new User();
210
                
210 211
                String dn = (String)users.get(i);
211
                aUser.setDN(dn);
212 212
                usersArray[i][AuthInterface.USERDNINDEX] = dn; //dn
213
                String surname = null;
214
                List<Object> surNames = userpassword.getList(USERS+SLASH+USER+"["+AT+DN+"='"+dn+"']"+SLASH+SURNAME);
215
                if(surNames != null && !surNames.isEmpty()) {
216
                    surname = (String)surNames.get(0);
217
                }
218
                aUser.setSurName(surname);
219
                String givenName = null;
220
                List<Object> givenNames = userpassword.getList(USERS+SLASH+USER+"["+AT+DN+"='"+dn+"']"+SLASH+GIVENNAME);
221
                if(givenNames != null && !givenNames.isEmpty()) {
222
                    givenName = (String)givenNames.get(0);
223
                }
224
                aUser.setGivenName(givenName);
225
                usersArray[i][AuthInterface.USERCNINDEX] = aUser.getCn();//common name
226
                usersArray[i][AuthInterface.USERORGINDEX] = null;//organization name. We set null
213
                String[] userInfo = getUserInfo(dn, password);
214
                usersArray[i][AuthInterface.USERCNINDEX] = userInfo[AuthInterface.USERINFOCNINDEX];//common name
215
                usersArray[i][AuthInterface.USERORGINDEX] = userInfo[AuthInterface.USERINFOORGANIDEX];//organization name. We set null
227 216
                usersArray[i][AuthInterface.USERORGUNITINDEX] = null;//organization ou name. We set null.
228
                List<Object> emails = userpassword.getList(USERS+SLASH+USER+"["+AT+DN+"='"+dn+"']"+SLASH+EMAIL);
229
                String email = null;
230
                if(emails != null && !emails.isEmpty() ) {
231
                    email = (String)emails.get(0);
232
                }
233
                usersArray[i][AuthInterface.USEREMAILINDEX] = email;
217
                usersArray[i][AuthInterface.USEREMAILINDEX] = userInfo[AuthInterface.USERINFOEMAILINDEX];
234 218
               
235 219
            }
236 220
            return usersArray;
......
239 223
    }
240 224
    
241 225
    @Override
226
    /**
227
     * Get an array about the user. The first column is the common name, the second column is the organization name.
228
     * The third column is the email address. It always returns an array. But the elements of the array can be null.
229
     */
242 230
    public String[] getUserInfo(String user, String password)
243 231
                    throws ConnectException {
244
        // TODO Auto-generated method stub
245
        return null;
232
        String[] userinfo = new String[3];
233
        User aUser = new User();
234
        aUser.setDN(user);
235
        String surname = null;
236
        List<Object> surNames = userpassword.getList(USERS+SLASH+USER+"["+AT+DN+"='"+user+"']"+SLASH+SURNAME);
237
        if(surNames != null && !surNames.isEmpty()) {
238
            surname = (String)surNames.get(0);
239
        }
240
        aUser.setSurName(surname);
241
        String givenName = null;
242
        List<Object> givenNames = userpassword.getList(USERS+SLASH+USER+"["+AT+DN+"='"+user+"']"+SLASH+GIVENNAME);
243
        if(givenNames != null && !givenNames.isEmpty()) {
244
            givenName = (String)givenNames.get(0);
245
        }
246
        aUser.setGivenName(givenName);
247
        userinfo[AuthInterface.USERINFOCNINDEX] = aUser.getCn();//common name
248
        String organization = null;
249
        List<Object> organizations = userpassword.getList(USERS+SLASH+USER+"["+AT+DN+"='"+user+"']"+SLASH+ORGANIZATION);
250
        if(organizations != null && !organizations.isEmpty()) {
251
            organization = (String)organizations.get(0);
252
        }
253
        userinfo[AuthInterface.USERINFOORGANIDEX] = organization;//organization name.
254
        aUser.setOrganization(organization);
255
        List<Object> emails = userpassword.getList(USERS+SLASH+USER+"["+AT+DN+"='"+user+"']"+SLASH+EMAIL);
256
        String email = null;
257
        if(emails != null && !emails.isEmpty() ) {
258
            email = (String)emails.get(0);
259
        }
260
        aUser.setEmail(email);
261
        userinfo[AuthInterface.USERINFOEMAILINDEX] = email;
262
        return userinfo;
246 263
    }
247 264
    
248 265
    
......
343 360
            out.append("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n");
344 361
            out.append("<principals>\n");
345 362
            out.append("  <authSystem URI=\"" +authURI
346
                    + "\" organization=\"" + ORGANIZATION + "\">\n");
363
                    + "\" organization=\"" + ORGANIZATIONNAME + "\">\n");
347 364

  
348 365
            // get all groups for directory context
349 366
            String[][] groups = getGroups(user, password);
......
578 595
        private String givenName = null;
579 596
        private String cn = null;//the common name
580 597
        private String[] groups = null;
598
        private String organization = null;
581 599
        
582 600
        /**
601
         * Get the organization of the user
602
         * @return
603
         */
604
        public String getOrganization() {
605
            return organization;
606
        }
607
        
608
        /**
609
         * Set the organization for the user.
610
         * @param organization
611
         */
612
        public void setOrganization(String organization) {
613
            this.organization = organization;
614
        }
615
        /**
583 616
         * Get the distinguish name of the user
584 617
         * @return the distinguish name 
585 618
         */

Also available in: Unified diff