sk.seges.acris.security.server.user_management.service.OpenIDUserService Maven / Gradle / Ivy
package sk.seges.acris.security.server.user_management.service;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import sk.seges.acris.security.server.core.user_management.dao.user.IGenericUserDao;
import sk.seges.acris.security.server.user_management.dao.api.IOpenIDUserDao;
import sk.seges.acris.security.server.user_management.domain.api.server.model.data.OpenIDUserData;
import sk.seges.acris.security.server.user_management.domain.jpa.JPAOpenIDUser;
import sk.seges.acris.security.shared.user_management.domain.api.OpenIDProvider;
import sk.seges.acris.security.shared.user_management.domain.api.UserData;
import sk.seges.acris.security.shared.user_management.domain.api.UserDataMetaModel;
import sk.seges.acris.security.shared.user_management.domain.dto.GenericUserDTO;
import sk.seges.acris.security.shared.user_management.service.IOpenIDUserService;
import sk.seges.sesam.dao.Filter;
import sk.seges.sesam.dao.Page;
import sk.seges.sesam.dao.SimpleExpression;
public class OpenIDUserService implements IOpenIDUserService {
private static final long serialVersionUID = 6393202762149693176L;
private IGenericUserDao genericUserDao;
private IOpenIDUserDao openIDUserDao;
public OpenIDUserService(IGenericUserDao genericUserDao,
IOpenIDUserDao openIDUserDao) {
this.genericUserDao = genericUserDao;
this.openIDUserDao = openIDUserDao;
}
@Override
public UserData getUserByOpenIDIdentifier(String identifier) {
Page page = new Page(0, Page.ALL_RESULTS);
page.setFilterable(new SimpleExpression>("id", identifier, Filter.EQ));
List result = openIDUserDao.findAll(page).getResult();
if (result.size() > 0) {
return convert(result.get(0).getUser());
}
return null;
}
/**
* Converts source domain object to DTO.
*
* @param source
* @return
*/
private UserData convert(UserData source) {
UserData target = new GenericUserDTO();
target.setEnabled(source.isEnabled());
target.setId((Long) source.getId());
target.setPassword(source.getPassword());
target.setUserAuthorities(source.getUserAuthorities());
target.setUsername(source.getUsername());
return target;
}
@Override
public List findProvidersByUserName(String userName) {
Page page = new Page(0, Page.ALL_RESULTS);
page.setFilterable(new SimpleExpression>(
OpenIDUserData.USER + "." + UserDataMetaModel.USERNAME, userName, Filter.EQ));
List result = new ArrayList();
List found = openIDUserDao.findAll(page).getResult();
for (OpenIDUserData hasOpenIDIdentifier : found) {
result.add(hasOpenIDIdentifier.getProvider());
}
return result;
}
@Override
public void saveUserByIdentifiers(String userName, Map identifiers) {
JPAOpenIDUser entity = new JPAOpenIDUser();
entity.setUser(genericUserDao.findByUsername(userName));
String identifier = (String) identifiers.get("identifier");
if (identifier != null) {
entity.setId(identifier);
}
String email = (String) identifiers.get("email");
if (email != null) {
entity.setEmail(email);
}
String providerName = (String) identifiers.get("provider");
if (providerName != null) {
if (providerName.equals(OpenIDProvider.GOOGLE.name())) {
entity.setProvider(OpenIDProvider.GOOGLE);
} else if (providerName.equals(OpenIDProvider.YAHOO.name())) {
entity.setProvider(OpenIDProvider.YAHOO);
} else if (providerName.equals(OpenIDProvider.AOL.name())) {
entity.setProvider(OpenIDProvider.AOL);
} else if (providerName.equals(OpenIDProvider.SEZNAM.name())) {
entity.setProvider(OpenIDProvider.SEZNAM);
} else if (providerName.equals(OpenIDProvider.MYOPENID.name())) {
entity.setProvider(OpenIDProvider.MYOPENID);
}
}
openIDUserDao.persist(entity);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy