added addRefreshTokenToUser in UserSessionBean. User is initialized with an empty Set of RefreshTokenEntities.
This commit is contained in:
@@ -1,18 +1,5 @@
|
||||
package com.mowesta.service.session;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.annotation.security.DeclareRoles;
|
||||
import javax.annotation.security.PermitAll;
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import com.mowesta.api.PageConfig;
|
||||
import com.mowesta.api.access.Roles;
|
||||
import com.mowesta.api.user.Email;
|
||||
@@ -40,6 +27,19 @@ import com.mowesta.service.principal.LoginManager;
|
||||
import com.mowesta.service.template.EmailAssignment;
|
||||
import com.mowesta.service.template.EmailTemplate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.annotation.security.DeclareRoles;
|
||||
import javax.annotation.security.PermitAll;
|
||||
import javax.annotation.security.RolesAllowed;
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* A stateful session bean that provides methods to manipulate
|
||||
* users.
|
||||
@@ -227,6 +227,17 @@ public class UserSessionBean extends AbstractPrincipalSessionBean {
|
||||
return page;
|
||||
}
|
||||
|
||||
@PermitAll
|
||||
public void addRefreshTokenToUser(String login, RefreshTokenEntity refreshTokenEntity) throws EntityNotFoundException {
|
||||
UserEntity u = findUser(login);
|
||||
if (u == null)
|
||||
throw new EntityNotFoundException(UserEntity.class, Long.valueOf(login), "User request by admin for non-existing user.");
|
||||
refreshTokenEntity.setUser(u);
|
||||
u.getRefreshTokens().add(refreshTokenEntity);
|
||||
em.persist(refreshTokenEntity);
|
||||
em.flush();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Registers the user and returns the new account or
|
||||
@@ -250,6 +261,7 @@ public class UserSessionBean extends AbstractPrincipalSessionBean {
|
||||
setPassword(u, registration.getPassword());
|
||||
setRoles(u, roles);
|
||||
u.setEmails(new HashSet<EmailEntity>());
|
||||
u.setRefreshTokens(new HashSet<RefreshTokenEntity>());
|
||||
em.persist(u);
|
||||
EmailEntity e = addEmail(u, registration.getEmail(), true);
|
||||
em.persist(e);
|
||||
@@ -545,24 +557,6 @@ public class UserSessionBean extends AbstractPrincipalSessionBean {
|
||||
if (u == null) throw new EntityNotFoundException(UserEntity.class, null, "Cannot access current user.");
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a refreshToken for a user.
|
||||
*
|
||||
* @param refreshToken The refreshToken to set.
|
||||
*/
|
||||
@RolesAllowed({Roles.USER })
|
||||
public void addRefreshToken(String refreshToken, String servicename) throws EntityNotFoundException {
|
||||
UserEntity u = getPrincipalUser();
|
||||
if (u == null) throw new EntityNotFoundException(UserEntity.class, null, "Cannot access current user.");
|
||||
|
||||
RefreshTokenEntity refreshTokenEntity = new RefreshTokenEntity();
|
||||
refreshTokenEntity.setRefreshToken(refreshToken);
|
||||
refreshTokenEntity.setServiceName(servicename);
|
||||
|
||||
u.getRefreshTokens().add(refreshTokenEntity);
|
||||
em.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets and updates an exisiting code for the specified action type
|
||||
|
||||
Reference in New Issue
Block a user