package com.mobius.model;
import com.adobe.idp.um.api.UMException;
import com.adobe.idp.um.api.infomodel.PrincipalSearchFilter;
import com.adobe.idp.um.api.infomodel.User;
import com.adobe.idp.um.api.infomodel.impl.RoleImpl;
import com.adobe.livecycle.usermanager.client.DirectoryManagerServiceClient;
import com.mobius.livecycle.LiveCycleService;
import com.mobius.utils.ResourceManager;
import java.util.Iterator;
import java.util.List;
/**
* Created with IntelliJ IDEA.
* User: Pawel
* Date: 02.01.14
* Time: 11:04
* To change this template use File | Settings | File Templates.
*/
public class LoggedUser {
private LiveCycleService liveCycleService;
private ResourceManager resourceManager;
public LoggedUser(String userName, String password) {
resourceManager = new ResourceManager();
liveCycleService = new LiveCycleService(getResourceManager());
this.userName = userName;
this.password = password;
}
public boolean authorize() {
if (liveCycleService.authorize(userName, password)) {
try {
PrincipalSearchFilter psf = new PrincipalSearchFilter();
DirectoryManagerServiceClient dirClient = new DirectoryManagerServiceClient(liveCycleService.getServiceClientFactory());
psf.setUserIdAbsolute(userName);
List<?> principalList = null;
principalList = dirClient.findPrincipals(psf);
Iterator<?> pit = principalList.iterator();
User lcUser = null;
if (pit.hasNext())
lcUser = (User) (pit.next());
canonicalName = lcUser.getCanonicalName();
userLogin = lcUser.getUserid();
userFullName = lcUser.getCommonName();
domainName = lcUser.getDomainName();
userRights = new String[lcUser.getRoleMembership().size()];
int counter = 0;
for (Object o : lcUser.getRoleMembership()) {
RoleImpl role = (RoleImpl)o;
if(role.getId().equals("BASIC_ROLE_APPLICATION_ADMINISTRATOR")){
this.admin = true;
}
userRights[counter] = role.getId();
counter++;
}
} catch (UMException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
return true;
}
return false;
}
public LiveCycleService getLiveCycleService() {
return liveCycleService;
}
public void setLiveCycleService(LiveCycleService liveCycleService) {
this.liveCycleService = liveCycleService;
}
private String[] userRights;
private String userFullName;
private String userLogin;
private String userName;
private String password;
private String canonicalName;
private String domainName;
private Boolean admin = false;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getCanonicalName() {
return canonicalName;
}
public void setCanonicalName(String canonicalName) {
this.canonicalName = canonicalName;
}
public String getDomainName() {
return domainName;
}
public void setDomainName(String domainName) {
this.domainName = domainName;
}
private ResponseUser responseUser = null;
public ResponseUser getResponseUser() {
if(responseUser==null) {
responseUser = new ResponseUser();
responseUser.setUser_fullname(this.userFullName);
responseUser.setUser_id(this.canonicalName);
responseUser.setUser_name(this.userLogin);
responseUser.setUser_permissions(this.userRights);
responseUser.setAdmin_access(this.admin);
}
return responseUser;
}
public ResourceManager getResourceManager() {
return resourceManager;
}
}