Search in sources :

Example 11 with GluuOrganization

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()]);
}
Also used : GluuUserRole(org.xdi.model.GluuUserRole) GluuOrganization(org.gluu.oxtrust.model.GluuOrganization) HashSet(java.util.HashSet)

Example 12 with GluuOrganization

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;
}
Also used : GluuOrganization(org.gluu.oxtrust.model.GluuOrganization)

Example 13 with GluuOrganization

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);
    }
}
Also used : DownloadWrapper(org.xdi.util.io.DownloadWrapper) InputStream(java.io.InputStream) GluuImage(org.xdi.model.GluuImage) OutputStream(java.io.OutputStream) IOException(java.io.IOException) GluuOrganization(org.gluu.oxtrust.model.GluuOrganization) File(java.io.File) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) Date(java.util.Date)

Example 14 with GluuOrganization

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;
}
Also used : RegistrationInterceptorScript(org.gluu.oxtrust.model.RegistrationInterceptorScript) ArrayList(java.util.ArrayList) RegistrationConfiguration(org.gluu.oxtrust.model.RegistrationConfiguration) GluuOrganization(org.gluu.oxtrust.model.GluuOrganization) GluuAttribute(org.xdi.model.GluuAttribute)

Example 15 with GluuOrganization

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);
        }
    }
}
Also used : GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) ArrayList(java.util.ArrayList) GluuOrganization(org.gluu.oxtrust.model.GluuOrganization) GluuBoolean(org.xdi.ldap.model.GluuBoolean)

Aggregations

GluuOrganization (org.gluu.oxtrust.model.GluuOrganization)18 RegistrationConfiguration (org.gluu.oxtrust.model.RegistrationConfiguration)7 ArrayList (java.util.ArrayList)4 RegistrationInterceptorScript (org.gluu.oxtrust.model.RegistrationInterceptorScript)4 IOException (java.io.IOException)3 RegistrationScript (org.gluu.oxtrust.service.python.interfaces.RegistrationScript)3 GluuAttribute (org.xdi.model.GluuAttribute)3 File (java.io.File)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 GluuImage (org.xdi.model.GluuImage)2 DownloadWrapper (org.xdi.util.io.DownloadWrapper)2 ParseException (java.text.ParseException)1 HashSet (java.util.HashSet)1 AuthenticationFailedException (javax.mail.AuthenticationFailedException)1 MessagingException (javax.mail.MessagingException)1 ServletException (javax.servlet.ServletException)1