Пример #1
0
  @Override
  public void setUserAdmin(final UserAdmin inUserAdmin) {
    super.setUserAdmin(inUserAdmin);

    final User lAdmin = (User) inUserAdmin.createRole(Constants.USER_NAME_ADMIN, Role.USER);
    setNamePassword(lAdmin, Constants.USER_NAME_ADMIN, Constants.USER_PW_ADMIN);

    final User lUser = (User) inUserAdmin.createRole(Constants.USER_NAME_USER, Role.USER);
    setNamePassword(lUser, Constants.USER_NAME_USER, Constants.USER_PW_USER);

    final Group lAdministrators =
        (Group) inUserAdmin.createRole(Constants.ADMIN_GROUP_NAME, Role.GROUP);
    if (lAdministrators != null) {
      lAdministrators.addRequiredMember(lAdmin);
      lAdministrators.addMember(inUserAdmin.getRole(Role.USER_ANYONE));
    }
    initializePermissions();
  }
Пример #2
0
  private Authorization login(
      HttpServletRequest request, final String username, final String password)
      throws LoginException {
    Authorization a = (Authorization) request.getAttribute(HttpContext.AUTHORIZATION);
    if (a != null) {
      return a;
    }

    if (userAdmin != null) {
      User user = userAdmin.getUser("it.telecomitalia.username", username);
      if (user == null) {
        throw new LoginException();
      }
      if (!user.hasCredential("it.telecomitalia.password", password)) {
        throw new LoginException();
      }

      return userAdmin.getAuthorization(user);
    }

    throw new LoginException();
  }
Пример #3
0
  private boolean allowUser(String username, String password) {
    if (userAdmin != null) {
      User user = userAdmin.getUser("org.energy_home.jemma.username", username);
      if (user == null) {
        return false;
      }
      if (!user.hasCredential("org.energy_home.jemma.password", password)) {
        return false;
      }

      return true;
    }
    return false;
  }