- Set<Principal> principals = subject.getPrincipals();
- try {
- String authName = authorization.getName();
-
- // determine user's principal
- final LdapName name;
- final Principal userPrincipal;
- if (authName == null) {
- name = ROLE_ANONYMOUS_NAME;
- userPrincipal = ROLE_ANONYMOUS_PRINCIPAL;
- principals.add(userPrincipal);
- principals.add(new AnonymousPrincipal());
- } else {
- name = new LdapName(authName);
- checkUserName(name);
- userPrincipal = new X500Principal(name.toString());
- principals.add(userPrincipal);
- principals.add(new ImpliedByPrincipal(ROLE_USER_NAME,
- userPrincipal));
- }
-
- // Add roles provided by authorization
- for (String role : authorization.getRoles()) {
- LdapName roleName = new LdapName(role);
- if (roleName.equals(name)) {
- // skip
- } else {
- checkImpliedPrincipalName(roleName);
- principals.add(new ImpliedByPrincipal(roleName.toString(),
- userPrincipal));
- if (roleName.equals(ROLE_ADMIN_NAME))
- principals.add(new AdminPrincipal(
- SecurityConstants.ADMIN_ID));
- }
- }
-
- return true;
- } catch (InvalidNameException e) {
- throw new CmsException("Cannot commit", e);
- }
+ CmsAuthUtils.addAuthentication(subject, authorization);
+ return true;
+ // // required for display name:
+ // subject.getPrivateCredentials().add(authorization);
+ //
+ // Set<Principal> principals = subject.getPrincipals();
+ // try {
+ // String authName = authorization.getName();
+ //
+ // // determine user's principal
+ // final LdapName name;
+ // final Principal userPrincipal;
+ // if (authName == null) {
+ // name = ROLE_ANONYMOUS_NAME;
+ // userPrincipal = ROLE_ANONYMOUS_PRINCIPAL;
+ // principals.add(userPrincipal);
+ // principals.add(new AnonymousPrincipal());
+ // } else {
+ // name = new LdapName(authName);
+ // checkUserName(name);
+ // userPrincipal = new X500Principal(name.toString());
+ // principals.add(userPrincipal);
+ // principals.add(new ImpliedByPrincipal(ROLE_USER_NAME,
+ // userPrincipal));
+ // }
+ //
+ // // Add roles provided by authorization
+ // for (String role : authorization.getRoles()) {
+ // LdapName roleName = new LdapName(role);
+ // if (roleName.equals(name)) {
+ // // skip
+ // } else {
+ // checkImpliedPrincipalName(roleName);
+ // principals.add(new ImpliedByPrincipal(roleName.toString(),
+ // userPrincipal));
+ // if (roleName.equals(ROLE_ADMIN_NAME))
+ // principals.add(new AdminPrincipal(SecurityConstants.ADMIN_ID));
+ // }
+ // }
+ //
+ // return true;
+ // } catch (InvalidNameException e) {
+ // throw new CmsException("Cannot commit", e);
+ // }