use of org.gluu.oxtrust.model.GluuOrganization in project oxTrust by GluuFederation.
the class SecurityService method getUserRoles.
/**
* Get person user roles
*
* @param user
* Person
* @return List of roles
* @throws Exception
* exception
*/
public GluuUserRole[] getUserRoles(User user) {
GluuOrganization organization = organizationService.getOrganization();
// String ownerGroupDn = organization.getOwnerGroup();
String managerGroupDn = organization.getManagerGroup();
String personDN = user.getDn();
Set<GluuUserRole> userRoles = new HashSet<GluuUserRole>();
if (groupService.isMemberOrOwner(managerGroupDn, personDN)) {
userRoles.add(GluuUserRole.MANAGER);
}
if ((userRoles.size() == 0)) /*
* &&
* (GluuStatus.ACTIVE.equals(person.getStatus
* ()))
*/
{
userRoles.add(GluuUserRole.USER);
}
return userRoles.toArray(new GluuUserRole[userRoles.size()]);
}
use of org.gluu.oxtrust.model.GluuOrganization in project oxTrust by GluuFederation.
the class OrganizationService method getOrganizationByInum.
/**
* Get organization by DN
*
* @param inum
* inum
* @return Organization
*/
public GluuOrganization getOrganizationByInum(String inum) {
String key = OxTrustConstants.CACHE_ORGANIZATION_KEY + "_" + inum;
GluuOrganization organization = (GluuOrganization) cacheService.get(OxTrustConstants.CACHE_APPLICATION_NAME, key);
if (organization == null) {
organization = ldapEntryManager.find(GluuOrganization.class, getDnForOrganization(inum));
cacheService.put(OxTrustConstants.CACHE_APPLICATION_NAME, key, organization);
}
return organization;
}
use of org.gluu.oxtrust.model.GluuOrganization in project oxTrust by GluuFederation.
the class FaviconImageServlet method doGet.
@Override
protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse response) throws ServletException, IOException {
log.debug("Starting organization favicon upload");
String preview = httpServletRequest.getParameter("preview");
GluuOrganization organization = null;
try {
organization = organizationService.getOrganization();
} catch (Exception ex) {
log.error("an Error Occured", ex);
}
GluuImage image = null;
if ("true".equals(preview)) {
image = imageService.getGluuImageFromXML(organization.getTempFaviconImage());
if (image != null) {
image.setStoreTemporary(true);
}
}
if (!"true".equals(preview) || image == null) {
image = imageService.getGluuImageFromXML(organization.getFaviconImage());
}
if (image != null) {
image.setLogo(false);
}
OutputStream os = null;
InputStream is = null;
try {
DownloadWrapper downloadWrapper = null;
// Send customized organization logo
if (image != null) {
File file = null;
try {
file = imageService.getSourceFile(image);
} catch (Exception ex) {
log.error("an Error Occured", ex);
}
try {
is = FileUtils.openInputStream(file);
if (is != null && file != null) {
downloadWrapper = new DownloadWrapper(is, image.getSourceName(), image.getSourceContentType(), image.getCreationDate(), (int) file.length());
}
} catch (IOException ex) {
log.error("Organization favicon image doesn't exist", ex);
FileDownloader.sendError(response);
return;
}
} else {
// If customized logo doesn't exist then send default
// organization logo
String defaultFaviconFileName = "/WEB-INF/static/images/favicon_ic.ico";
is = getServletContext().getResourceAsStream(defaultFaviconFileName);
if (is == null) {
log.error("Default organization favicon image doesn't exist");
FileDownloader.sendError(response);
return;
}
// Calculate default logo size
long contentLength;
try {
contentLength = is.skip(Long.MAX_VALUE);
} catch (IOException ex) {
log.error("Failed to calculate default organization favicon image size", ex);
FileDownloader.sendError(response);
return;
} finally {
IOUtils.closeQuietly(is);
}
is = getServletContext().getResourceAsStream(defaultFaviconFileName);
downloadWrapper = new DownloadWrapper(is, "favicon_ic.ico", "image/x-icon", new Date(), (int) contentLength);
}
try {
int logoSize = FileDownloader.writeOutput(downloadWrapper, ContentDisposition.INLINE, response);
response.getOutputStream().flush();
log.debug("Successfully send organization favicon with size", logoSize);
} catch (IOException ex) {
log.error("Failed to send organization favicon", ex);
FileDownloader.sendError(response);
}
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
}
}
use of org.gluu.oxtrust.model.GluuOrganization in project oxTrust by GluuFederation.
the class RegistrationManagementAction method init.
public String init() {
customScriptTypes = new ArrayList<String>();
customScriptTypes.add(OxTrustConstants.INIT_REGISTRATION_SCRIPT);
customScriptTypes.add(OxTrustConstants.PRE_REGISTRATION_SCRIPT);
customScriptTypes.add(OxTrustConstants.POST_REGISTRATION_SCRIPT);
GluuOrganization org = organizationService.getOrganization();
RegistrationConfiguration config = org.getOxRegistrationConfiguration();
List<RegistrationInterceptorScript> newScripts = new ArrayList<RegistrationInterceptorScript>();
String configLinksExpirationFrequency = null;
String configAccountsExpirationServiceFrequency = null;
String configAccountsExpirationPeriod = null;
if (config != null) {
List<RegistrationInterceptorScript> scripts = config.getRegistrationInterceptorScripts();
if (scripts != null && !scripts.isEmpty()) {
newScripts.addAll(scripts);
}
configureInterceptors = config.isRegistrationInterceptorsConfigured();
captchaDisabled = config.isCaptchaDisabled();
List<String> attributeList = config.getAdditionalAttributes();
if (attributeList != null && !attributeList.isEmpty()) {
configureRegistrationForm = true;
for (String attributeInum : attributeList) {
GluuAttribute attribute = attributeService.getAttributeByInum(attributeInum);
selectedAttributes.add(attribute);
attributes.add(attribute);
}
}
}
registrationInterceptors = newScripts;
return OxTrustConstants.RESULT_SUCCESS;
}
use of org.gluu.oxtrust.model.GluuOrganization in project oxTrust by GluuFederation.
the class UpdateGroupAction method updatePersons.
private void updatePersons(List<DisplayNameEntry> oldMembers, List<DisplayNameEntry> newMembers) throws Exception {
log.debug("Old members: {}", oldMembers);
log.debug("New members: {}", newMembers);
String groupDn = this.group.getDn();
GluuOrganization organization = organizationService.getOrganization();
String[] organizationGroups = { organization.getManagerGroup() };
// Convert members to array of DNs
String[] oldMemberDns = convertToDNsArray(oldMembers);
String[] newMemberDns = convertToDNsArray(newMembers);
Arrays.sort(oldMemberDns);
Arrays.sort(newMemberDns);
boolean[] retainOldMembers = new boolean[oldMemberDns.length];
Arrays.fill(retainOldMembers, false);
List<String> addedMembers = new ArrayList<String>();
List<String> removedMembers = new ArrayList<String>();
List<String> existingMembers = new ArrayList<String>();
// Add new values
for (String value : newMemberDns) {
int idx = Arrays.binarySearch(oldMemberDns, value);
if (idx >= 0) {
// Old members array contains member. Retain member
retainOldMembers[idx] = true;
} else {
// This is new member
addedMembers.add(value);
}
}
// Remove members which we don't have in new members
for (int i = 0; i < oldMemberDns.length; i++) {
if (retainOldMembers[i]) {
existingMembers.add(oldMemberDns[i]);
} else {
removedMembers.add(oldMemberDns[i]);
}
}
for (String dn : addedMembers) {
GluuCustomPerson person = personService.getPersonByDn(dn);
log.debug("Adding group {} to person {} memberOf", groupDn, person.getDisplayName());
if (appConfiguration.isUpdateApplianceStatus()) {
GluuBoolean slaManager = isSLAManager(organizationGroups, person);
person.setSLAManager(slaManager);
}
List<String> personMemberOf = new ArrayList<String>(person.getMemberOf());
personMemberOf.add(groupDn);
person.setMemberOf(personMemberOf);
personService.updatePerson(person);
}
for (String dn : removedMembers) {
GluuCustomPerson person = personService.getPersonByDn(dn);
log.debug("Removing group {} from person {} memberOf", groupDn, person.getDisplayName());
if (appConfiguration.isUpdateApplianceStatus()) {
GluuBoolean slaManager = isSLAManager(organizationGroups, person);
person.setSLAManager(slaManager);
}
List<String> personMemberOf = new ArrayList<String>(person.getMemberOf());
personMemberOf.remove(groupDn);
person.setMemberOf(personMemberOf);
personService.updatePerson(person);
}
if (appConfiguration.isUpdateApplianceStatus()) {
// Update existing members if needed
for (String dn : existingMembers) {
GluuCustomPerson person = personService.getPersonByDn(dn);
log.debug("Updating group {} to person {} memberOf", groupDn, person.getDisplayName());
GluuBoolean slaManager = isSLAManager(organizationGroups, person);
if (slaManager.equals(person.getSLAManager())) {
continue;
}
person.setSLAManager(slaManager);
personService.updatePerson(person);
}
}
}
Aggregations