Search in sources :

Example 1 with Role

use of com.twinsoft.convertigo.engine.AuthenticatedSessionManager.Role in project convertigo by convertigo.

the class List method getServiceResult.

protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    Element root = document.getDocumentElement();
    Element usersListElement = document.createElement("users");
    root.appendChild(usersListElement);
    for (String username : Engine.authenticatedSessionManager.getUsers()) {
        Element userElement = document.createElement("user");
        userElement.setAttribute("name", username);
        for (Role role : Engine.authenticatedSessionManager.getRoles(username)) {
            Element roleElement = document.createElement("role");
            roleElement.setAttribute("name", role.name());
            userElement.appendChild(roleElement);
        }
        usersListElement.appendChild(userElement);
    }
    Element rolesListElement = document.createElement("roles");
    root.appendChild(rolesListElement);
    for (Role role : Role.values()) {
        if (role.description() != null) {
            Element roleElement = document.createElement("role");
            roleElement.setAttribute("name", role.name());
            roleElement.setAttribute("description", role.description());
            rolesListElement.appendChild(roleElement);
        }
    }
}
Also used : Role(com.twinsoft.convertigo.engine.AuthenticatedSessionManager.Role) Element(org.w3c.dom.Element)

Example 2 with Role

use of com.twinsoft.convertigo.engine.AuthenticatedSessionManager.Role in project convertigo by convertigo.

the class ServiceUtils method addRoleNodes.

public static void addRoleNodes(Element parent, Role[] roles) {
    Document document = parent.getOwnerDocument();
    Element e_roles = (Element) parent.appendChild(document.createElement("roles"));
    for (Role role : roles) {
        ((Element) e_roles.appendChild(document.createElement("role"))).setAttribute("name", role.name());
    }
}
Also used : Role(com.twinsoft.convertigo.engine.AuthenticatedSessionManager.Role) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 3 with Role

use of com.twinsoft.convertigo.engine.AuthenticatedSessionManager.Role in project convertigo by convertigo.

the class List method getServiceResult.

protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    Element rootElement = document.getDocumentElement();
    Role[] roles = Engine.authenticatedSessionManager.getRoles(request.getSession());
    for (PropertyCategory propertyCategory : PropertyCategory.getSortedValues()) {
        if (propertyCategory.isVisible() && (AuthenticatedSessionManager.hasRole(roles, Role.WEB_ADMIN) || AuthenticatedSessionManager.hasRole(roles, propertyCategory.viewRoles()))) {
            Element elementCategory = document.createElement("category");
            elementCategory.setAttribute("name", propertyCategory.toString());
            elementCategory.setAttribute("displayName", propertyCategory.getDisplayName());
            rootElement.appendChild(elementCategory);
        }
    }
    NodeList categories = document.getElementsByTagName("category");
    for (PropertyName property : PropertyName.values()) {
        if (property.isVisible()) {
            Element categoryElement = (Element) XMLUtils.findNodeByAttributeValue(categories, "name", property.getCategory().name());
            if (categoryElement != null) {
                String value = EnginePropertiesManager.getProperty(property);
                String originalValue = EnginePropertiesManager.getOriginalProperty(property);
                switch(property.getType()) {
                    case PasswordHash:
                        if ("0".equals(value)) {
                            value = "";
                        }
                    case PasswordPlain:
                        if (value.length() > 0) {
                            originalValue = value = "••••••••••••••••";
                        } else {
                            originalValue = "";
                        }
                        break;
                    default:
                        break;
                }
                Element propertyElement = document.createElement("property");
                propertyElement.setAttribute("name", property.name());
                propertyElement.setAttribute("type", property.getType().name());
                propertyElement.setAttribute("description", property.getDescription());
                propertyElement.setAttribute("value", value);
                propertyElement.setAttribute("originalValue", originalValue);
                propertyElement.setAttribute("isAdvanced", Boolean.toString(property.isAdvance()));
                categoryElement.appendChild(propertyElement);
                if (property.getType() == PropertyType.Combo) {
                    for (ComboEnum ce : property.getCombo()) {
                        String display = ce.getDisplay();
                        if (display != null) {
                            Element comboValueElement = document.createElement("item");
                            comboValueElement.setAttribute("value", ce.getValue());
                            Text comboValueText = document.createTextNode(display);
                            comboValueElement.appendChild(comboValueText);
                            propertyElement.appendChild(comboValueElement);
                        }
                    }
                }
            }
        }
    }
}
Also used : Role(com.twinsoft.convertigo.engine.AuthenticatedSessionManager.Role) PropertyCategory(com.twinsoft.convertigo.engine.EnginePropertiesManager.PropertyCategory) PropertyName(com.twinsoft.convertigo.engine.EnginePropertiesManager.PropertyName) ComboEnum(com.twinsoft.convertigo.engine.EnginePropertiesManager.ComboEnum) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Text(org.w3c.dom.Text)

Example 4 with Role

use of com.twinsoft.convertigo.engine.AuthenticatedSessionManager.Role in project convertigo by convertigo.

the class Update method getServiceResult.

protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    Element rootElement = document.getDocumentElement();
    Document post = null;
    post = XMLUtils.parseDOM(request.getInputStream());
    NodeList nl = post.getElementsByTagName("property");
    Role[] roles = Engine.authenticatedSessionManager.getRoles(request.getSession());
    for (int i = 0; i < nl.getLength(); i++) {
        String propKey = ((Element) nl.item(i)).getAttribute("key");
        PropertyName property = PropertyName.valueOf(propKey);
        if (property.isVisible()) {
            if (!AuthenticatedSessionManager.hasRole(roles, Role.WEB_ADMIN) && !AuthenticatedSessionManager.hasRole(roles, property.getCategory().configRoles())) {
                throw new AuthenticationException("Authentication failure: user has not sufficient rights!");
            }
        }
        if (property == PropertyName.SECURITY_FILTER) {
            if (!SecurityFilter.isAccept(request)) {
                throw new InvalidParameterException("Turn on '" + property.getDescription() + "' will block you current session, not allowed.");
            }
        }
    }
    for (int i = 0; i < nl.getLength(); i++) {
        String propKey = ((Element) nl.item(i)).getAttribute("key");
        PropertyName property = PropertyName.valueOf(propKey);
        if (property.isVisible()) {
            String propValue = ((Element) nl.item(i)).getAttribute("value");
            if (PropertyName.TEST_PLATFORM_PASSWORD.equals(property) || PropertyName.ADMIN_PASSWORD.equals(property)) {
                AuthenticatedSessionManager.validatePassword(propValue);
            }
            EnginePropertiesManager.setProperty(property, propValue);
            Engine.logAdmin.info("The engine property '" + propKey + "' has been updated to '" + propValue + "'");
        }
    }
    EnginePropertiesManager.saveProperties();
    Element update = document.createElement("update");
    update.setAttribute("status", "ok");
    rootElement.appendChild(update);
}
Also used : Role(com.twinsoft.convertigo.engine.AuthenticatedSessionManager.Role) PropertyName(com.twinsoft.convertigo.engine.EnginePropertiesManager.PropertyName) InvalidParameterException(java.security.InvalidParameterException) AuthenticationException(com.twinsoft.convertigo.engine.AuthenticationException) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document)

Example 5 with Role

use of com.twinsoft.convertigo.engine.AuthenticatedSessionManager.Role in project convertigo by convertigo.

the class Add method getServiceResult.

protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    String[] roles = request.getParameterValues("roles");
    Element root = document.getDocumentElement();
    Element response = document.createElement("response");
    try {
        if (StringUtils.isBlank(username)) {
            throw new IllegalArgumentException("Blank username not allowed");
        }
        if (StringUtils.isBlank(password)) {
            throw new IllegalArgumentException("Blank password not allowed");
        }
        if (Engine.authenticatedSessionManager.hasUser(username)) {
            throw new IllegalArgumentException("User '" + username + "' already exists");
        }
        Set<Role> set;
        if (roles == null) {
            set = Collections.emptySet();
        } else {
            set = new HashSet<Role>(roles.length);
            for (String role : roles) {
                set.add(Role.valueOf(role));
            }
        }
        AuthenticatedSessionManager.validatePassword(password);
        Engine.authenticatedSessionManager.setUser(username, DigestUtils.sha512Hex(password), set);
        response.setAttribute("state", "success");
        response.setAttribute("message", "User '" + username + "' have been successfully declared!");
    } catch (Exception e) {
        Engine.logAdmin.error("Error during adding the user!\n" + e.getMessage());
        response.setAttribute("state", "error");
        response.setAttribute("message", "Error during adding the user!\n" + e.getMessage());
    }
    root.appendChild(response);
}
Also used : Role(com.twinsoft.convertigo.engine.AuthenticatedSessionManager.Role) Element(org.w3c.dom.Element)

Aggregations

Role (com.twinsoft.convertigo.engine.AuthenticatedSessionManager.Role)9 Element (org.w3c.dom.Element)7 HttpSession (javax.servlet.http.HttpSession)3 PropertyName (com.twinsoft.convertigo.engine.EnginePropertiesManager.PropertyName)2 Document (org.w3c.dom.Document)2 NodeList (org.w3c.dom.NodeList)2 Session (com.twinsoft.api.Session)1 Transaction (com.twinsoft.convertigo.beans.core.Transaction)1 AuthenticationException (com.twinsoft.convertigo.engine.AuthenticationException)1 Context (com.twinsoft.convertigo.engine.Context)1 ComboEnum (com.twinsoft.convertigo.engine.EnginePropertiesManager.ComboEnum)1 PropertyCategory (com.twinsoft.convertigo.engine.EnginePropertiesManager.PropertyCategory)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileReader (java.io.FileReader)1 InvalidParameterException (java.security.InvalidParameterException)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Text (org.w3c.dom.Text)1