2017-12-07 13 views
1

:ldap에서 사용자 정보를 얻는 방법? 내가 LDAP 확인을 위하여 아파치 시로을 사용하고

Factory<SecurityManager> ldapFactory = new IniSecurityManagerFactory("classpath:active.ini"); 
SecurityManager sManager = ldapFactory.getInstance(); 
SecurityUtils.setSecurityManager(sManager); 

Subject currentUser = SecurityUtils.getSubject(); 

     if (!currentUser.isAuthenticated()) { 
      UsernamePasswordToken token = new UsernamePasswordToken("user", "password"); 
      try { 
       currentUser.login(token); 
      } catch (UnknownAccountException ex) { 
       logger.info("Unknown user"); 
      } catch (IncorrectCredentialsException ex) { 
       logger.info("Incorrect credentials"); 
      } catch (LockedAccountException ex) { 
       logger.info("Account is Locked"); 
      } catch (AuthenticationException ex) { 
       logger.info("Authentication Exception"); 
      } 
     } 

     logger.info("User [" + currentUser.getPrincipal() +"] logged succesfully"); 
     currentUser.logout(); 

currentUser.getPrincipal()를 호출하면, 내가 로그인 한 사용자의 전용 이메일 주소를 가지고있다.
더 많은 사용자 정보를 얻는 방법 (예 : 성, 이름 등)?

답변

1

getPrincipal()은 주체의 식별자 만 반환합니다. 대신 getPrincipals()을 사용해보십시오.

객체 해, getPrincipal()
반환이 주제의 응용 프로그램 전체 고유하게 식별 교장, 또는이 주제 익명의 경우는 null. 는 PrincipalCollection 또는 null 의 형태 (속성을 식별하는)이 주제는 당신이를 확장 할 수

Apache Shiro API (JavaDoc)

+0

나는 그것을 이미 시도했고'getPrincipal()'과 같은 것을 얻었다. 나는'getPrincipals()'를 반복했지만 결과는'getPrincipal()'과 같습니다. –

0

익명

PrincipalCollection의 getPrincipals()
반환이 Subject의 주체 인 경우 LDAP 영역. Principal/PrincipalCollection에 컨텍스트 추가 (또는 사용자 지정 개체 또는 사용자 교장 반환)

이 항목은 old thread입니다.하지만이 항목은 한 번씩 파고 들며이 항목을 다룹니다. Shiro의 원래 프로젝트 이름).