- String username = System.getProperty("user.name");
- X500Principal principal = new X500Principal("uid=" + username
- + ",dc=localhost,dc=localdomain");
+ X500Principal principal;
+ KerberosPrincipal kerberosPrincipal = CmsAuthUtils.getSinglePrincipal(subject, KerberosPrincipal.class);
+ if (kerberosPrincipal != null) {
+ LdapName userDn = IpaUtils.kerberosToDn(kerberosPrincipal.getName());
+ principal = new X500Principal(userDn.toString());
+ } else {
+ Object username = sharedState.get(CmsAuthUtils.SHARED_STATE_NAME);
+ if (username == null)
+ throw new LoginException("No username available");
+ String hostname;
+ try {
+ hostname = InetAddress.getLocalHost().getHostName();
+ } catch (UnknownHostException e) {
+ log.warn("Using localhost as hostname", e);
+ hostname = "localhost";
+ }
+ String baseDn = ("." + hostname).replaceAll("\\.", ",dc=");
+ principal = new X500Principal(LdapAttrs.uid + "=" + username + baseDn);
+ }