- Authorization authorization = subject
- .getPrivateCredentials(Authorization.class).iterator().next();
- if (request != null) {
- request.setAttribute(HttpContext.REMOTE_USER,
- authorization.getName());
- request.setAttribute(HttpContext.AUTHORIZATION, authorization);
- request.getSession().setAttribute(HttpContext.AUTHORIZATION,
- authorization);
- subject.getPrivateCredentials().add(request.getSession());
+ if (locale == null)
+ subject.getPublicCredentials().add(Locale.getDefault());
+ else
+ subject.getPublicCredentials().add(locale);
+
+ if (singleUser) {
+ OsUserUtils.loginAsSystemUser(subject);
+ }
+ UserAdmin userAdmin = Activator.getUserAdmin();
+ Authorization authorization;
+ if (callbackHandler == null) {// anonymous
+ authorization = userAdmin.getAuthorization(null);
+ } else if (bindAuthorization != null) {// bind
+ authorization = bindAuthorization;
+ } else {// Kerberos
+ User authenticatingUser;
+ Set<KerberosPrincipal> kerberosPrincipals = subject.getPrincipals(KerberosPrincipal.class);
+ if (kerberosPrincipals.isEmpty()) {
+ if (authenticatedUser == null) {
+ if (log.isTraceEnabled())
+ log.trace("Neither kerberos nor user admin login succeeded. Login failed.");
+ return false;
+ } else {
+ authenticatingUser = authenticatedUser;
+ }
+ } else {
+ KerberosPrincipal kerberosPrincipal = kerberosPrincipals.iterator().next();
+ LdapName dn = IpaUtils.kerberosToDn(kerberosPrincipal.getName());
+ authenticatingUser = new AuthenticatingUser(dn);
+ if (authenticatedUser != null && !authenticatingUser.getName().equals(authenticatedUser.getName()))
+ throw new LoginException("Kerberos login " + authenticatingUser.getName()
+ + " is inconsistent with user admin login " + authenticatedUser.getName());
+ }
+ authorization = Subject.doAs(subject, new PrivilegedAction<Authorization>() {
+
+ @Override
+ public Authorization run() {
+ Authorization authorization = userAdmin.getAuthorization(authenticatingUser);
+ return authorization;
+ }
+
+ });
+ if (authorization == null)
+ throw new LoginException(
+ "User admin found no authorization for authenticated user " + authenticatingUser.getName());