Skip to content
Snippets Groups Projects
Commit eeeb43bd authored by Nils Christian Ehmke's avatar Nils Christian Ehmke
Browse files

Some minor code modifications for quality reasons.

parent 14d9ec47
No related branches found
No related tags found
No related merge requests found
Showing
with 148 additions and 11 deletions
......@@ -136,7 +136,7 @@ public final class GlobalPropertiesBean implements Serializable {
/**
* Setter for the property {@link GlobalPropertiesBean#analysisEditorGridSizeCookieName}. <b>Do not use this method. This property is Spring managed.</b>
*
* @param projectOverviewPage
* @param analysisEditorGridSizeCookieName
* The new value for the property.
*/
public void setAnalysisEditorGridSizeCookieName(final String analysisEditorGridSizeCookieName) {
......
......@@ -34,7 +34,6 @@ import kieker.webgui.common.IProjectManagerFacade;
import kieker.webgui.common.exception.ProjectAlreadyExistingException;
import kieker.webgui.common.exception.ProjectLoadException;
import kieker.webgui.common.exception.ProjectNotExistingException;
import kieker.webgui.common.impl.ProjectManagerFacadeImpl;
/**
* The {@link ProjectsBean} is a Spring managed bean to manage a list with all application wide available projects. It provides methods to receive this list as well
......@@ -91,6 +90,8 @@ public final class ProjectsBean {
*
* @param project
* The name for the new project which should be added to the application.
* @param currentProjectOverviewBean
* The current instance of {@link CurrentProjectOverviewBean} which will be used to update the list of projects.
*/
public void addProject(final String project, final CurrentProjectOverviewBean currentProjectOverviewBean) {
try {
......@@ -122,6 +123,8 @@ public final class ProjectsBean {
* The name of the source project.
* @param destinationProject
* The name of the new (copied) project.
* @param currentProjectOverviewBean
* The current instance of {@link CurrentProjectOverviewBean} which will be used to update the list of projects.
*/
public void copyProject(final String sourceProject, final String destinationProject, final CurrentProjectOverviewBean currentProjectOverviewBean) {
try {
......@@ -148,7 +151,7 @@ public final class ProjectsBean {
/**
* This method can be used to open an already existing project. This means that the current state of the project on the file system is loaded into an instance of
* {@link MIProject}. This instance can be modified at will and for example later saved by the {@link ProjectManagerFacadeImpl}.
* {@link MIProject}. This instance can be modified at will and for example later saved by the {@link IProjectManagerFacade}.
*
* @param project
* The name of the project to be opened.
......
......@@ -50,6 +50,7 @@ public final class ThemeSwitcherBean {
* The setter for the property {@link ThemeSwitcherBean#themes}. <b>Do not use this method. This property is Spring managed.</b>
*
* @param themes
* The value for the property.
*/
public void setThemes(final Map<String, String> themes) {
this.themes = themes;
......
/***************************************************************************
* Copyright 2012 Kieker Project (http://kieker-monitoring.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
package kieker.webgui.beans.request;
import java.util.ArrayList;
......@@ -5,6 +21,12 @@ import java.util.List;
import kieker.webgui.common.Role;
/**
* This simple bean is request scoped and can be used to store the necessary data for a new user during a request. It is not to be used to deliver a list of users
* for example, as there is a field for a password.
*
* @author Nils Christian Ehmke
*/
public class NewUserBean {
private List<Role> roles;
......@@ -20,26 +42,59 @@ public class NewUserBean {
this.password = "";
}
/**
* Delivers the current value of the property {@link NewUserBean#roles}.
*
* @return The current value of the property.
*/
public List<Role> getRoles() {
return this.roles;
}
/**
* Setter for the property {@link NewUserBean#roles}.
*
* @param roles
* The new value for the property.
*/
public void setRoles(final List<Role> roles) {
this.roles = roles;
}
/**
* Delivers the current value of the property {@link NewUserBean#username}.
*
* @return The current value of the property.
*/
public String getUsername() {
return this.username;
}
/**
* Setter for the property {@link NewUserBean#username}.
*
* @param username
* The new value for the property.
*/
public void setUsername(final String username) {
this.username = username;
}
/**
* Delivers the current value of the property {@link NewUserBean#password}.
*
* @return The current value of the property.
*/
public String getPassword() {
return this.password;
}
/**
* Setter for the property {@link NewUserBean#password}.
*
* @param password
* The new value for the property.
*/
public void setPassword(final String password) {
this.password = password;
}
......
......@@ -50,7 +50,7 @@ public final class UserBean implements Serializable {
*
* @return The user name.
*/
public String getUserName() {
public String getUsername() {
final String username;
final Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
......
......@@ -156,6 +156,12 @@ public final class CurrentAnalysisEditorBean {
// No code necessary
}
/**
* Setter for the attribute {@link CurrentAnalysisEditorBean#projectManagerFacade}.
*
* @param projectManagerFacade
* The new value of the attribute.
*/
public void setProjectManagerFacade(final IProjectManagerFacade projectManagerFacade) {
this.projectManagerFacade = projectManagerFacade;
}
......
......@@ -97,6 +97,12 @@ public final class CurrentCockpitEditorBean {
this.createDashboard();
}
/**
* Setter for the property {@link CurrentCockpitEditorBean#projectManagerFacade}.
*
* @param projectManagerFacade
* The new value of the property.
*/
public void setProjectManagerFacade(final IProjectManagerFacade projectManagerFacade) {
this.projectManagerFacade = projectManagerFacade;
}
......
......@@ -80,12 +80,18 @@ public final class CurrentProjectOverviewBean {
this.setProjectName((String) event.getObject());
}
/**
* Setter for the property {@link CurrentProjectOverviewBean#projectsBean}.
*
* @param projectsBean
* The new value for the property.
*/
public void setProjectsBean(final ProjectsBean projectsBean) {
this.projectsBean = projectsBean;
}
/**
* This method should only be called automatically by the JVM to update the projects list.
* This method should only be called automatically by Spring to update the projects list.
*/
protected void initialialize() {
this.updateLists();
......
......@@ -44,24 +44,59 @@ public final class CurrentUserManagementBean {
// No code necessary
}
/**
* Setter for the property {@link CurrentUserManagementBean#userManagerFacade}.
*
* @param userManagerFacade
* The new value for the property.
*/
public void setUserManagerFacade(final IUserManagerFacade userManagerFacade) {
this.userManagerFacade = userManagerFacade;
}
/**
* This method adds the given user to the database and informs about success via the growl component.
*
* @param username
* The name of the new user.
* @param password
* The password of the new user.
* @param roles
* The roles of the new user.
*/
public void addUser(final String username, final String password, final List<Role> roles) {
this.userManagerFacade.addUser(username, password, roles);
// TODO Check that the op was successful before adding the user to our list
this.users.add(new User(username, roles, true));
}
/**
* This method removed the given user from the database and informs about success via the growl component.
*
* @param username
* The name of the user.
*/
public void removeUser(final String username) {
this.userManagerFacade.removeUser(username);
}
/**
* This method edits the given user within the database and informs about success via the growl component.
*
* @param username
* The name of the user.
* @param password
* The (new) password of the user.
* @param roles
* The (new) roles of the user.
*/
public void editUser(final String username, final String password, final Role... roles) {
this.userManagerFacade.editUser(username, password, roles);
}
/**
* This method initializes the bean. <b>Do not call this method manually. It will only be accessed by Spring.</b>
*/
protected void initialialize() {
this.updateList();
}
......
......@@ -61,6 +61,14 @@ public class UserManagerFacadeImpl implements IUserManagerFacade {
}
}
public void destroy() {
try {
this.connection.close();
} catch (final SQLException ex) {
UserManagerFacadeImpl.LOG.error("Could not close database connection.", ex);
}
}
public void setDataSource(final DataSource dataSource) {
this.dataSource = dataSource;
}
......@@ -68,9 +76,11 @@ public class UserManagerFacadeImpl implements IUserManagerFacade {
@Override
@PreAuthorize("hasRole('ROLE_ADMIN')")
public void addUser(final String username, final String password, final List<Role> roles) {
PreparedStatement userCmd = null;
PreparedStatement roleCmd = null;
try {
final PreparedStatement userCmd = this.connection.prepareStatement("INSERT INTO KIEKERUser (name, password, enabled) VALUES (?, ?, True)");
final PreparedStatement roleCmd = this.connection.prepareStatement("INSERT INTO Userroles (name, role) VALUES (?, ?)");
userCmd = this.connection.prepareStatement("INSERT INTO KIEKERUser (name, password, enabled) VALUES (?, ?, True)");
roleCmd = this.connection.prepareStatement("INSERT INTO Userroles (name, role) VALUES (?, ?)");
userCmd.setString(1, username);
userCmd.setString(2, password);
......@@ -83,6 +93,21 @@ public class UserManagerFacadeImpl implements IUserManagerFacade {
}
} catch (final SQLException ex) {
UserManagerFacadeImpl.LOG.error("Could not add user to the database.", ex);
} finally {
if (userCmd != null) {
try {
userCmd.close();
} catch (final SQLException ex) {
UserManagerFacadeImpl.LOG.error("Could not close prepared statement.", ex);
}
}
if (roleCmd != null) {
try {
roleCmd.close();
} catch (final SQLException ex) {
UserManagerFacadeImpl.LOG.error("Could not close prepared statement.", ex);
}
}
}
}
......
......@@ -66,7 +66,7 @@
</map>
</property>
</bean>
<bean init-method="initialize" id="userManagerFacade" class="kieker.webgui.common.impl.UserManagerFacadeImpl">
<bean destroy-method="destroy" init-method="initialize" id="userManagerFacade" class="kieker.webgui.common.impl.UserManagerFacadeImpl">
<property name="dataSource" ref="userDataSource" />
</bean>
......
......@@ -68,7 +68,7 @@
<p:menuitem styleClass="element-with-whitespace" icon="ui-icon-about" value=" #{localizedMessages.about}" onclick="aboutDlg.show()" ajax="true"/>
</p:submenu>
<p:menuitem styleClass="logOutButton element-with-whitespace" icon="ui-icon-logout" value=" #{userBean.userName}" ajax="true" url="#{request.contextPath}/j_spring_security_logout"/>
<p:menuitem styleClass="logOutButton element-with-whitespace" icon="ui-icon-logout" value=" #{userBean.username}" ajax="true" url="#{request.contextPath}/j_spring_security_logout"/>
</p:menubar>
</h:form>
</p:layoutUnit>
......
......@@ -61,7 +61,7 @@
<p:menuitem styleClass="element-with-whitespace" icon="ui-icon-about" value=" #{localizedMessages.about}" onclick="aboutDlg.show()" ajax="true"/>
</p:submenu>
<p:menuitem styleClass="logOutButton element-with-whitespace" icon="ui-icon-logout" value=" #{userBean.userName}" ajax="true" url="#{request.contextPath}/j_spring_security_logout"/>
<p:menuitem styleClass="logOutButton element-with-whitespace" icon="ui-icon-logout" value=" #{userBean.username}" ajax="true" url="#{request.contextPath}/j_spring_security_logout"/>
</p:menubar>
</h:form>
......
......@@ -57,7 +57,7 @@
<p:menuitem styleClass="element-with-whitespace" icon="ui-icon-about" value=" #{localizedMessages.about}" onclick="aboutDlg.show()" ajax="true"/>
</p:submenu>
<p:menuitem styleClass="logOutButton element-with-whitespace" icon="ui-icon-logout" value=" #{userBean.userName}" ajax="true" url="#{request.contextPath}/j_spring_security_logout"/>
<p:menuitem styleClass="logOutButton element-with-whitespace" icon="ui-icon-logout" value=" #{userBean.username}" ajax="true" url="#{request.contextPath}/j_spring_security_logout"/>
</p:menubar>
<ui:insert name="furtherMenuBar"/>
</h:form>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment