Announcement Announcement Module
Collapse
No announcement yet.
Security: Principal on the server side Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Security: Principal on the server side

    Did any body try to get Principal (user name) on the server side? I am getting Context null.
    I want to know what was the design idea: should client pass to the server user name and password on each request?

    Thank you

  • #2
    Jurijus

    I usually use:
    Code:
    /**
         * getUsername
         * We the username from the securityContextHolder.
         * @return String
         */
        private String getUsername() {
            Authentication auth = SecurityContextHolder.getContext()
                                  .getAuthentication();
    
            if (auth.getPrincipal() instanceof UserDetails) {
                return ((UserDetails)auth.getPrincipal()).getUsername();
            }
            else {
                return auth.getPrincipal().toString();
            }
        }
    im my services implementation I run in the server and are exposed with some remoting (in our case httpinvoker).

    We are using the whole acegi stuff for this including of course remoting for Acegi (xxx.httpinvoker.BasicAuthHttpInvokerProxyFactoryB ean). Nothing that special.

    Should work.

    Cheers,
    Gustavo

    Comment


    • #3
      Thanks for you help Gustavo!

      Comment

      Working...
      X