Package ch.entwine.weblounge.security.sql.entities

Examples of ch.entwine.weblounge.security.sql.entities.JpaAccount


      password = PasswordEncoder.encode(StringUtils.trim(password));
    }

    // Create the user
    try {
      JpaAccount account = directory.addAccount(site, login, password);
      account.setEmail(StringUtils.trimToNull(eMail));
      directory.updateAccount(account);
      response = Response.created(new URI(UrlUtils.concat(request.getRequestURL().toString(), account.getLogin()))).build();
    } catch (UserExistsException e) {
      logger.warn("Error creating account: {}", e.getMessage());
      return Response.status(Status.CONFLICT).build();
    } catch (UserShadowedException e) {
      logger.warn("Error creating account: {}", e.getMessage());
View Full Code Here


  @Path("/account/{login}")
  public Response getAccount(@PathParam("login") String login,
      @Context HttpServletRequest request) {
    Site site = getSite(request);

    JpaAccount account = null;
    try {
      account = directory.getAccount(site, login);
    } catch (Throwable t) {
      logger.warn("Error accessing account '{}': {}", login, t.getMessage());
      throw new WebApplicationException();
    }

    if (account == null)
      throw new WebApplicationException(Status.NOT_FOUND);

    WebloungeUser wu = new WebloungeUserImpl(login, directory.getIdentifier());
    wu.setFirstName(account.getFirstname());
    wu.setLastName(account.getLastname());
    wu.setEmail(account.getEmail());
    wu.setInitials(account.getInitials());
    wu.setLastLogin(account.getLastLoginDate(), account.getLastLoginFrom());
    wu.setChallenge(account.getChallenge());
    if (account.getLanguage() != null)
      wu.setLanguage(LanguageUtils.getLanguage(account.getLanguage()));
    if (account.getResponse() != null)
      wu.setResponse(account.getResponse().getBytes(Charset.forName("utf-8")), DigestType.md5);
    for (JpaRole r : account.getRoles()) {
      wu.addPublicCredentials(new RoleImpl(r.getContext(), r.getRolename()));
    }

    return Response.ok(wu.toXml()).build();
  }
View Full Code Here

    // Make sure that the user owns the roles required for this operation
    User user = securityService.getUser();
    if (!SecurityUtils.userHasRole(user, SystemRole.SITEADMIN) && !user.getLogin().equals(login))
      return Response.status(Status.FORBIDDEN).build();

    JpaAccount account = null;
    Site site = getSite(request);
    try {
      account = directory.getAccount(site, login);
      if (account == null)
        return Response.status(Status.NOT_FOUND).build();

      // Hash the password
      if (StringUtils.isNotBlank(password)) {
        logger.debug("Hashing password for user '{}@{}' using md5", login, site.getIdentifier());
        String digestPassword = PasswordEncoder.encode(StringUtils.trim(password));
        account.setPassword(digestPassword);
      }

      account.setFirstname(StringUtils.trimToNull(firstname));
      account.setLastname(StringUtils.trimToNull(lastname));
      account.setInitials(StringUtils.trimToNull(initials));
      account.setEmail(StringUtils.trimToNull(email));

      // The language
      if (StringUtils.isNotBlank(language)) {
        try {
          account.setLanguage(LanguageUtils.getLanguage(language));
        } catch (UnknownLanguageException e) {
          return Response.status(Status.BAD_REQUEST).build();
        }
      } else {
        account.setLanguage(null);
      }

      // Hash the response
      if (StringUtils.isNotBlank(response)) {
        logger.debug("Hashing response for user '{}@{}' using md5", login, site.getIdentifier());
        String digestResponse = PasswordEncoder.encode(StringUtils.trim(response));
        account.setResponse(digestResponse);
      }

      directory.updateAccount(account);
      return Response.ok().build();
    } catch (Throwable t) {
View Full Code Here

    // Make sure that the user owns the roles required for this operation
    User user = securityService.getUser();
    if (!SecurityUtils.userHasRole(user, SystemRole.SITEADMIN) && !user.getLogin().equals(login))
      return Response.status(Status.FORBIDDEN).build();

    JpaAccount account = null;
    Site site = getSite(request);
    try {
      account = directory.getAccount(site, login);
      if (account == null)
        return Response.status(Status.NOT_FOUND).build();

      // Hash the password
      if (StringUtils.isNotBlank(password)) {
        logger.debug("Hashing password for user '{}@{}' using md5", login, site.getIdentifier());
        String digestPassword = PasswordEncoder.encode(StringUtils.trim(password));
        account.setPassword(digestPassword);
      } else {
        account.setPassword(null);
      }

      directory.updateAccount(account);
      return Response.ok().build();
    } catch (Throwable t) {
View Full Code Here

    // Make sure that the user owns the roles required for this operation
    User user = securityService.getUser();
    if (!SecurityUtils.userHasRole(user, SystemRole.SITEADMIN) && !user.getLogin().equals(login))
      return Response.status(Status.FORBIDDEN).build();

    JpaAccount account = null;
    Site site = getSite(request);
    try {
      account = directory.getAccount(site, login);
      if (account == null)
        return Response.status(Status.NOT_FOUND).build();

      // Set the challenge
      account.setChallenge(StringUtils.trimToNull(challenge));

      // Hash the response
      if (StringUtils.isNotBlank(response)) {
        logger.debug("Hashing response for user '{}@{}' using md5", login, site.getIdentifier());
        String digestResponse = PasswordEncoder.encode(StringUtils.trim(response));
        account.setResponse(digestResponse);
      } else {
        account.setResponse(response);
      }

      directory.updateAccount(account);
      return Response.ok().build();
    } catch (Throwable t) {
View Full Code Here

    if (!SecurityUtils.userHasRole(user, SystemRole.SITEADMIN) && !user.getLogin().equals(login))
      return Response.status(Status.FORBIDDEN).build();

    Site site = getSite(request);
    try {
      JpaAccount account = directory.getAccount(site, login);
      if (account == null)
        return Response.status(Status.NOT_FOUND).build();

      directory.removeAccount(site, login);
      return Response.ok().build();
View Full Code Here

    // Make sure that the user owns the roles required for this operation
    User user = securityService.getUser();
    if (!SecurityUtils.userHasRole(user, SystemRole.SITEADMIN))
      return Response.status(Status.FORBIDDEN).build();

    JpaAccount account = null;
    Site site = getSite(request);
    try {
      account = directory.getAccount(site, login);
      if (account == null)
        return Response.status(Status.NOT_FOUND).build();
      if (account.isEnabled())
        return Response.status(Status.NOT_MODIFIED).build();

      directory.enableAccount(site, login);
      return Response.ok().build();
    } catch (Throwable t) {
View Full Code Here

    // Make sure that the user owns the roles required for this operation
    User user = securityService.getUser();
    if (!SecurityUtils.userHasRole(user, SystemRole.SITEADMIN))
      return Response.status(Status.FORBIDDEN).build();

    JpaAccount account = null;
    Site site = getSite(request);
    try {
      account = directory.getAccount(site, login);
      if (account == null)
        return Response.status(Status.NOT_FOUND).build();
      if (!account.isEnabled())
        return Response.status(Status.NOT_MODIFIED).build();

      directory.disableAccount(site, login);
      return Response.ok().build();
    } catch (Throwable t) {
View Full Code Here

    // Make sure a role has been provided as part of the request
    if (StringUtils.isBlank(role))
      return Response.status(Status.BAD_REQUEST).build();

    JpaAccount account = null;
    Site site = getSite(request);
    try {
      account = directory.getAccount(site, login);
      if (account == null)
        return Response.status(Status.NOT_FOUND).build();

      if (account.hasRole(context, role))
        return Response.status(Status.NOT_MODIFIED).build();

      account.addRole(context, role);
      directory.updateAccount(account);
      return Response.ok().build();
    } catch (Throwable t) {
      logger.warn("Error adding role '{}:{}' to account {}: {}", new String[] {
          context,
View Full Code Here

    // Make sure a role has been provided as part of the request
    if (StringUtils.isBlank(role))
      return Response.status(Status.BAD_REQUEST).build();

    JpaAccount account = null;
    Site site = getSite(request);
    try {
      account = directory.getAccount(site, login);
      if (account == null)
        return Response.status(Status.NOT_FOUND).build();

      if (!account.hasRole(context, role))
        return Response.status(Status.NOT_MODIFIED).build();

      account.removeRole(context, role);
      directory.updateAccount(account);
      return Response.ok().build();
    } catch (Throwable t) {
      logger.warn("Error adding role '{}:{}' to account: {}", new String[] {
          context,
View Full Code Here

TOP

Related Classes of ch.entwine.weblounge.security.sql.entities.JpaAccount

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.