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);
}
}
}
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());
}
}
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);
}
}
}
}
}
}
}
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);
}
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);
}
Aggregations