- UiContext.setLocale(locale);
-
- if (authorization == null) {
- // create credentials
- final String username = nameCallback.getName();
- if (username == null || username.trim().equals("")) {
- // authorization = userAdmin.getAuthorization(null);
- throw new CredentialNotFoundException(
- "No credentials provided");
- } else {
- char[] password = {};
- if (passwordCallback.getPassword() != null)
- password = passwordCallback.getPassword();
- else
- throw new CredentialNotFoundException(
- "No credentials provided");
-
- User user = userAdmin.getUser(null, username);
- if (user == null)
- return false;
- if (!user.hasCredential(null, password))
- return false;
- authorization = userAdmin.getAuthorization(user);
+ // FIXME add it to Subject
+ // Locale.setDefault(locale);
+
+ username = nameCallback.getName();
+ if (username == null || username.trim().equals("")) {
+ // authorization = userAdmin.getAuthorization(null);
+ throw new CredentialNotFoundException("No credentials provided");
+ }
+ if (passwordCallback.getPassword() != null)
+ password = passwordCallback.getPassword();
+ else
+ throw new CredentialNotFoundException("No credentials provided");
+ sharedState.put(CmsAuthUtils.SHARED_STATE_NAME, username);
+ sharedState.put(CmsAuthUtils.SHARED_STATE_PWD, password);
+ }
+ User user = searchForUser(userAdmin, username);
+
+ // Tokens
+ if (user == null) {
+ String token = username;
+ Group tokenGroup = searchForToken(userAdmin, token);
+ if (tokenGroup != null) {
+ Authorization tokenAuthorization = getAuthorizationFromToken(userAdmin, tokenGroup);
+ if (tokenAuthorization != null) {
+ bindAuthorization = tokenAuthorization;
+ authenticatedUser = (User) userAdmin.getRole(bindAuthorization.getName());
+ return true;
+ }
+ }
+ }
+
+ if (user == null)
+ return true;// expect Kerberos
+
+ if (password != null) {
+ // TODO disabling bind for the time being,
+ // as it requires authorisations to be set at LDAP level
+ boolean tryBind = false;
+ // try bind first
+ if (tryBind)
+ try {
+ AuthenticatingUser authenticatingUser = new AuthenticatingUser(user.getName(), password);
+ bindAuthorization = userAdmin.getAuthorization(authenticatingUser);
+ // TODO check tokens as well
+ if (bindAuthorization != null) {
+ authenticatedUser = user;
+ return true;
+ }
+ } catch (Exception e) {
+ // silent
+ if (log.isTraceEnabled())
+ log.trace("Bind failed", e);