Skip to content
This repository was archived by the owner on Nov 24, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ atlassian-ide-plugin.xml
/dist/md5sums
/dist/output.txt
/dist/updates.xml
log.txt
log.txt
.project
.settings/
.classpath
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM maven:3-jdk-8-alpine as builder
VOLUME /root/.m2
COPY . /source
WORKDIR /source
RUN cp -r repository /root/.m2/ && \
mvn org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file -Dfile=repository/nl/tecon/scalahighcharts/highcharts/1.7/highcharts-1.7.jar && \
mvn install -Pprod -Dmaven.test.skip=true -DskipTests

FROM openjdk:8
COPY --from=0 /source/eHour-standalone/target/ehour-1.4.4-SNAPSHOT-standalone/ehour-1.4.4-SNAPSHOT/ /ehour
WORKDIR /ehour
ENV EHOUR_HOME=/ehour
CMD java -cp "lib/*" net.rrm.ehour.EhourServerRunner
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,36 @@ public class EhourSystemConfig {
@Value("${ehour.disableAuth:false}")
private boolean disableAuth = false;

@Value("${ehour.enableOAuth:false}")
private boolean enableOAuth;

@Value("${ehour.oauth2.callbackURI}")
private String oauthCallbackURI;

@Value("${ehour.oauth2.hostURL}")
private String oauthHostURL;

@Value("${ehour.oauth2.name}")
private String oauthName;

@Value("${ehour.oauth2.userAuthorizationUri}")
private String oauthAuthURL;

@Value("${ehour.oauth2.accessTokenUri}")
private String oauthTokenURI;

@Value("${ehour.oauth2.clientID}")
private String oauthClientID;

@Value("${ehour.oauth2.clientSecret}")
private String oauthClientSecuret;

@Value("${ehour.oauth2.scope}")
private String oauthScope;

@Value("${ehour.disableIndividualReport}")
private boolean disableIndividualReport = false;

public EhourSystemConfig() {
}

Expand Down Expand Up @@ -66,4 +96,45 @@ public String getEhourHome() {
public String getTranslationsDir() {
return translationsDir;
}

public boolean isEnableOAuth() {
return enableOAuth;
}

public String getOauthCallbackURI() {
return oauthCallbackURI;
}

public String getOauthHostURL() {
return oauthHostURL;
}

public String getOauthName() {
return oauthName;
}

public String getOauthAuthURL() {
return oauthAuthURL;
}

public String getOauthClientID() {
return oauthClientID;
}

public String getOauthClientSecuret() {
return oauthClientSecuret;
}

public String getOauthScope() {
return oauthScope;
}

public String getOauthTokenURI() {
return oauthTokenURI;
}

public boolean isDisableIndividualReport() {
return disableIndividualReport;
}

}
10 changes: 5 additions & 5 deletions eHour-common/src/main/java/net/rrm/ehour/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ public class User extends DomainObject<Integer, User> {
private Integer userId;

@NotNull
@Column(name = "USERNAME", length = 64)
@Column(name = "USERNAME", length = 1024)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are they so lengthy, oauth standard? The datamodel needs changes as well to accommodate the longer username.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this change is for when login with oauth, I have to set the username to the email as that's the only reliable field that comes with the claims that is readable. It's probably not necessary to set it to something readable, for example use the "subject" claim. I was trying to let the user able to login with their emails as well after logged in with Oauth the first time.

So I think we should remove this change.

private String username;

@NotNull
@Column(name = "PASSWORD", nullable = false, length = 128)
@Column(name = "PASSWORD", nullable = false, length = 1024)
private String password;

@Column(name = "FIRST_NAME", length = 64)
@Column(name = "FIRST_NAME", length = 1024)
private String firstName;

@Column(name = "LAST_NAME", nullable = false, length = 64)
@Column(name = "LAST_NAME", nullable = false, length = 1024)
private String lastName;

@Column(name = "EMAIL", length = 128)
@Column(name = "EMAIL", length = 1024)
private String email;

@Column(name = "ACTIVE")
Expand Down
10 changes: 5 additions & 5 deletions eHour-persistence/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@
<artifactId>eHour-common</artifactId>
</dependency>

<dependency>
<groupId>net.rrm.ehour</groupId>
<artifactId>eHour-common</artifactId>
<type>test-jar</type>
</dependency>
<!--<dependency>-->

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is excluded because somehow if there the docker build won't pass

<!--<groupId>net.rrm.ehour</groupId>-->
<!--<artifactId>eHour-common</artifactId>-->
<!--<type>test-jar</type>-->
<!--</dependency>-->

<dependency>
<groupId>cglib</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@

<query name="Project.findActiveProjectsForCustomers">
FROM Project prj
WHERE prj.customer IN (:customers) AND
WHERE
prj.customer IN (:customers) AND
prj.active is true
ORDER BY prj.name
</query>
Expand All @@ -47,4 +48,4 @@
</query>


</hibernate-mapping>
</hibernate-mapping>
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@
(pa.dateEnd IS NULL or pa.dateEnd > :dateStart)]]>
</query>

</hibernate-mapping>
</hibernate-mapping>
14 changes: 7 additions & 7 deletions eHour-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@
<artifactId>eHour-common</artifactId>
</dependency>

<dependency>
<groupId>net.rrm.ehour</groupId>
<artifactId>eHour-common</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<classifier>tests</classifier>
</dependency>
<!--<dependency>-->

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same reason about the docker build

<!--<groupId>net.rrm.ehour</groupId>-->
<!--<artifactId>eHour-common</artifactId>-->
<!--<version>${project.version}</version>-->
<!--<scope>test</scope>-->
<!--<classifier>tests</classifier>-->
<!--</dependency>-->

<dependency>
<groupId>org.springframework</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ login.login.failed=invalid username or password
login.login.username=username
login.login.password=password
`login.login.submit=Sign in
login.login.slack=Sign in with slack
login.login.rememberMe=remember me on this computer
login.sessionexpired=you have been automatically logged out
login.demoMode=Demo mode, 'save' and 'delete' are disabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %-5p %c - %m%n
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=ehour.log
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{ISO8601} %-5p %c - %m%n
log4j.appender.FILE.layout.ConversionPattern=%d{ISO8601} %-5p %c - %m%n


log4j.logger.org.hibernate.SQL=DEBUG
#log4j.logger.org.hibernate.type=TRACE
26 changes: 13 additions & 13 deletions eHour-wicketweb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@
<artifactId>eHour-common</artifactId>
</dependency>

<dependency>
<groupId>net.rrm.ehour</groupId>
<artifactId>eHour-common</artifactId>
<scope>test</scope>
<classifier>tests</classifier>
</dependency>
<!--<dependency>-->

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same reason about the docker build

<!--<groupId>net.rrm.ehour</groupId>-->
<!--<artifactId>eHour-common</artifactId>-->
<!--<scope>test</scope>-->
<!--<classifier>tests</classifier>-->
<!--</dependency>-->

<dependency>
<groupId>javax.servlet</groupId>
Expand All @@ -78,13 +78,13 @@
<artifactId>eHour-service</artifactId>
</dependency>

<dependency>
<groupId>net.rrm.ehour</groupId>
<artifactId>eHour-service</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<classifier>tests</classifier>
</dependency>
<!--<dependency>-->

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same reason about the docker build

<!--<groupId>net.rrm.ehour</groupId>-->
<!--<artifactId>eHour-service</artifactId>-->
<!--<version>${project.version}</version>-->
<!--<scope>test</scope>-->
<!--<classifier>tests</classifier>-->
<!--</dependency>-->

<dependency>
<groupId>nl.tecon.scalahighcharts</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import net.rrm.ehour.ui.common.session.EhourWebSession;
import net.rrm.ehour.ui.login.page.Login;
import net.rrm.ehour.ui.login.page.Logout;
import net.rrm.ehour.ui.login.page.OAuthCallback;
import net.rrm.ehour.ui.login.page.SessionExpiredPage;
import net.rrm.ehour.ui.manage.assignment.AssignmentManagePage;
import net.rrm.ehour.ui.manage.customer.CustomerManagePage;
Expand Down Expand Up @@ -65,6 +66,7 @@
import org.apache.wicket.request.resource.caching.version.IResourceVersion;
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
import org.apache.wicket.util.time.Duration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.authentication.AuthenticationManager;

import java.util.Comparator;
Expand Down Expand Up @@ -186,6 +188,9 @@ public RuntimeConfigurationType getConfigurationType() {
protected void mountPages() {
mountPage("/login", Login.class);
mountPage("/logout", Logout.class);
if (ehourSystemConfig.isEnableOAuth()){
mountPage(ehourSystemConfig.getOauthCallbackURI(), OAuthCallback.class);
}

mountPage("/admin", MainConfigPage.class);
mountPage("/admin/employee", UserManagePage.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.rrm.ehour.ui.EhourWebApplication;
import net.rrm.ehour.ui.common.authorization.AuthUser;
import net.rrm.ehour.ui.common.util.WebUtils;
import net.rrm.ehour.user.service.UserService;
import net.rrm.ehour.util.DateUtil;
import org.apache.log4j.Logger;
import org.apache.wicket.Session;
Expand All @@ -44,6 +45,7 @@
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;

import java.util.Calendar;
import java.util.Collection;
Expand All @@ -63,9 +65,13 @@ public class EhourWebSession extends AuthenticatedWebSession {
@SpringBean
private AuditService auditService;

@SpringBean
private UserService userService;

private Calendar navCalendar;
private UserSelectedCriteria userSelectedCriteria;
private Boolean hideInactiveSelections = true;
private boolean isOauth = false;

private Optional<AuthUser> impersonatingAuthUser = Optional.absent();

Expand Down Expand Up @@ -157,8 +163,16 @@ public boolean authenticate(String username, String password) {
String u = username == null ? "" : username;
String p = password == null ? "" : password;

UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(u, p);
if (isOauth) {
// TODO: verify
User user = userService.getUser(username);
AuthUser authUser = new AuthUser(user);
PreAuthenticatedAuthenticationToken auth = new PreAuthenticatedAuthenticationToken(authUser, null, user.getUserRoles());
setAuthentication(auth);
return true;
}

Authentication authRequest = new UsernamePasswordAuthenticationToken(u, p);
// Attempt authentication.
try {
AuthenticationManager authenticationManager = ((EhourWebApplication) getApplication()).getAuthenticationManager();
Expand All @@ -169,7 +183,6 @@ public boolean authenticate(String username, String password) {

Authentication authResult = authenticationManager.authenticate(authRequest);
setAuthentication(authResult);

User user = ((AuthUser) authResult.getPrincipal()).getUser();

auditService.doAudit(new Audit()
Expand Down Expand Up @@ -368,4 +381,12 @@ public void setUserSelectedCriteria(UserSelectedCriteria userSelectedCriteria) {
}

private static final long serialVersionUID = 93189812483240412L;

public boolean isOauth() {
return isOauth;
}

public void setOauth(boolean oauth) {
isOauth = oauth;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@
</div>
</div>



<div class="row">
<div class="col-sm-11 login-form submit">
<button class="btn btn-default button" id="loginSubmit">
Expand All @@ -90,6 +88,9 @@
</div>
</div>
</form>
<a class="btn btn-default button" wicket:id="loginOAuth">
Login with slack
</a>
</div>
</div>
</div>
Expand Down
Loading