updated libraries
updated to JUNIT5
This commit is contained in:
@ -1,80 +1,80 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018 Joern Muehlencord <joern at muehlencord.de>.
|
* Copyright 2018 Joern Muehlencord <joern at muehlencord.de>.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.account.web;
|
package de.muehlencord.shared.account.web;
|
||||||
|
|
||||||
import de.muehlencord.shared.account.business.account.boundary.AccountPermissions;
|
import de.muehlencord.shared.account.business.account.boundary.AccountPermissions;
|
||||||
import de.muehlencord.shared.account.business.account.entity.AccountException;
|
import de.muehlencord.shared.account.business.account.entity.AccountException;
|
||||||
import de.muehlencord.shared.account.business.instance.boundary.ApplicationPermissions;
|
import de.muehlencord.shared.account.business.application.control.ApplicationPermissionControl;
|
||||||
import de.muehlencord.shared.account.business.application.control.ApplicationPermissionControl;
|
import de.muehlencord.shared.account.business.application.control.ApplicationRoleControl;
|
||||||
import de.muehlencord.shared.account.business.application.control.ApplicationRoleControl;
|
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
import de.muehlencord.shared.account.business.instance.boundary.ApplicationPermissions;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import javax.enterprise.context.ApplicationScoped;
|
import javax.enterprise.context.ApplicationScoped;
|
||||||
import javax.enterprise.context.Initialized;
|
import javax.enterprise.context.Initialized;
|
||||||
import javax.enterprise.event.Observes;
|
import javax.enterprise.event.Observes;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||||
*/
|
*/
|
||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
public class EnsurePermissionsBean {
|
public class EnsurePermissionsBean {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ApplicationEntity application;
|
ApplicationEntity application;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ApplicationPermissionControl applicationPermissionControl;
|
ApplicationPermissionControl applicationPermissionControl;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ApplicationRoleControl applicationRoleControl;
|
ApplicationRoleControl applicationRoleControl;
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(EnsurePermissionsBean.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(EnsurePermissionsBean.class);
|
||||||
|
|
||||||
public void init(@Observes @Initialized(ApplicationScoped.class) Object init) {
|
public void init(@Observes @Initialized(ApplicationScoped.class) Object init) {
|
||||||
if (LOGGER.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
LOGGER.debug("Ensure all permissions for {} are available", application.getApplicationName());
|
LOGGER.debug("Ensure all permissions for {} are available", application.getApplicationName());
|
||||||
}
|
}
|
||||||
applicationPermissionControl.setupPermissions(Arrays.asList(ApplicationPermissions.values()));
|
applicationPermissionControl.setupPermissions(Arrays.asList(ApplicationPermissions.values()));
|
||||||
applicationPermissionControl.setupPermissions(Arrays.asList(AccountPermissions.values()));
|
applicationPermissionControl.setupPermissions(Arrays.asList(AccountPermissions.values()));
|
||||||
if (LOGGER.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
LOGGER.debug("All permissions added to application", application.getApplicationName());
|
LOGGER.debug("All permissions added to application", application.getApplicationName());
|
||||||
}
|
}
|
||||||
|
|
||||||
// all permissions available - ensure permission is assigned to Admin role
|
// all permissions available - ensure permission is assigned to Admin role
|
||||||
if (LOGGER.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
LOGGER.debug("Ensuring Admin role for {} has all permissions", application.getApplicationName());
|
LOGGER.debug("Ensuring Admin role for {} has all permissions", application.getApplicationName());
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
applicationRoleControl.setupRolePermission(Arrays.asList(ApplicationPermissions.values()), "Admin"); // NOI18N
|
applicationRoleControl.setupRolePermission(Arrays.asList(ApplicationPermissions.values()), "Admin"); // NOI18N
|
||||||
applicationRoleControl.setupRolePermission(Arrays.asList(AccountPermissions.values()), "Admin"); // NOI18N
|
applicationRoleControl.setupRolePermission(Arrays.asList(AccountPermissions.values()), "Admin"); // NOI18N
|
||||||
} catch (AccountException ex) {
|
} catch (AccountException ex) {
|
||||||
LOGGER.error("Error adding permission to Admin role. Reason={}", ex.getMessage());
|
LOGGER.error("Error adding permission to Admin role. Reason={}", ex.getMessage());
|
||||||
if (LOGGER.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
LOGGER.debug("Detailed stacktrace", new Object[]{ex});
|
LOGGER.debug("Detailed stacktrace", new Object[]{ex});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (LOGGER.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
LOGGER.debug("All permissions added to Admin role of {}", application.getApplicationName());
|
LOGGER.debug("All permissions added to Admin role of {}", application.getApplicationName());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,55 +1,55 @@
|
|||||||
package de.muehlencord.shared.account.web.presentation;
|
package de.muehlencord.shared.account.web.presentation;
|
||||||
|
|
||||||
import de.muehlencord.shared.account.business.instance.control.ApplicationController;
|
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
import de.muehlencord.shared.account.business.config.boundary.ConfigService;
|
||||||
import de.muehlencord.shared.account.business.config.boundary.ConfigService;
|
import de.muehlencord.shared.account.business.config.entity.ConfigException;
|
||||||
import de.muehlencord.shared.account.business.config.entity.ConfigException;
|
import de.muehlencord.shared.account.business.instance.control.ApplicationController;
|
||||||
import javax.enterprise.context.ApplicationScoped;
|
import javax.enterprise.context.ApplicationScoped;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO - move to shared-account and remove from all applications and archetype
|
* TODO - move to shared-account and remove from all applications and archetype
|
||||||
*
|
*
|
||||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||||
*/
|
*/
|
||||||
@Named(value = "instanceView")
|
@Named(value = "instanceView")
|
||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
public class InstanceView {
|
public class InstanceView {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(InstanceView.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(InstanceView.class);
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ConfigService configService;
|
ConfigService configService;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
ApplicationController applicationController;
|
ApplicationController applicationController;
|
||||||
|
|
||||||
public boolean isDevelopmentVersion() {
|
public boolean isDevelopmentVersion() {
|
||||||
String instanceName = getInstanceName();
|
String instanceName = getInstanceName();
|
||||||
return !instanceName.equals("Production");
|
return !instanceName.equals("Production");
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getInstanceName() {
|
public String getInstanceName() {
|
||||||
String instanceName;
|
String instanceName;
|
||||||
try {
|
try {
|
||||||
instanceName = configService.getConfigValue("base.instance");
|
instanceName = configService.getConfigValue("base.instance");
|
||||||
} catch (ConfigException ex) {
|
} catch (ConfigException ex) {
|
||||||
if (LOGGER.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
LOGGER.debug("Detailed stacktrace", new Object[]{ex});
|
LOGGER.debug("Detailed stacktrace", new Object[]{ex});
|
||||||
}
|
}
|
||||||
instanceName = "unknown (" + ex.toString() + ")";
|
instanceName = "unknown (" + ex.toString() + ")";
|
||||||
}
|
}
|
||||||
if (instanceName == null) {
|
if (instanceName == null) {
|
||||||
return "unknown";
|
return "unknown";
|
||||||
} else {
|
} else {
|
||||||
return instanceName;
|
return instanceName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApplicationEntity getInstanceApplication() {
|
public ApplicationEntity getInstanceApplication() {
|
||||||
return applicationController.getApplication();
|
return applicationController.getApplication();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,10 @@
|
|||||||
package de.muehlencord.shared.account.web.presentation;
|
package de.muehlencord.shared.account.web.presentation;
|
||||||
|
|
||||||
|
import de.muehlencord.shared.account.business.application.control.ApplicationRoleControl;
|
||||||
|
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||||
|
import de.muehlencord.shared.account.business.application.entity.ApplicationRoleEntity;
|
||||||
|
import de.muehlencord.shared.account.util.AccountPU;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import javax.faces.application.FacesMessage;
|
import javax.faces.application.FacesMessage;
|
||||||
import javax.faces.component.UIComponent;
|
import javax.faces.component.UIComponent;
|
||||||
import javax.faces.component.UIInput;
|
import javax.faces.component.UIInput;
|
||||||
@ -12,11 +15,6 @@ import javax.faces.validator.ValidatorException;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
|
||||||
import de.muehlencord.shared.account.business.application.control.ApplicationRoleControl;
|
|
||||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
|
||||||
import de.muehlencord.shared.account.business.application.entity.ApplicationRoleEntity;
|
|
||||||
import de.muehlencord.shared.account.util.AccountPU;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
package de.muehlencord.shared.account.web.presentation;
|
package de.muehlencord.shared.account.web.presentation;
|
||||||
|
|
||||||
|
import de.muehlencord.shared.account.business.application.control.ApplicationControl;
|
||||||
|
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import javax.faces.application.FacesMessage;
|
import javax.faces.application.FacesMessage;
|
||||||
import javax.faces.component.UIComponent;
|
import javax.faces.component.UIComponent;
|
||||||
import javax.faces.component.UIInput;
|
import javax.faces.component.UIInput;
|
||||||
@ -10,13 +11,9 @@ import javax.faces.validator.FacesValidator;
|
|||||||
import javax.faces.validator.Validator;
|
import javax.faces.validator.Validator;
|
||||||
import javax.faces.validator.ValidatorException;
|
import javax.faces.validator.ValidatorException;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import de.muehlencord.shared.account.business.application.control.ApplicationControl;
|
|
||||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
package de.muehlencord.shared.account.web.presentation;
|
package de.muehlencord.shared.account.web.presentation;
|
||||||
|
|
||||||
import de.muehlencord.shared.account.business.application.entity.ApplicationPermissionEntity;
|
|
||||||
import de.muehlencord.shared.account.business.application.control.ApplicationPermissionControl;
|
import de.muehlencord.shared.account.business.application.control.ApplicationPermissionControl;
|
||||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||||
|
import de.muehlencord.shared.account.business.application.entity.ApplicationPermissionEntity;
|
||||||
import de.muehlencord.shared.account.util.AccountPU;
|
import de.muehlencord.shared.account.util.AccountPU;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import javax.faces.application.FacesMessage;
|
import javax.faces.application.FacesMessage;
|
||||||
|
|||||||
@ -54,15 +54,20 @@
|
|||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-core</artifactId>
|
<artifactId>mockito-core</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-junit-jupiter</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-log4j12</artifactId>
|
<artifactId>slf4j-log4j12</artifactId>
|
||||||
|
|||||||
@ -163,8 +163,9 @@ public class ApiKeyService implements Serializable {
|
|||||||
@Transactional
|
@Transactional
|
||||||
@Lock(LockType.WRITE)
|
@Lock(LockType.WRITE)
|
||||||
public ApiKeyObject createNewApiKey(String userName, short expirationInMinutes) throws ApiKeyException {
|
public ApiKeyObject createNewApiKey(String userName, short expirationInMinutes) throws ApiKeyException {
|
||||||
if ((password == null || issuer == null) || (userName == null)) {
|
if (password == null || issuer == null || userName == null) {
|
||||||
LOGGER.error("password, issuer or username not set in, please validate configuration");
|
String hint = "password, issuer or username not set in, please validate configuration";
|
||||||
|
throw new ApiKeyException(hint);
|
||||||
}
|
}
|
||||||
Date now = DateUtil.getCurrentTimeInUTC();
|
Date now = DateUtil.getCurrentTimeInUTC();
|
||||||
ZonedDateTime issuedOn = ZonedDateTime.ofInstant(now.toInstant(), ZoneId.of("UTC"));
|
ZonedDateTime issuedOn = ZonedDateTime.ofInstant(now.toInstant(), ZoneId.of("UTC"));
|
||||||
|
|||||||
@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.account.business.config.boundary;
|
package de.muehlencord.shared.account.business.config.boundary;
|
||||||
|
|
||||||
import de.muehlencord.shared.db.ControllerException;
|
|
||||||
import de.muehlencord.shared.account.business.account.entity.Account;
|
import de.muehlencord.shared.account.business.account.entity.Account;
|
||||||
import de.muehlencord.shared.account.business.account.entity.AccountEntity;
|
import de.muehlencord.shared.account.business.account.entity.AccountEntity;
|
||||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||||
@ -23,6 +22,7 @@ import de.muehlencord.shared.account.business.config.entity.ConfigEntity;
|
|||||||
import de.muehlencord.shared.account.business.config.entity.ConfigEntityPK;
|
import de.muehlencord.shared.account.business.config.entity.ConfigEntityPK;
|
||||||
import de.muehlencord.shared.account.business.config.entity.ConfigException;
|
import de.muehlencord.shared.account.business.config.entity.ConfigException;
|
||||||
import de.muehlencord.shared.account.util.AccountPU;
|
import de.muehlencord.shared.account.util.AccountPU;
|
||||||
|
import de.muehlencord.shared.db.ControllerException;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -37,6 +37,7 @@ import javax.inject.Inject;
|
|||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.Query;
|
import javax.persistence.Query;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -121,7 +122,7 @@ public class ConfigService implements Serializable {
|
|||||||
|
|
||||||
// if config value is not found null has been returned
|
// if config value is not found null has been returned
|
||||||
// in this case the value to return is the defaultValue
|
// in this case the value to return is the defaultValue
|
||||||
if (configValue == null) {
|
if (StringUtils.isEmpty(configValue)) {
|
||||||
configValue = defaultValue;
|
configValue = defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -15,10 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.account.business.instance.boundary;
|
package de.muehlencord.shared.account.business.instance.boundary;
|
||||||
|
|
||||||
import de.muehlencord.shared.db.ControllerException;
|
|
||||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||||
import de.muehlencord.shared.account.business.config.boundary.ConfigService;
|
import de.muehlencord.shared.account.business.config.boundary.ConfigService;
|
||||||
import de.muehlencord.shared.account.business.config.entity.ConfigException;
|
import de.muehlencord.shared.account.business.config.entity.ConfigException;
|
||||||
|
import de.muehlencord.shared.db.ControllerException;
|
||||||
import javax.annotation.PreDestroy;
|
import javax.annotation.PreDestroy;
|
||||||
import javax.enterprise.context.ApplicationScoped;
|
import javax.enterprise.context.ApplicationScoped;
|
||||||
import javax.enterprise.context.Initialized;
|
import javax.enterprise.context.Initialized;
|
||||||
|
|||||||
@ -1,202 +1,201 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018 joern.muehlencord.
|
* Copyright 2018 joern.muehlencord.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.account.presentation;
|
package de.muehlencord.shared.account.presentation;
|
||||||
|
|
||||||
import de.muehlencord.shared.account.business.account.control.AccountControl;
|
import de.muehlencord.shared.account.business.account.control.AccountControl;
|
||||||
import de.muehlencord.shared.account.business.account.entity.AccountEntity;
|
import de.muehlencord.shared.account.business.account.entity.AccountEntity;
|
||||||
import de.muehlencord.shared.jeeutil.FacesUtil;
|
import de.muehlencord.shared.jeeutil.FacesUtil;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import javax.ejb.EJB;
|
import javax.ejb.EJB;
|
||||||
import javax.faces.context.ExternalContext;
|
import javax.faces.context.ExternalContext;
|
||||||
import javax.faces.context.FacesContext;
|
import javax.faces.context.FacesContext;
|
||||||
import javax.faces.view.ViewScoped;
|
import javax.faces.view.ViewScoped;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
import javax.servlet.ServletRequest;
|
import javax.servlet.ServletResponse;
|
||||||
import javax.servlet.ServletResponse;
|
import org.apache.shiro.SecurityUtils;
|
||||||
import org.apache.shiro.subject.Subject;
|
import org.apache.shiro.authc.AuthenticationException;
|
||||||
import org.apache.shiro.SecurityUtils;
|
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||||
import org.apache.shiro.authc.AuthenticationException;
|
import org.apache.shiro.subject.Subject;
|
||||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
import org.apache.shiro.web.util.WebUtils;
|
||||||
import org.apache.shiro.web.util.WebUtils;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
/**
|
||||||
/**
|
*
|
||||||
*
|
* @author joern.muehlencord
|
||||||
* @author joern.muehlencord
|
*/
|
||||||
*/
|
@Named(value = "loginView")
|
||||||
@Named(value = "loginView")
|
@ViewScoped
|
||||||
@ViewScoped
|
public class LoginView implements Serializable {
|
||||||
public class LoginView implements Serializable {
|
|
||||||
|
private static final long serialVersionUID = -1164860380769648432L;
|
||||||
private static final long serialVersionUID = -1164860380769648432L;
|
|
||||||
|
@EJB
|
||||||
@EJB
|
private AccountControl accountService;
|
||||||
private AccountControl accountService;
|
|
||||||
|
private String username = null;
|
||||||
private String username = null;
|
private String password = null;
|
||||||
private String password = null;
|
private boolean rememberMe = false;
|
||||||
private boolean rememberMe = false;
|
|
||||||
|
private String resetPasswordToken = null;
|
||||||
private String resetPasswordToken = null;
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(LoginView.class.getName());
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(LoginView.class.getName());
|
|
||||||
|
public void authenticate() {
|
||||||
public void authenticate() {
|
|
||||||
|
// Example using most common scenario of username/password pair:
|
||||||
// Example using most common scenario of username/password pair:
|
UsernamePasswordToken token = new UsernamePasswordToken(getUsername(), getPassword());
|
||||||
UsernamePasswordToken token = new UsernamePasswordToken(getUsername(), getPassword());
|
|
||||||
|
// "Remember Me" built-in:
|
||||||
// "Remember Me" built-in:
|
token.setRememberMe(rememberMe);
|
||||||
token.setRememberMe(rememberMe);
|
Subject currentUser = SecurityUtils.getSubject();
|
||||||
Subject currentUser = SecurityUtils.getSubject();
|
LOGGER.info("Trying to login user {}", username);
|
||||||
LOGGER.info("Trying to login user {}", username);
|
|
||||||
|
try {
|
||||||
try {
|
currentUser.login(token);
|
||||||
currentUser.login(token);
|
LOGGER.info("User {} logged in", username);
|
||||||
LOGGER.info("User {} logged in", username);
|
// user logged in, update account entity
|
||||||
// user logged in, update account entity
|
AccountEntity account = accountService.getAccountEntity(username, true);
|
||||||
AccountEntity account = accountService.getAccountEntity(username, true);
|
accountService.updateLogin(account);
|
||||||
accountService.updateLogin(account);
|
|
||||||
|
// redirect to home
|
||||||
// redirect to home
|
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
|
||||||
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
|
ServletResponse servletResponse = (ServletResponse) ec.getResponse();
|
||||||
ServletResponse servletResponse = (ServletResponse) ec.getResponse();
|
String fallbackUrl = "/web/index.xhtml"; // TODO make configurable
|
||||||
String fallbackUrl = "/web/index.xhtml"; // TODO make configurable
|
// ec.redirect(url);
|
||||||
// ec.redirect(url);
|
if (LOGGER.isTraceEnabled()) {
|
||||||
if (LOGGER.isTraceEnabled()) {
|
LOGGER.trace("redirecting to {}, fallbackUrl={}", servletResponse.toString(), fallbackUrl);
|
||||||
LOGGER.trace("redirecting to {}, fallbackUrl={}", servletResponse.toString(), fallbackUrl);
|
}
|
||||||
}
|
|
||||||
|
WebUtils.redirectToSavedRequest((ServletRequest) ec.getRequest(), servletResponse, fallbackUrl);
|
||||||
WebUtils.redirectToSavedRequest((ServletRequest) ec.getRequest(), servletResponse, fallbackUrl);
|
} catch (IOException | AuthenticationException ex) {
|
||||||
} catch (IOException | AuthenticationException ex) {
|
// Could catch a subclass of AuthenticationException if you like
|
||||||
// Could catch a subclass of AuthenticationException if you like
|
String hint = "Error while authenticating user " + username;
|
||||||
String hint = "Error while authenticating user " + username;
|
if (LOGGER.isDebugEnabled()) {
|
||||||
if (LOGGER.isDebugEnabled()) {
|
LOGGER.debug(hint, ex);
|
||||||
LOGGER.debug(hint, ex);
|
}
|
||||||
}
|
|
||||||
|
if (ex.getMessage() != null) {
|
||||||
if (ex.getMessage() != null) {
|
hint += "Reason: " + ex.getMessage();
|
||||||
hint += "Reason: " + ex.getMessage();
|
} else {
|
||||||
} else {
|
hint += "Reason: " + ex.toString();
|
||||||
hint += "Reason: " + ex.toString();
|
}
|
||||||
}
|
if ((ex.getCause() != null) && (ex.getCause().getMessage() != null)) {
|
||||||
if ((ex.getCause() != null) && (ex.getCause().getMessage() != null)) {
|
hint += "Rootcause: " + ex.getMessage();
|
||||||
hint += "Rootcause: " + ex.getMessage();
|
|
||||||
|
LOGGER.error(hint);
|
||||||
LOGGER.error(hint);
|
}
|
||||||
}
|
FacesUtil.addGlobalErrorMessage("Login failed", hint);
|
||||||
FacesUtil.addGlobalErrorMessage("Login failed", hint);
|
|
||||||
|
AccountEntity account = accountService.getAccountEntity(username, false);
|
||||||
AccountEntity account = accountService.getAccountEntity(username, false);
|
if (account != null) {
|
||||||
if (account != null) {
|
accountService.addLoginError(account);
|
||||||
accountService.addLoginError(account);
|
}
|
||||||
}
|
} finally {
|
||||||
} finally {
|
token.clear();
|
||||||
token.clear();
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public void logout() {
|
||||||
public void logout() {
|
Subject currentUser = SecurityUtils.getSubject();
|
||||||
Subject currentUser = SecurityUtils.getSubject();
|
try {
|
||||||
try {
|
currentUser.logout();
|
||||||
currentUser.logout();
|
|
||||||
|
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
|
||||||
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
|
|
||||||
|
// ensure faces session is invalidated so beans are destroyed
|
||||||
// ensure faces session is invalidated so beans are destroyed
|
ec.invalidateSession();
|
||||||
ec.invalidateSession();
|
|
||||||
|
// check if redirect shall be executed
|
||||||
// check if redirect shall be executed
|
// default setting is yes to /login.xhtml
|
||||||
// default setting is yes to /login.xhtml
|
// can be overwritten using parameters
|
||||||
// can be overwritten using parameters
|
// de.muehlencord.shared.account.loginview.executeredirect boolean true/false
|
||||||
// de.muehlencord.shared.account.loginview.executeredirect boolean true/false
|
// de.muehlencord.shared.account.loginview.redirecttarget path to redirect to (without external context, will be added automatically)
|
||||||
// de.muehlencord.shared.account.loginview.redirecttarget path to redirect to (without external context, will be added automatically)
|
String executeRedirectString = ec.getInitParameter("de.muehlencord.shared.account.loginview.executeredirect");
|
||||||
String executeRedirectString = ec.getInitParameter("de.muehlencord.shared.account.loginview.executeredirect");
|
boolean executeRedirect = true;
|
||||||
boolean executeRedirect = true;
|
if (executeRedirectString != null) {
|
||||||
if (executeRedirectString != null) {
|
executeRedirect = Boolean.parseBoolean(executeRedirectString);
|
||||||
executeRedirect = Boolean.parseBoolean(executeRedirectString);
|
}
|
||||||
}
|
|
||||||
|
String redirectTarget = ec.getInitParameter("de.muehlencord.shared.account.loginview.redirecttarget");
|
||||||
String redirectTarget = ec.getInitParameter("de.muehlencord.shared.account.loginview.redirecttarget");
|
if ((redirectTarget == null) || (redirectTarget.equals(""))) {
|
||||||
if ((redirectTarget == null) || (redirectTarget.equals(""))) {
|
redirectTarget = "/login.xhtml";
|
||||||
redirectTarget = "/login.xhtml";
|
}
|
||||||
}
|
|
||||||
|
if (executeRedirect) {
|
||||||
if (executeRedirect) {
|
String url = ec.getRequestContextPath() + redirectTarget;
|
||||||
String url = ec.getRequestContextPath() + redirectTarget;
|
ec.redirect(url);
|
||||||
ec.redirect(url);
|
}
|
||||||
}
|
|
||||||
|
} catch (Exception e) {
|
||||||
} catch (Exception e) {
|
LOGGER.warn(e.toString());
|
||||||
LOGGER.warn(e.toString());
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public String executePasswordReset() {
|
||||||
public String executePasswordReset() {
|
boolean passwordResetted = accountService.resetPassword(username, password, resetPasswordToken);
|
||||||
boolean passwordResetted = accountService.resetPassword(username, password, resetPasswordToken);
|
if (passwordResetted) {
|
||||||
if (passwordResetted) {
|
// TODO add email notification on updated user account
|
||||||
// TODO add email notification on updated user account
|
FacesUtil.addGlobalInfoMessage("Password resetted", null);
|
||||||
FacesUtil.addGlobalInfoMessage("Password resetted", null);
|
return login();
|
||||||
return login();
|
} else {
|
||||||
} else {
|
// TODO add email notificaton on failed password reset
|
||||||
// TODO add email notificaton on failed password reset
|
FacesUtil.addGlobalErrorMessage("Password reset failed", null);
|
||||||
FacesUtil.addGlobalErrorMessage("Password reset failed", null);
|
return login();
|
||||||
return login();
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/* **** naviation rules **** */
|
||||||
/* **** naviation rules **** */
|
public String login() {
|
||||||
public String login() {
|
return "/login.xhtml"; // TODO make configurable
|
||||||
return "/login.xhtml"; // TODO make configurable
|
}
|
||||||
}
|
|
||||||
|
/* *** getter / setter */
|
||||||
/* *** getter / setter */
|
public String getUsername() {
|
||||||
public String getUsername() {
|
return username;
|
||||||
return username;
|
}
|
||||||
}
|
|
||||||
|
public void setUsername(String un) {
|
||||||
public void setUsername(String un) {
|
this.username = un;
|
||||||
this.username = un;
|
}
|
||||||
}
|
|
||||||
|
public String getPassword() {
|
||||||
public String getPassword() {
|
return password;
|
||||||
return password;
|
}
|
||||||
}
|
|
||||||
|
public void setPassword(String pw) {
|
||||||
public void setPassword(String pw) {
|
this.password = pw;
|
||||||
this.password = pw;
|
}
|
||||||
}
|
|
||||||
|
public boolean isRememberMe() {
|
||||||
public boolean isRememberMe() {
|
return rememberMe;
|
||||||
return rememberMe;
|
}
|
||||||
}
|
|
||||||
|
public void setRememberMe(boolean rememberMe) {
|
||||||
public void setRememberMe(boolean rememberMe) {
|
this.rememberMe = rememberMe;
|
||||||
this.rememberMe = rememberMe;
|
}
|
||||||
}
|
|
||||||
|
public String getResetPasswordToken() {
|
||||||
public String getResetPasswordToken() {
|
return resetPasswordToken;
|
||||||
return resetPasswordToken;
|
}
|
||||||
}
|
|
||||||
|
public void setResetPasswordToken(String resetPasswordToken) {
|
||||||
public void setResetPasswordToken(String resetPasswordToken) {
|
this.resetPasswordToken = resetPasswordToken;
|
||||||
this.resetPasswordToken = resetPasswordToken;
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|||||||
@ -1,172 +1,169 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018 joern.muehlencord.
|
* Copyright 2018 joern.muehlencord.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.account.shiro.filter;
|
package de.muehlencord.shared.account.shiro.filter;
|
||||||
|
|
||||||
import java.io.IOException;
|
import de.muehlencord.shared.account.business.account.boundary.ApiKeyService;
|
||||||
import java.io.StringReader;
|
import de.muehlencord.shared.account.business.account.entity.JWTObject;
|
||||||
|
import de.muehlencord.shared.account.shiro.token.JWTAuthenticationToken;
|
||||||
import javax.json.Json;
|
import de.muehlencord.shared.account.util.AccountSecurityException;
|
||||||
import javax.json.JsonObject;
|
import de.muehlencord.shared.jeeutil.restexfw.APIException;
|
||||||
import javax.json.JsonReader;
|
import java.io.IOException;
|
||||||
import javax.naming.Context;
|
import java.io.StringReader;
|
||||||
import javax.naming.InitialContext;
|
import javax.json.Json;
|
||||||
import javax.naming.NamingException;
|
import javax.json.JsonObject;
|
||||||
import javax.servlet.ServletException;
|
import javax.json.JsonReader;
|
||||||
import javax.servlet.ServletRequest;
|
import javax.naming.Context;
|
||||||
import javax.servlet.ServletResponse;
|
import javax.naming.InitialContext;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.naming.NamingException;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
import org.apache.commons.io.IOUtils;
|
import javax.servlet.ServletResponse;
|
||||||
import org.apache.shiro.authc.AuthenticationToken;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import org.apache.shiro.web.filter.authc.AuthenticatingFilter;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.shiro.web.util.WebUtils;
|
import org.apache.shiro.authc.AuthenticationToken;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||||
|
import org.apache.shiro.web.filter.authc.AuthenticatingFilter;
|
||||||
import de.muehlencord.shared.account.business.account.boundary.ApiKeyService;
|
import org.apache.shiro.web.util.WebUtils;
|
||||||
import de.muehlencord.shared.account.business.account.entity.JWTObject;
|
import org.slf4j.LoggerFactory;
|
||||||
import de.muehlencord.shared.account.shiro.token.JWTAuthenticationToken;
|
|
||||||
import de.muehlencord.shared.account.util.AccountSecurityException;
|
/**
|
||||||
import de.muehlencord.shared.jeeutil.restexfw.APIException;
|
*
|
||||||
|
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||||
/**
|
*/
|
||||||
*
|
public final class JWTAuthenticationFilter extends AuthenticatingFilter {
|
||||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
|
||||||
*/
|
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(JWTAuthenticationFilter.class);
|
||||||
public final class JWTAuthenticationFilter extends AuthenticatingFilter {
|
protected static final String AUTHORIZATION_HEADER = "Authorization"; // NOI18N
|
||||||
|
protected static final String USERNAME = "username"; // NOI18N
|
||||||
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(JWTAuthenticationFilter.class);
|
protected static final String PASSWORD = "password"; // NOI18N
|
||||||
protected static final String AUTHORIZATION_HEADER = "Authorization"; // NOI18N
|
|
||||||
protected static final String USERNAME = "username"; // NOI18N
|
private final ApiKeyService apiKeyService = lookupApiKeyServiceBean();
|
||||||
protected static final String PASSWORD = "password"; // NOI18N
|
|
||||||
|
public JWTAuthenticationFilter() {
|
||||||
private final ApiKeyService apiKeyService = lookupApiKeyServiceBean();
|
// FIXME - logging in via JWTAuthenticationFilter does not yet work. Need to set login to anonymous to execute login in rest service
|
||||||
|
setLoginUrl("/rest/account/login");
|
||||||
public JWTAuthenticationFilter() {
|
}
|
||||||
// FIXME - logging in via JWTAuthenticationFilter does not yet work. Need to set login to anonymous to execute login in rest service
|
|
||||||
setLoginUrl("/rest/account/login");
|
@Override
|
||||||
}
|
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
|
||||||
|
boolean loggedIn = false;
|
||||||
@Override
|
|
||||||
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
|
if (isLoginRequest(request, response) || isLoggedAttempt(request, response)) {
|
||||||
boolean loggedIn = false;
|
loggedIn = executeLogin(request, response);
|
||||||
|
}
|
||||||
if (isLoginRequest(request, response) || isLoggedAttempt(request, response)) {
|
|
||||||
loggedIn = executeLogin(request, response);
|
if (!loggedIn) {
|
||||||
}
|
HttpServletResponse httpResponse = WebUtils.toHttp(response);
|
||||||
|
httpResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||||
if (!loggedIn) {
|
}
|
||||||
HttpServletResponse httpResponse = WebUtils.toHttp(response);
|
|
||||||
httpResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
return loggedIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
return loggedIn;
|
@Override
|
||||||
}
|
protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) throws Exception {
|
||||||
|
if (isLoginRequest(request, response)) {
|
||||||
@Override
|
String json = IOUtils.toString(request.getInputStream(), "UTF-8"); // FIXME - check charset in request
|
||||||
protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) throws Exception {
|
|
||||||
if (isLoginRequest(request, response)) {
|
if (json != null && !json.isEmpty()) {
|
||||||
String json = IOUtils.toString(request.getInputStream(), "UTF-8"); // FIXME - check charset in request
|
try (JsonReader jr = Json.createReader(new StringReader(json))) {
|
||||||
|
JsonObject object = jr.readObject();
|
||||||
if (json != null && !json.isEmpty()) {
|
String username = object.getString(USERNAME);
|
||||||
try (JsonReader jr = Json.createReader(new StringReader(json))) {
|
String password = object.getString(PASSWORD);
|
||||||
JsonObject object = jr.readObject();
|
return new UsernamePasswordToken(username, password);
|
||||||
String username = object.getString(USERNAME);
|
}
|
||||||
String password = object.getString(PASSWORD);
|
|
||||||
return new UsernamePasswordToken(username, password);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
if (isLoggedAttempt(request, response)) {
|
||||||
}
|
String jwtToken = getAuthzHeader(request);
|
||||||
|
if (LOGGER.isTraceEnabled()) {
|
||||||
if (isLoggedAttempt(request, response)) {
|
LOGGER.trace("found jwtToke in header = {}", jwtToken);
|
||||||
String jwtToken = getAuthzHeader(request);
|
}
|
||||||
if (LOGGER.isTraceEnabled()) {
|
|
||||||
LOGGER.trace("found jwtToke in header = {}", jwtToken);
|
if (jwtToken != null) {
|
||||||
}
|
JWTObject jwtObject = apiKeyService.getJWTObject(jwtToken);
|
||||||
|
return new JWTAuthenticationToken(jwtObject.getUserName(), jwtToken);
|
||||||
if (jwtToken != null) {
|
}
|
||||||
JWTObject jwtObject = apiKeyService.getJWTObject(jwtToken);
|
}
|
||||||
return new JWTAuthenticationToken(jwtObject.getUserName(), jwtToken);
|
|
||||||
}
|
return new UsernamePasswordToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new UsernamePasswordToken();
|
private boolean isLoggedAttempt(ServletRequest request, ServletResponse response) {
|
||||||
}
|
String authzHeader = getAuthzHeader(request);
|
||||||
|
return authzHeader != null;
|
||||||
private boolean isLoggedAttempt(ServletRequest request, ServletResponse response) {
|
}
|
||||||
String authzHeader = getAuthzHeader(request);
|
|
||||||
return authzHeader != null;
|
private String getAuthzHeader(ServletRequest request) {
|
||||||
}
|
HttpServletRequest httpRequest = WebUtils.toHttp(request);
|
||||||
|
return httpRequest.getHeader(AUTHORIZATION_HEADER);
|
||||||
private String getAuthzHeader(ServletRequest request) {
|
}
|
||||||
HttpServletRequest httpRequest = WebUtils.toHttp(request);
|
|
||||||
return httpRequest.getHeader(AUTHORIZATION_HEADER);
|
|
||||||
}
|
/**
|
||||||
|
* Overwrite cleanup to ensure no exception is thrown if an
|
||||||
|
* AccountSecurityException / APIException is raised during login. As long
|
||||||
/**
|
* as the user is not logged in JERSEYs ExceptionMapper and intercepor
|
||||||
* Overwrite cleanup to ensure no exception is thrown if an
|
* classes are overruled by Shiro.
|
||||||
* AccountSecurityException / APIException is raised during login. As long
|
*
|
||||||
* as the user is not logged in JERSEYs ExceptionMapper and intercepor
|
* @param request the incoming request
|
||||||
* classes are overruled by Shiro.
|
* @param response the response to return
|
||||||
*
|
* @param existing the raised exception
|
||||||
* @param request the incoming request
|
* @throws ServletException may be thrown by AuthenticatingFilter.cleanup if
|
||||||
* @param response the response to return
|
* existing is not a AccountSecurityException
|
||||||
* @param existing the raised exception
|
* @throws IOException may be thrown by AuthenticatingFilter.cleanup if
|
||||||
* @throws ServletException may be thrown by AuthenticatingFilter.cleanup if
|
* existing is not a AccountSecurityException
|
||||||
* existing is not a AccountSecurityException
|
*/
|
||||||
* @throws IOException may be thrown by AuthenticatingFilter.cleanup if
|
@Override
|
||||||
* existing is not a AccountSecurityException
|
protected void cleanup(ServletRequest request, ServletResponse response, Exception existing) throws ServletException, IOException {
|
||||||
*/
|
if ((existing != null) && (existing.getClass().isAssignableFrom(AccountSecurityException.class))) {
|
||||||
@Override
|
HttpServletResponse httpResponse = WebUtils.toHttp(response);
|
||||||
protected void cleanup(ServletRequest request, ServletResponse response, Exception existing) throws ServletException, IOException {
|
httpResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||||
if ((existing != null) && (existing.getClass().isAssignableFrom(AccountSecurityException.class))) {
|
} else if ((existing != null) && (existing.getClass().isAssignableFrom(APIException.class))) {
|
||||||
HttpServletResponse httpResponse = WebUtils.toHttp(response);
|
APIException apiException = (APIException) existing;
|
||||||
httpResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
|
||||||
} else if ((existing != null) && (existing.getClass().isAssignableFrom(APIException.class))) {
|
HttpServletResponse httpResponse = WebUtils.toHttp(response);
|
||||||
APIException apiException = (APIException) existing;
|
httpResponse.setStatus(apiException.getHttpResponse().getStatus());
|
||||||
|
httpResponse.addHeader(APIException.HTTP_HEADER_X_ERROR, apiException.getHttpResponse().getHeaderString(APIException.HTTP_HEADER_X_ERROR));
|
||||||
HttpServletResponse httpResponse = WebUtils.toHttp(response);
|
httpResponse.addHeader(APIException.HTTP_HEADER_X_ERROR_CODE, apiException.getHttpResponse().getHeaderString(APIException.HTTP_HEADER_X_ERROR_CODE));
|
||||||
httpResponse.setStatus(apiException.getHttpResponse().getStatus());
|
|
||||||
httpResponse.addHeader(APIException.HTTP_HEADER_X_ERROR, apiException.getHttpResponse().getHeaderString(APIException.HTTP_HEADER_X_ERROR));
|
if (apiException.getHttpResponse().getHeaderString(APIException.HTTP_HEADER_X_ROOT_CAUSE) != null) {
|
||||||
httpResponse.addHeader(APIException.HTTP_HEADER_X_ERROR_CODE, apiException.getHttpResponse().getHeaderString(APIException.HTTP_HEADER_X_ERROR_CODE));
|
httpResponse.addHeader(APIException.HTTP_HEADER_X_ROOT_CAUSE, apiException.getHttpResponse().getHeaderString(APIException.HTTP_HEADER_X_ROOT_CAUSE));
|
||||||
|
}
|
||||||
if (apiException.getHttpResponse().getHeaderString(APIException.HTTP_HEADER_X_ROOT_CAUSE) != null) {
|
} else {
|
||||||
httpResponse.addHeader(APIException.HTTP_HEADER_X_ROOT_CAUSE, apiException.getHttpResponse().getHeaderString(APIException.HTTP_HEADER_X_ROOT_CAUSE));
|
super.cleanup(request, response, existing);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
super.cleanup(request, response, existing);
|
|
||||||
}
|
// TODO - can this be injected?
|
||||||
}
|
private ApiKeyService lookupApiKeyServiceBean() {
|
||||||
|
try {
|
||||||
// TODO - can this be injected?
|
Context c = new InitialContext();
|
||||||
private ApiKeyService lookupApiKeyServiceBean() {
|
return (ApiKeyService) c.lookup("java:module/ApiKeyService"); // NOI18N
|
||||||
try {
|
} catch (NamingException ex) {
|
||||||
Context c = new InitialContext();
|
if (LOGGER.isDebugEnabled()) {
|
||||||
return (ApiKeyService) c.lookup("java:module/ApiKeyService"); // NOI18N
|
LOGGER.debug(ex.toString(), ex);
|
||||||
} catch (NamingException ex) {
|
} else {
|
||||||
if (LOGGER.isDebugEnabled()) {
|
LOGGER.error(ex.toString());
|
||||||
LOGGER.debug(ex.toString(), ex);
|
}
|
||||||
} else {
|
throw new RuntimeException(ex);
|
||||||
LOGGER.error(ex.toString());
|
}
|
||||||
}
|
}
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,21 +1,98 @@
|
|||||||
package de.muehlencord.shared.account.business.account.boundary;
|
package de.muehlencord.shared.account.business.account.boundary;
|
||||||
|
|
||||||
import org.junit.Test;
|
import de.muehlencord.shared.account.business.account.control.AccountControl;
|
||||||
|
import de.muehlencord.shared.account.business.account.entity.AccountEntity;
|
||||||
|
import de.muehlencord.shared.account.business.application.entity.ApplicationRoleEntity;
|
||||||
|
import de.muehlencord.shared.account.business.config.boundary.ConfigService;
|
||||||
|
import de.muehlencord.shared.account.business.config.entity.ConfigException;
|
||||||
|
import de.muehlencord.shared.account.dao.ApiKeyObject;
|
||||||
|
import de.muehlencord.shared.db.ControllerException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import javax.persistence.EntityManager;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
import org.mockito.invocation.InvocationOnMock;
|
||||||
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
import org.mockito.stubbing.Answer;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||||
*/
|
*/
|
||||||
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class ApiKeyServiceTest {
|
public class ApiKeyServiceTest {
|
||||||
|
|
||||||
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ApiKeyServiceTest.class);
|
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ApiKeyServiceTest.class);
|
||||||
|
|
||||||
|
ApiKeyService apiKeyService;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setup() {
|
||||||
|
apiKeyService = new ApiKeyService();
|
||||||
|
apiKeyService.configService = mock(ConfigService.class);
|
||||||
|
try {
|
||||||
|
when(apiKeyService.configService.getConfigValue(anyString(), anyString(), anyBoolean())).thenReturn("120");
|
||||||
|
when(apiKeyService.configService.getConfigValue(anyString())).thenAnswer(new Answer<String>() {
|
||||||
|
@Override
|
||||||
|
public String answer(InvocationOnMock invocation) throws Throwable {
|
||||||
|
Object[] args = invocation.getArguments();
|
||||||
|
String configKey = args[0].toString();
|
||||||
|
switch (configKey) {
|
||||||
|
case "rest.password":
|
||||||
|
return "secret";
|
||||||
|
case "rest.issuer":
|
||||||
|
return "ApiKeyServiceTest";
|
||||||
|
default:
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (ConfigException | ControllerException ex) {
|
||||||
|
LOGGER.error(ex.getMessage());
|
||||||
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
LOGGER.debug("Detailed stacktrace", new Object[]{ex});
|
||||||
|
}
|
||||||
|
fail("An exception occured");
|
||||||
|
}
|
||||||
|
apiKeyService.accountControl = mock(AccountControl.class);
|
||||||
|
when(apiKeyService.accountControl.getAccountEntity(anyString(), anyBoolean())).thenAnswer(new Answer<AccountEntity>() {
|
||||||
|
@Override
|
||||||
|
public AccountEntity answer(InvocationOnMock iom) throws Throwable {
|
||||||
|
Object[] args = iom.getArguments();
|
||||||
|
String userName = args[0].toString();
|
||||||
|
boolean loadRoles = (boolean) args[1];
|
||||||
|
AccountEntity account = new AccountEntity();
|
||||||
|
account.setUsername(userName);
|
||||||
|
account.setFirstname("FirstName");
|
||||||
|
account.setLastname("LastName");
|
||||||
|
if (loadRoles) {
|
||||||
|
account.setApplicationRoleList(new ArrayList<>());
|
||||||
|
ApplicationRoleEntity exampleRoleEntity = new ApplicationRoleEntity();
|
||||||
|
exampleRoleEntity.setRoleName("Example Role");
|
||||||
|
account.getApplicationRoleList().add(exampleRoleEntity);
|
||||||
|
}
|
||||||
|
return account;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
apiKeyService.em = mock (EntityManager.class);
|
||||||
|
apiKeyService.init();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateApiKey() {
|
public void testCreateApiKey() {
|
||||||
try {
|
try {
|
||||||
ApiKeyService apiKeyService = new ApiKeyService();
|
ApiKeyObject apiKeyObject = apiKeyService.createNewApiKey("web", (short) 120);
|
||||||
apiKeyService.createNewApiKey("web", (short) 120);
|
assertNotNull(apiKeyObject);
|
||||||
|
LOGGER.info("authToken: "+apiKeyObject.getAuthToken());
|
||||||
} catch (ApiKeyException ex) {
|
} catch (ApiKeyException ex) {
|
||||||
LOGGER.error(ex.getMessage());
|
LOGGER.error(ex.getMessage());
|
||||||
if (LOGGER.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
|
|||||||
@ -1,76 +1,76 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018 joern.muehlencord.
|
* Copyright 2018 joern.muehlencord.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.account.business.config.boundary;
|
package de.muehlencord.shared.account.business.config.boundary;
|
||||||
|
|
||||||
import de.muehlencord.shared.account.business.account.entity.AccountEntity;
|
import de.muehlencord.shared.account.business.account.entity.AccountEntity;
|
||||||
import de.muehlencord.shared.account.business.account.entity.AccountLoginEntity;
|
import de.muehlencord.shared.account.business.account.entity.AccountLoginEntity;
|
||||||
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
import de.muehlencord.shared.account.business.application.entity.ApplicationEntity;
|
||||||
import de.muehlencord.shared.account.business.config.entity.ConfigEntity;
|
import de.muehlencord.shared.account.business.config.entity.ConfigEntity;
|
||||||
import de.muehlencord.shared.account.business.config.entity.ConfigEntityPK;
|
import de.muehlencord.shared.account.business.config.entity.ConfigEntityPK;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.Ignore;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author joern.muehlencord
|
* @author joern.muehlencord
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
public class ConfigServiceTest {
|
public class ConfigServiceTest {
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private ConfigService configService;
|
private ConfigService configService;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private EntityManager entityManagerMock;
|
private EntityManager entityManagerMock;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void init() {
|
public void init() {
|
||||||
ApplicationEntity application = new ApplicationEntity();
|
ApplicationEntity application = new ApplicationEntity();
|
||||||
application.setId(UUID.randomUUID());
|
application.setId(UUID.randomUUID());
|
||||||
application.setApplicationName("Test App");
|
application.setApplicationName("Test App");
|
||||||
|
|
||||||
AccountEntity account = new AccountEntity();
|
AccountEntity account = new AccountEntity();
|
||||||
account.setUsername("system");
|
account.setUsername("system");
|
||||||
AccountLoginEntity login = new AccountLoginEntity();
|
AccountLoginEntity login = new AccountLoginEntity();
|
||||||
login.setAccount (account);
|
login.setAccount (account);
|
||||||
account.setAccountLogin(login);
|
account.setAccountLogin(login);
|
||||||
|
|
||||||
ConfigEntityPK pk = new ConfigEntityPK(application, "account.maxFailedLogins", account);
|
ConfigEntityPK pk = new ConfigEntityPK(application, "account.maxFailedLogins", account);
|
||||||
ConfigEntity configEntity = new ConfigEntity (pk);
|
ConfigEntity configEntity = new ConfigEntity (pk);
|
||||||
configEntity.setConfigValue("7");
|
configEntity.setConfigValue("7");
|
||||||
when (entityManagerMock.find(ConfigEntity.class, "account.maxFailedLogins")).thenReturn (configEntity);
|
when (entityManagerMock.find(ConfigEntity.class, "account.maxFailedLogins")).thenReturn (configEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
// TODO move to account test
|
// TODO move to account test
|
||||||
public void testGetMaxFailedLogins() {
|
public void testGetMaxFailedLogins() {
|
||||||
// configService.init();
|
// configService.init();
|
||||||
// assertEquals ("maxFailedLogins", 7, configService.getMaxFailedLogins());
|
// assertEquals ("maxFailedLogins", 7, configService.getMaxFailedLogins());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,68 +1,75 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018 joern.muehlencord.
|
* Copyright 2018 joern.muehlencord.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.account.shiro.realm;
|
package de.muehlencord.shared.account.shiro.realm;
|
||||||
|
|
||||||
import org.apache.shiro.SecurityUtils;
|
import org.apache.shiro.SecurityUtils;
|
||||||
import org.apache.shiro.authc.AuthenticationException;
|
import org.apache.shiro.authc.AuthenticationException;
|
||||||
import org.apache.shiro.authc.UsernamePasswordToken;
|
import org.apache.shiro.authc.UsernamePasswordToken;
|
||||||
import org.apache.shiro.config.IniSecurityManagerFactory;
|
import org.apache.shiro.config.IniSecurityManagerFactory;
|
||||||
import org.apache.shiro.subject.Subject;
|
import org.apache.shiro.mgt.SecurityManager;
|
||||||
import org.junit.Test;
|
import org.apache.shiro.subject.Subject;
|
||||||
import org.apache.shiro.mgt.SecurityManager;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import static org.junit.Assume.assumeNotNull;
|
import static org.junit.jupiter.api.Assumptions.assumeFalse;
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
/**
|
import org.junit.jupiter.api.Test;
|
||||||
*
|
|
||||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
/**
|
||||||
*/
|
*
|
||||||
public class UserNameActiveDirectoryRealmTest {
|
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||||
|
*/
|
||||||
@Test
|
public class UserNameActiveDirectoryRealmTest {
|
||||||
public void testUsernameLogin() {
|
|
||||||
String userName = "user.name";
|
@Test
|
||||||
String password = "secret";
|
public void testUsernameLogin() {
|
||||||
testLogin(userName, password);
|
String userName = "root";
|
||||||
}
|
String password = "secret";
|
||||||
|
testLogin(userName, password);
|
||||||
@Test
|
}
|
||||||
public void testEmailaddressLogin() {
|
|
||||||
String userName = "user.name@domain.com";
|
@Test
|
||||||
String password = "secret";
|
@Disabled
|
||||||
testLogin(userName, password);
|
public void testEmailaddressLogin() {
|
||||||
}
|
String userName = "user.name@domain.com";
|
||||||
|
String password = "secret";
|
||||||
@Test(expected=AuthenticationException.class)
|
Assertions.assertThrows(AuthenticationException.class, () -> {
|
||||||
public void testWrongUserNamePassword() {
|
testLogin(userName, password);
|
||||||
String userName = "test123";
|
});
|
||||||
String password = "secret";
|
}
|
||||||
testLogin(userName, password);
|
|
||||||
}
|
@Test
|
||||||
|
public void testWrongUserNamePassword() {
|
||||||
private void testLogin(String userName, String password) throws AuthenticationException {
|
String userName = "test123";
|
||||||
assumeNotNull(UserNameActiveDirectoryRealmTest.class.getResource("/shiro.ini"));
|
String password = "secret";
|
||||||
|
Assertions.assertThrows(AuthenticationException.class, () -> {
|
||||||
IniSecurityManagerFactory factory = new IniSecurityManagerFactory("classpath:shiro.ini");
|
testLogin(userName, password);
|
||||||
SecurityManager securityManager = factory.getInstance();
|
});
|
||||||
SecurityUtils.setSecurityManager(securityManager);
|
}
|
||||||
|
|
||||||
UsernamePasswordToken token = new UsernamePasswordToken(userName, password);
|
private void testLogin(String userName, String password) throws AuthenticationException {
|
||||||
Subject currentUser = SecurityUtils.getSubject();
|
assumeFalse(UserNameActiveDirectoryRealmTest.class.getResource("/shiro.ini") == null);
|
||||||
|
|
||||||
currentUser.login(token);
|
IniSecurityManagerFactory factory = new IniSecurityManagerFactory("classpath:shiro.ini");
|
||||||
System.out.println("Logged in");
|
SecurityManager securityManager = factory.getInstance();
|
||||||
}
|
SecurityUtils.setSecurityManager(securityManager);
|
||||||
|
|
||||||
}
|
UsernamePasswordToken token = new UsernamePasswordToken(userName, password);
|
||||||
|
Subject currentUser = SecurityUtils.getSubject();
|
||||||
|
|
||||||
|
currentUser.login(token);
|
||||||
|
System.out.println("Logged in");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@ -1,32 +1,32 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2018 joern.muehlencord.
|
* Copyright 2018 joern.muehlencord.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package de.muehlencord.shared.account.util;
|
package de.muehlencord.shared.account.util;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Joern Muehlencord <joern at muehlencord.de>
|
* @author Joern Muehlencord <joern at muehlencord.de>
|
||||||
*/
|
*/
|
||||||
public class SecurityUtilTest {
|
public class SecurityUtilTest {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreatePassword() {
|
public void testCreatePassword() {
|
||||||
System.out.println (SecurityUtil.createPassword("secret"));
|
System.out.println (SecurityUtil.createPassword("secret"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
25
account/src/test/resources/shiro.ini
Normal file
25
account/src/test/resources/shiro.ini
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# =============================================================================
|
||||||
|
# Tutorial INI configuration
|
||||||
|
#
|
||||||
|
# Usernames/passwords are based on the classic Mel Brooks' film "Spaceballs" :)
|
||||||
|
# =============================================================================
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# Users and their (optional) assigned roles
|
||||||
|
# username = password, role1, role2, ..., roleN
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
[users]
|
||||||
|
root = secret, admin
|
||||||
|
guest = guest, guest
|
||||||
|
presidentskroob = 12345, president
|
||||||
|
darkhelmet = ludicrousspeed, darklord, schwartz
|
||||||
|
lonestarr = vespa, goodguy, schwartz
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# Roles with assigned permissions
|
||||||
|
# roleName = perm1, perm2, ..., permN
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
[roles]
|
||||||
|
admin = *
|
||||||
|
schwartz = lightsaber:*
|
||||||
|
goodguy = winnebago:drive:eagle5
|
||||||
@ -19,10 +19,10 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
|
|||||||
@ -25,11 +25,10 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
<type>jar</type>
|
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.enterprisedt</groupId>
|
<groupId>com.enterprisedt</groupId>
|
||||||
<artifactId>edtFTPj</artifactId>
|
<artifactId>edtFTPj</artifactId>
|
||||||
|
|||||||
@ -5,8 +5,8 @@
|
|||||||
package de.muehlencord.shared.network;
|
package de.muehlencord.shared.network;
|
||||||
|
|
||||||
import static de.muehlencord.shared.network.CidrTool.rangeToCidrList;
|
import static de.muehlencord.shared.network.CidrTool.rangeToCidrList;
|
||||||
import org.junit.Ignore;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -18,7 +18,7 @@ public class CidrToolTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testCidrConversion() {
|
public void testCidrConversion() {
|
||||||
System.out.println (rangeToCidrList("213.55.64.0", "213.55.127.255"));
|
System.out.println (rangeToCidrList("213.55.64.0", "213.55.127.255"));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,9 +3,9 @@ package de.muehlencord.shared.network;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import org.apache.commons.net.util.SubnetUtils;
|
import org.apache.commons.net.util.SubnetUtils;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import org.junit.Ignore;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -17,7 +17,7 @@ public class NetworkScannerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // takes very long
|
@Disabled // takes very long
|
||||||
public void testScan() throws UnknownHostException {
|
public void testScan() throws UnknownHostException {
|
||||||
String ipAddress = InetAddress.getLocalHost().getHostAddress();
|
String ipAddress = InetAddress.getLocalHost().getHostAddress();
|
||||||
SubnetUtils utils = new SubnetUtils(ipAddress, "255.255.255.0");
|
SubnetUtils utils = new SubnetUtils(ipAddress, "255.255.255.0");
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
package de.muehlencord.shared.network;
|
package de.muehlencord.shared.network;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.junit.Ignore;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -14,7 +14,7 @@ public class PortScannerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // takes very long
|
@Disabled // takes very long
|
||||||
public void testMain() {
|
public void testMain() {
|
||||||
PortScanner portScanner = new PortScanner();
|
PortScanner portScanner = new PortScanner();
|
||||||
List<PortInformation> resultList = portScanner.scan("127.0.0.1");
|
List<PortInformation> resultList = portScanner.scan("127.0.0.1");
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
package de.muehlencord.shared.network;
|
package de.muehlencord.shared.network;
|
||||||
|
|
||||||
import static de.muehlencord.shared.network.CidrTool.rangeToCidrList;
|
import static de.muehlencord.shared.network.CidrTool.rangeToCidrList;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@ -7,10 +7,11 @@ import java.net.URL;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import org.junit.Before;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
import org.junit.Ignore;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -27,8 +28,8 @@ public class FTPConnectionTest {
|
|||||||
/** true, if init is complete to execute test */
|
/** true, if init is complete to execute test */
|
||||||
boolean initDone = false;
|
boolean initDone = false;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void initClass() {
|
public void setup() {
|
||||||
System.out.println("\n[FTPConnectionTest]");
|
System.out.println("\n[FTPConnectionTest]");
|
||||||
URL testConfigURL = FTPConnectionTest.class.getResource("/test.properties");
|
URL testConfigURL = FTPConnectionTest.class.getResource("/test.properties");
|
||||||
FileInputStream fin = null;
|
FileInputStream fin = null;
|
||||||
@ -80,7 +81,7 @@ public class FTPConnectionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testList() throws FTPConnectionException {
|
public void testList() throws FTPConnectionException {
|
||||||
System.out.println("list");
|
System.out.println("list");
|
||||||
String dir = "";
|
String dir = "";
|
||||||
@ -92,7 +93,7 @@ public class FTPConnectionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testListDirsOnly() throws FTPConnectionException {
|
public void testListDirsOnly() throws FTPConnectionException {
|
||||||
System.out.println("listDirsOnly");
|
System.out.println("listDirsOnly");
|
||||||
String dir = "";
|
String dir = "";
|
||||||
@ -104,7 +105,7 @@ public class FTPConnectionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testListFilesOnly() throws FTPConnectionException {
|
public void testListFilesOnly() throws FTPConnectionException {
|
||||||
System.out.println("listFilesOnly");
|
System.out.println("listFilesOnly");
|
||||||
String dir = "";
|
String dir = "";
|
||||||
@ -116,7 +117,7 @@ public class FTPConnectionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testListLinksOnly() throws FTPConnectionException {
|
public void testListLinksOnly() throws FTPConnectionException {
|
||||||
System.out.println("listLinksOnly");
|
System.out.println("listLinksOnly");
|
||||||
String dir = "";
|
String dir = "";
|
||||||
@ -128,7 +129,7 @@ public class FTPConnectionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testUploadFile() throws FTPConnectionException {
|
public void testUploadFile() throws FTPConnectionException {
|
||||||
System.out.println("uploadFile");
|
System.out.println("uploadFile");
|
||||||
String localFilename = "";
|
String localFilename = "";
|
||||||
@ -138,7 +139,7 @@ public class FTPConnectionTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testRename() throws FTPConnectionException {
|
public void testRename() throws FTPConnectionException {
|
||||||
System.out.println("rename");
|
System.out.println("rename");
|
||||||
String remoteOldName = "";
|
String remoteOldName = "";
|
||||||
|
|||||||
@ -9,8 +9,9 @@ import java.util.HashMap;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.junit.Ignore;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -19,7 +20,7 @@ import org.junit.Test;
|
|||||||
public class HttpLayerTest extends BaseTest {
|
public class HttpLayerTest extends BaseTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testPostByMap() throws Exception {
|
public void testPostByMap() throws Exception {
|
||||||
System.out.println("testPostByMap");
|
System.out.println("testPostByMap");
|
||||||
Map<String, String[]> map = new HashMap<>();
|
Map<String, String[]> map = new HashMap<>();
|
||||||
@ -32,7 +33,7 @@ public class HttpLayerTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testPostByMapList() throws Exception {
|
public void testPostByMapList() throws Exception {
|
||||||
System.out.println("testPostByMapList");
|
System.out.println("testPostByMapList");
|
||||||
List<Map<String, String[]>> list = new LinkedList<>();
|
List<Map<String, String[]>> list = new LinkedList<>();
|
||||||
@ -45,41 +46,43 @@ public class HttpLayerTest extends BaseTest {
|
|||||||
map.put("url", urlValue);
|
map.put("url", urlValue);
|
||||||
list.add(map);
|
list.add(map);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
HttpLayer httpLayer = new HttpLayer("http://localhost:8080/HttpPostListener/HttpPostListener");
|
HttpLayer httpLayer = new HttpLayer("http://localhost:8080/HttpPostListener/HttpPostListener");
|
||||||
httpLayer.post(list);
|
httpLayer.post(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testByValue() throws Exception {
|
public void testByValue() throws Exception {
|
||||||
System.out.println("testByValue");
|
System.out.println("testByValue");
|
||||||
HttpLayer httpLayer = new HttpLayer(
|
HttpLayer httpLayer = new HttpLayer("http://localhost:8080/HttpPostListener/HttpPostListener");
|
||||||
"http://localhost:8080/HttpPostListener/HttpPostListener");
|
|
||||||
httpLayer.post("message", "Hello World by single parameter");
|
httpLayer.post("message", "Hello World by single parameter");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = MessageNotSendException.class)
|
@Test
|
||||||
public void testWithUnknownURL() throws MessageNotSendException {
|
public void testWithUnknownURL() throws MessageNotSendException {
|
||||||
System.out.println("testWithUnknownURL");
|
System.out.println("testWithUnknownURL");
|
||||||
HttpLayer httpLayer = new HttpLayer(
|
HttpLayer httpLayer = new HttpLayer("http://localhost/thisURLDoesNotExist");
|
||||||
"http://localhost/thisURLDoesNotExist");
|
Assertions.assertThrows(MessageNotSendException.class, () -> {
|
||||||
httpLayer.post("message", "Hello World by single parameter");
|
httpLayer.post("message", "Hello World by single parameter");
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = MessageNotSendException.class)
|
@Test
|
||||||
public void testInvalidURL() throws MessageNotSendException {
|
public void testInvalidURL() throws MessageNotSendException {
|
||||||
System.out.println("testInvalidURL");
|
System.out.println("testInvalidURL");
|
||||||
HttpLayer httpLayer = new HttpLayer("joern@muehlencord.de");
|
HttpLayer httpLayer = new HttpLayer("joern@muehlencord.de");
|
||||||
httpLayer.post("message", "Hello World by single parameter");
|
Assertions.assertThrows(MessageNotSendException.class, () -> {
|
||||||
|
httpLayer.post("message", "Hello World by single parameter");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = MessageNotSendException.class)
|
@Test
|
||||||
public void testUnsupportedURL() throws MessageNotSendException {
|
public void testUnsupportedURL() throws MessageNotSendException {
|
||||||
System.out.println("testUnsupportedURL");
|
System.out.println("testUnsupportedURL");
|
||||||
HttpLayer httpLayer = new HttpLayer("ftp://localhost");
|
HttpLayer httpLayer = new HttpLayer("ftp://localhost");
|
||||||
httpLayer.post("message", "Hello World by single parameter");
|
Assertions.assertThrows(MessageNotSendException.class, () -> {
|
||||||
|
httpLayer.post("message", "Hello World by single parameter");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,11 +6,11 @@ import de.muehlencord.shared.network.mail.imap.ImapMailReader;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Ignore;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -18,13 +18,13 @@ import org.junit.Test;
|
|||||||
*/
|
*/
|
||||||
public class MailMessageUtilsTest extends BaseTest {
|
public class MailMessageUtilsTest extends BaseTest {
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setup() {
|
public void setup() {
|
||||||
System.out.println ("\n[MailMessageUtilsTest]");
|
System.out.println ("\n[MailMessageUtilsTest]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // depends on environment
|
@Disabled // depends on environment
|
||||||
public void testGetInstance() throws Exception {
|
public void testGetInstance() throws Exception {
|
||||||
System.out.println("testGetInstance");
|
System.out.println("testGetInstance");
|
||||||
URL testConfigURL = MailMessageUtilsTest.class.getResource("/test.properties");
|
URL testConfigURL = MailMessageUtilsTest.class.getResource("/test.properties");
|
||||||
|
|||||||
@ -1,8 +1,3 @@
|
|||||||
/*
|
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
|
||||||
* To change this template file, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
package de.muehlencord.shared.network.mail;
|
package de.muehlencord.shared.network.mail;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -23,8 +18,8 @@ import javax.mail.internet.InternetAddress;
|
|||||||
import javax.mail.internet.MimeBodyPart;
|
import javax.mail.internet.MimeBodyPart;
|
||||||
import javax.mail.internet.MimeMessage;
|
import javax.mail.internet.MimeMessage;
|
||||||
import javax.mail.internet.MimeMultipart;
|
import javax.mail.internet.MimeMultipart;
|
||||||
import org.junit.Assume;
|
import static org.junit.jupiter.api.Assumptions.assumeFalse;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -42,8 +37,8 @@ public class TestSendMail {
|
|||||||
@Test
|
@Test
|
||||||
public void testSendEmail() throws AddressException, MessagingException, IOException {
|
public void testSendEmail() throws AddressException, MessagingException, IOException {
|
||||||
|
|
||||||
Assume.assumeFalse(RECEIVER == null);
|
assumeFalse(RECEIVER == null);
|
||||||
Assume.assumeFalse(PASSWORD == null);
|
assumeFalse(PASSWORD == null);
|
||||||
|
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
props.put("mail.smtp.host", "jomu.timelord.de");
|
props.put("mail.smtp.host", "jomu.timelord.de");
|
||||||
|
|||||||
@ -6,9 +6,9 @@ import de.muehlencord.shared.network.mail.MailReaderConfiguration;
|
|||||||
import de.muehlencord.shared.network.mail.MailReaderConnectionException;
|
import de.muehlencord.shared.network.mail.MailReaderConnectionException;
|
||||||
import de.muehlencord.shared.network.mail.MailReaderException;
|
import de.muehlencord.shared.network.mail.MailReaderException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
import static org.junit.Assume.assumeNotNull;
|
import static org.junit.jupiter.api.Assumptions.assumeFalse;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -33,12 +33,12 @@ public class ExchangeMailReaderTest {
|
|||||||
String emailaddress = null;
|
String emailaddress = null;
|
||||||
|
|
||||||
// disable tests if not all values are set
|
// disable tests if not all values are set
|
||||||
assumeNotNull(smtpHost);
|
assumeFalse(smtpHost == null);
|
||||||
assumeNotNull(folder);
|
assumeFalse(folder == null);
|
||||||
assumeNotNull(testFolder);
|
assumeFalse(testFolder == null);
|
||||||
assumeNotNull(userName);
|
assumeFalse(userName == null);
|
||||||
assumeNotNull(emailaddress);
|
assumeFalse(emailaddress == null);
|
||||||
assumeNotNull(password);
|
assumeFalse(password == null);
|
||||||
|
|
||||||
MailReaderConfiguration config = new MailReaderConfiguration(smtpHost, imapHost, userName, password, emailaddress);
|
MailReaderConfiguration config = new MailReaderConfiguration(smtpHost, imapHost, userName, password, emailaddress);
|
||||||
MailReader instance = new ExchangeMailReader(config);
|
MailReader instance = new ExchangeMailReader(config);
|
||||||
|
|||||||
@ -1,7 +1,3 @@
|
|||||||
/*
|
|
||||||
* To change this template, choose Tools | Templates
|
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
|
||||||
package de.muehlencord.shared.network.mail.imap;
|
package de.muehlencord.shared.network.mail.imap;
|
||||||
|
|
||||||
import de.muehlencord.shared.network.BaseTest;
|
import de.muehlencord.shared.network.BaseTest;
|
||||||
@ -10,10 +6,10 @@ import de.muehlencord.shared.network.mail.MailReaderConfiguration;
|
|||||||
import de.muehlencord.shared.network.mail.MailReaderConnectionException;
|
import de.muehlencord.shared.network.mail.MailReaderConnectionException;
|
||||||
import de.muehlencord.shared.network.mail.MailReaderException;
|
import de.muehlencord.shared.network.mail.MailReaderException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import org.junit.Ignore;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -28,7 +24,7 @@ public class ImapMailReaderTest extends BaseTest {
|
|||||||
* @throws Exception if the tests fails
|
* @throws Exception if the tests fails
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore // depends on environment
|
@Disabled // depends on environment
|
||||||
public void testConnect() throws Exception {
|
public void testConnect() throws Exception {
|
||||||
System.out.println("connect");
|
System.out.println("connect");
|
||||||
String meta = "meta.muehlencord.intra";
|
String meta = "meta.muehlencord.intra";
|
||||||
@ -40,7 +36,7 @@ public class ImapMailReaderTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // depends on environment
|
@Disabled // depends on environment
|
||||||
public void testGetFolder() throws Exception {
|
public void testGetFolder() throws Exception {
|
||||||
System.out.println("getFolder");
|
System.out.println("getFolder");
|
||||||
String meta = "meta.muehlencord.intra";
|
String meta = "meta.muehlencord.intra";
|
||||||
@ -54,7 +50,7 @@ public class ImapMailReaderTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // depends on environment
|
@Disabled // depends on environment
|
||||||
public void testGetMessageCount() throws MailReaderConnectionException, MailReaderException {
|
public void testGetMessageCount() throws MailReaderConnectionException, MailReaderException {
|
||||||
System.out.println("testGetMessageCount");
|
System.out.println("testGetMessageCount");
|
||||||
String meta = "meta.muehlencord.intra";
|
String meta = "meta.muehlencord.intra";
|
||||||
@ -67,7 +63,7 @@ public class ImapMailReaderTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // depends on environment
|
@Disabled // depends on environment
|
||||||
public void testGetSubFolder() throws MailReaderConnectionException, MailReaderException {
|
public void testGetSubFolder() throws MailReaderConnectionException, MailReaderException {
|
||||||
System.out.println("getSubFolder");
|
System.out.println("getSubFolder");
|
||||||
String meta = "meta.muehlencord.intra";
|
String meta = "meta.muehlencord.intra";
|
||||||
|
|||||||
@ -2,9 +2,9 @@ package de.muehlencord.shared.network.whois;
|
|||||||
|
|
||||||
import de.muehlencord.shared.network.BaseTest;
|
import de.muehlencord.shared.network.BaseTest;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.junit.Test;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.*;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.Ignore;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -14,7 +14,7 @@ public class ArinWhoisParserTest extends BaseTest {
|
|||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testParseArinIp() throws IOException, WhoisException {
|
public void testParseArinIp() throws IOException, WhoisException {
|
||||||
String whoisInformation = this.readContentFromFile("204.232.209.184.txt");
|
String whoisInformation = this.readContentFromFile("204.232.209.184.txt");
|
||||||
ArinWhoisParser parser = new ArinWhoisParser();
|
ArinWhoisParser parser = new ArinWhoisParser();
|
||||||
@ -28,7 +28,7 @@ public class ArinWhoisParserTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testParseArinDoubleIp() throws IOException, WhoisException {
|
public void testParseArinDoubleIp() throws IOException, WhoisException {
|
||||||
String whoisInformation = this.readContentFromFile("108.166.92.167.txt");
|
String whoisInformation = this.readContentFromFile("108.166.92.167.txt");
|
||||||
ArinWhoisParser parser = new ArinWhoisParser();
|
ArinWhoisParser parser = new ArinWhoisParser();
|
||||||
@ -42,7 +42,7 @@ public class ArinWhoisParserTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // FIXME test broken
|
@Disabled // FIXME test broken
|
||||||
public void testParseArinUnknown() throws IOException, WhoisException {
|
public void testParseArinUnknown() throws IOException, WhoisException {
|
||||||
String whoisInformation = this.readContentFromFile("74.95.241.217.txt");
|
String whoisInformation = this.readContentFromFile("74.95.241.217.txt");
|
||||||
ArinWhoisParser parser = new ArinWhoisParser();
|
ArinWhoisParser parser = new ArinWhoisParser();
|
||||||
|
|||||||
@ -1,69 +1,68 @@
|
|||||||
package de.muehlencord.shared.network.whois;
|
package de.muehlencord.shared.network.whois;
|
||||||
|
|
||||||
import de.muehlencord.shared.network.BaseTest;
|
import de.muehlencord.shared.network.BaseTest;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import org.junit.Ignore;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author jomu
|
* @author jomu
|
||||||
*/
|
*/
|
||||||
public class WhoisTest extends BaseTest {
|
public class WhoisTest extends BaseTest {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testDenicWhoIs() throws WhoisException {
|
public void testDenicWhoIs() throws WhoisException {
|
||||||
Whois whoIsClient = new Whois();
|
Whois whoIsClient = new Whois();
|
||||||
// Denic answers "status: connect" only
|
// Denic answers "status: connect" only
|
||||||
whoIsClient.execute ("whois.denic.de", "-T dn,ace muehlencord.de");
|
whoIsClient.execute("whois.denic.de", "-T dn,ace muehlencord.de");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Ignore
|
|
||||||
public void testInternic() throws WhoisException {
|
|
||||||
Whois whoIsClient = new Whois();
|
|
||||||
whoIsClient.execute ("whois.1api.net", "egameladder.com");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
|
public void testInternic() throws WhoisException {
|
||||||
|
Whois whoIsClient = new Whois();
|
||||||
|
whoIsClient.execute("whois.1api.net", "egameladder.com");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Disabled
|
||||||
// TODO 184.173.67.10 whois with referal
|
// TODO 184.173.67.10 whois with referal
|
||||||
public void testArin() throws WhoisException {
|
public void testArin() throws WhoisException {
|
||||||
Whois whoIsClient = new Whois();
|
Whois whoIsClient = new Whois();
|
||||||
// WhoisInformation whoisInformation = whoIsClient.execute ("whois.arin.net", "204.232.209.184");
|
// WhoisInformation whoisInformation = whoIsClient.execute ("whois.arin.net", "204.232.209.184");
|
||||||
WhoisInformation whoisInformation = whoIsClient.execute ("whois.arin.net", "74.95.241.217");
|
WhoisInformation whoisInformation = whoIsClient.execute("whois.arin.net", "74.95.241.217");
|
||||||
assertNotNull (whoisInformation);
|
assertNotNull(whoisInformation);
|
||||||
whoisInformation.validate();
|
whoisInformation.validate();
|
||||||
assertEquals ("Country", "US", whoisInformation.getNetworkInformation().getCountry());
|
assertEquals("Country", "US", whoisInformation.getNetworkInformation().getCountry());
|
||||||
System.out.println ("Network: "+whoisInformation.getNetwork());
|
System.out.println("Network: " + whoisInformation.getNetwork());
|
||||||
assertTrue ("Network", whoisInformation.getNetwork().contains("74.95.224.0/19"));
|
assertTrue(whoisInformation.getNetwork().contains("74.95.224.0/19"), "Network");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testApnic() throws WhoisException {
|
public void testApnic() throws WhoisException {
|
||||||
Whois whoIsClient = new Whois();
|
Whois whoIsClient = new Whois();
|
||||||
whoIsClient.execute ("whois.apnic.net", "60.247.69.45");
|
whoIsClient.execute("whois.apnic.net", "60.247.69.45");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testLacnic() throws WhoisException {
|
public void testLacnic() throws WhoisException {
|
||||||
Whois whoIsClient = new Whois();
|
Whois whoIsClient = new Whois();
|
||||||
WhoisInformation whoisInformation = whoIsClient.execute ("whois.lacnic.net", "200.29.132.82");
|
WhoisInformation whoisInformation = whoIsClient.execute("whois.lacnic.net", "200.29.132.82");
|
||||||
assertNotNull (whoisInformation);
|
assertNotNull(whoisInformation);
|
||||||
assertEquals ("Country", "CL", whoisInformation.getNetworkInformation().getCountry());
|
assertEquals("Country", "CL", whoisInformation.getNetworkInformation().getCountry());
|
||||||
assertTrue ("Network", whoisInformation.getNetwork().contains("200.29.132.80/29"));
|
assertTrue(whoisInformation.getNetwork().contains("200.29.132.80/29"), "Network");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testUnkown() throws WhoisException {
|
public void testUnkown() throws WhoisException {
|
||||||
Whois whoIsClient = new Whois();
|
Whois whoIsClient = new Whois();
|
||||||
// whoIsClient.execute("whois.arin.net", "174.139.180.10");
|
// whoIsClient.execute("whois.arin.net", "174.139.180.10");
|
||||||
// whoIsClient.execute("whois.twnic.net", "60.250.38.39");
|
// whoIsClient.execute("whois.twnic.net", "60.250.38.39");
|
||||||
@ -72,32 +71,31 @@ public class WhoisTest extends BaseTest {
|
|||||||
// whoIsClient.execute("whois.apnic.net", "182.72.111.26");
|
// whoIsClient.execute("whois.apnic.net", "182.72.111.26");
|
||||||
// whoIsClient.execute("whois.ripe.net", "213.55.95.62"); // Transferred to Afrinic
|
// whoIsClient.execute("whois.ripe.net", "213.55.95.62"); // Transferred to Afrinic
|
||||||
// whoIsClient.execute("whois.afrinic.net", "213.55.95.62");
|
// whoIsClient.execute("whois.afrinic.net", "213.55.95.62");
|
||||||
whoIsClient.execute("whois.arin.net", "32.64.68.229");
|
whoIsClient.execute("whois.arin.net", "32.64.68.229");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testGeneric() throws WhoisException {
|
public void testGeneric() throws WhoisException {
|
||||||
Whois whoIsClient = new Whois();
|
Whois whoIsClient = new Whois();
|
||||||
WhoisInformation info = whoIsClient.execute( "85.185.91.5");
|
WhoisInformation info = whoIsClient.execute("85.185.91.5");
|
||||||
assertNotNull (info);
|
assertNotNull(info);
|
||||||
assertNotNull (info.getNetwork());
|
assertNotNull(info.getNetwork());
|
||||||
assertFalse (info.getNetwork().isEmpty());
|
assertFalse(info.getNetwork().isEmpty());
|
||||||
System.out.println (info.getNetwork().toString());
|
System.out.println(info.getNetwork().toString());
|
||||||
System.out.println (info.getRootNetwork().toString());
|
System.out.println(info.getRootNetwork().toString());
|
||||||
System.out.println (info.getNetworkInformation().getDescription());
|
System.out.println(info.getNetworkInformation().getDescription());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testStepWise() throws WhoisException {
|
public void testStepWise() throws WhoisException {
|
||||||
Whois whoIsClient = new Whois();
|
Whois whoIsClient = new Whois();
|
||||||
// whoIsClient.execute ("whois.ripe.net", "88.198.181.181");
|
// whoIsClient.execute ("whois.ripe.net", "88.198.181.181");
|
||||||
WhoisInformation whoisInformation = whoIsClient.execute ("212.204.60.1");
|
WhoisInformation whoisInformation = whoIsClient.execute("212.204.60.1");
|
||||||
assertTrue ("network", whoisInformation.getNetwork().contains("212.204.60.0/24"));
|
assertTrue(whoisInformation.getNetwork().contains("212.204.60.0/24"), "network");
|
||||||
// whoIsClient.execute ("whois.ripe.net", "212.204.60.0");
|
// whoIsClient.execute ("whois.ripe.net", "212.204.60.0");
|
||||||
// whoIsClient.execute ("whois.ripe.net", "212.0.0.0/8");
|
// whoIsClient.execute ("whois.ripe.net", "212.0.0.0/8");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,10 +17,10 @@
|
|||||||
<artifactId>freemarker</artifactId>
|
<artifactId>freemarker</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
|||||||
@ -2,12 +2,12 @@ package de.muehlencord.shared.pdf;
|
|||||||
|
|
||||||
import com.google.gson.JsonDeserializationContext;
|
import com.google.gson.JsonDeserializationContext;
|
||||||
import com.google.gson.JsonDeserializer;
|
import com.google.gson.JsonDeserializer;
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParseException;
|
import com.google.gson.JsonParseException;
|
||||||
import com.google.gson.JsonSerializationContext;
|
import com.google.gson.JsonSerializationContext;
|
||||||
import com.google.gson.JsonSerializer;
|
import com.google.gson.JsonSerializer;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@ -7,7 +7,6 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentLinkedDeque;
|
|
||||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||||
import org.apache.pdfbox.pdmodel.font.PDFont;
|
import org.apache.pdfbox.pdmodel.font.PDFont;
|
||||||
import org.apache.pdfbox.pdmodel.font.PDType1Font;
|
import org.apache.pdfbox.pdmodel.font.PDType1Font;
|
||||||
|
|||||||
@ -1,35 +1,35 @@
|
|||||||
package de.muehlencord.shared.pdf;
|
package de.muehlencord.shared.pdf;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author joern.muehlencord
|
* @author joern.muehlencord
|
||||||
*/
|
*/
|
||||||
public class DefaultTableRowTest {
|
public class DefaultTableRowTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFromJson() {
|
public void testFromJson() {
|
||||||
String jsonString = "{\n" +
|
String jsonString = "{\n"
|
||||||
" \"type\": \"de.muehlencord.shared.pdf.DefaultTableRow\",\n" +
|
+ " \"type\": \"de.muehlencord.shared.pdf.DefaultTableRow\",\n"
|
||||||
" \"data\": {\n" +
|
+ " \"data\": {\n"
|
||||||
" \"row\": [\n" +
|
+ " \"row\": [\n"
|
||||||
" {\n" +
|
+ " {\n"
|
||||||
" \"text\": \"Rechnungs-Nr.:\"\n" +
|
+ " \"text\": \"Rechnungs-Nr.:\"\n"
|
||||||
" },\n" +
|
+ " },\n"
|
||||||
" {\n" +
|
+ " {\n"
|
||||||
" \"text\": \"${invoiceNumber}\"\n" +
|
+ " \"text\": \"${invoiceNumber}\"\n"
|
||||||
" }\n" +
|
+ " }\n"
|
||||||
" ],\n" +
|
+ " ],\n"
|
||||||
" \"isList\": false\n" +
|
+ " \"isList\": false\n"
|
||||||
" }\n" +
|
+ " }\n"
|
||||||
" }";
|
+ " }";
|
||||||
|
|
||||||
|
TableRow tableRow = GsonUtil.getInstance().fromJson(jsonString, TableRow.class);
|
||||||
TableRow tableRow = GsonUtil.getInstance().fromJson(jsonString, TableRow.class);
|
assertFalse(tableRow == null, "tableRowObject");
|
||||||
assertNotNull ("tableRowObject", tableRow);
|
assertEquals(2, tableRow.getColumnCount(), "column count");
|
||||||
assertEquals ("column count", 2, tableRow.getColumnCount());
|
assertFalse(tableRow.isList(), "isList");
|
||||||
assertFalse ("isList", tableRow.isList());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
package de.muehlencord.shared.pdf;
|
package de.muehlencord.shared.pdf;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.*;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@ -2,7 +2,7 @@ package de.muehlencord.shared.pdf;
|
|||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
package de.muehlencord.shared.pdf;
|
package de.muehlencord.shared.pdf;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -17,10 +18,10 @@ public class TextTest {
|
|||||||
String jsonString = "{\n"
|
String jsonString = "{\n"
|
||||||
+ "\"text\": \"Rechnungs-Nr.:\"\n"
|
+ "\"text\": \"Rechnungs-Nr.:\"\n"
|
||||||
+ "}";
|
+ "}";
|
||||||
|
|
||||||
TextElement text = GsonUtil.getInstance().fromJson(jsonString, TextElement.class);
|
TextElement text = GsonUtil.getInstance().fromJson(jsonString, TextElement.class);
|
||||||
assertNotNull ("text object", text);
|
assertFalse(text == null, "text object");
|
||||||
assertEquals ("text value", "Rechnungs-Nr.:", text.getText());
|
assertEquals("Rechnungs-Nr.:", text.getText(), "text value");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import java.io.IOException;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@ -25,14 +25,15 @@ import java.net.URL;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.junit.FixMethodOrder;
|
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.TestMethodOrder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author jomu
|
* @author jomu
|
||||||
*/
|
*/
|
||||||
@FixMethodOrder
|
@TestMethodOrder(OrderAnnotation.class)
|
||||||
public class PDFDocumentTest {
|
public class PDFDocumentTest {
|
||||||
|
|
||||||
private String jsonString = null;
|
private String jsonString = null;
|
||||||
|
|||||||
@ -1,11 +1,12 @@
|
|||||||
|
|
||||||
package de.muehlencord.shared.pdf.util;
|
package de.muehlencord.shared.pdf.util;
|
||||||
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import org.junit.Ignore;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -32,7 +33,7 @@ public class ImageUtilTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testFromFile() throws IOException {
|
public void testFromFile() throws IOException {
|
||||||
System.out.println ("testFromFile");
|
System.out.println ("testFromFile");
|
||||||
BufferedImage img = ImageIO.read(new File ("c:/temp/dn_logo_smartteller_transparent.png"));
|
BufferedImage img = ImageIO.read(new File ("c:/temp/dn_logo_smartteller_transparent.png"));
|
||||||
|
|||||||
90
pom.xml
90
pom.xml
@ -72,41 +72,11 @@
|
|||||||
<groupId>de.muehlencord.sf</groupId>
|
<groupId>de.muehlencord.sf</groupId>
|
||||||
<artifactId>filter</artifactId>
|
<artifactId>filter</artifactId>
|
||||||
<version>1.1-SNAPSHOT</version>
|
<version>1.1-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>4.12</version> <!-- TODO needs update to v5 -->
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.junit.jupiter</groupId>
|
|
||||||
<artifactId>junit-jupiter-api</artifactId>
|
|
||||||
<version>5.3.1</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.junit.jupiter</groupId>
|
|
||||||
<artifactId>junit-jupiter-params</artifactId>
|
|
||||||
<version>5.3.1</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.junit.jupiter</groupId>
|
|
||||||
<artifactId>junit-jupiter-engine</artifactId>
|
|
||||||
<version>5.3.1</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mockito</groupId>
|
|
||||||
<artifactId>mockito-core</artifactId>
|
|
||||||
<version>2.23.0</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-codec</groupId>
|
<groupId>commons-codec</groupId>
|
||||||
<artifactId>commons-codec</artifactId>
|
<artifactId>commons-codec</artifactId>
|
||||||
<version>1.11</version>
|
<version>1.12</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-net</groupId>
|
<groupId>commons-net</groupId>
|
||||||
@ -116,7 +86,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
<version>3.8.1</version>
|
<version>3.9</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-io</groupId>
|
<groupId>commons-io</groupId>
|
||||||
@ -157,24 +127,24 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-annotations</artifactId>
|
<artifactId>jackson-annotations</artifactId>
|
||||||
<version>2.9.8</version>
|
<version>2.9.9</version>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>2.9.8</version>
|
<version>2.9.9.1</version>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.shiro</groupId>
|
<groupId>org.apache.shiro</groupId>
|
||||||
<artifactId>shiro-core</artifactId>
|
<artifactId>shiro-core</artifactId>
|
||||||
<version>1.4.0</version>
|
<version>1.4.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.shiro</groupId>
|
<groupId>org.apache.shiro</groupId>
|
||||||
<artifactId>shiro-web</artifactId>
|
<artifactId>shiro-web</artifactId>
|
||||||
<version>1.4.0</version>
|
<version>1.4.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax</groupId>
|
<groupId>javax</groupId>
|
||||||
@ -259,6 +229,38 @@
|
|||||||
<artifactId>prime-jwt</artifactId>
|
<artifactId>prime-jwt</artifactId>
|
||||||
<version>1.3.1</version>
|
<version>1.3.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Testing -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
|
<version>5.5.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-params</artifactId>
|
||||||
|
<version>5.5.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
|
<version>5.5.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
<version>2.28.2</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-junit-jupiter</artifactId>
|
||||||
|
<version>2.23.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
@ -295,7 +297,13 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-release-plugin</artifactId>
|
<artifactId>maven-release-plugin</artifactId>
|
||||||
<version>2.5.3</version>
|
<version>2.5.3</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.22.2</version>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</pluginManagement>
|
</pluginManagement>
|
||||||
<plugins>
|
<plugins>
|
||||||
@ -309,7 +317,11 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<tagNameFormat>v@{project.version}</tagNameFormat>
|
<tagNameFormat>v@{project.version}</tagNameFormat>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|||||||
@ -21,8 +21,9 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-codec</groupId>
|
<groupId>commons-codec</groupId>
|
||||||
|
|||||||
@ -15,8 +15,9 @@ package de.muehlencord.shared.security;
|
|||||||
|
|
||||||
import static de.muehlencord.shared.security.Luhn.computeCheckDigit;
|
import static de.muehlencord.shared.security.Luhn.computeCheckDigit;
|
||||||
import static de.muehlencord.shared.security.Luhn.validateNumber;
|
import static de.muehlencord.shared.security.Luhn.validateNumber;
|
||||||
import org.junit.Test;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@ -2,153 +2,153 @@ package de.muehlencord.shared.security;
|
|||||||
|
|
||||||
import static de.muehlencord.shared.security.OldPasswordUtil.getScryptHash;
|
import static de.muehlencord.shared.security.OldPasswordUtil.getScryptHash;
|
||||||
import static de.muehlencord.shared.security.OldPasswordUtil.validateScryptHash;
|
import static de.muehlencord.shared.security.OldPasswordUtil.validateScryptHash;
|
||||||
import org.junit.Test;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author jomu
|
* @author jomu
|
||||||
*/
|
*/
|
||||||
public class OldPasswordUtilTest {
|
public class OldPasswordUtilTest {
|
||||||
|
|
||||||
/**
|
|
||||||
* Test of createSaltString method, of class PasswordUtil.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void createSaltString() throws Exception {
|
|
||||||
System.out.println("createSaltString");
|
|
||||||
int saltLength = 40;
|
|
||||||
String result = OldPasswordUtil.createSaltString(saltLength);
|
|
||||||
assertNotNull(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of getMD5Password method, of class PasswordUtil.
|
* Test of createSaltString method, of class PasswordUtil.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void getMD5Password() throws Exception {
|
public void createSaltString() throws Exception {
|
||||||
System.out.println("getMD5Password");
|
System.out.println("createSaltString");
|
||||||
String plainTextPassword = "";
|
int saltLength = 40;
|
||||||
int saltLength = 40;
|
String result = OldPasswordUtil.createSaltString(saltLength);
|
||||||
String[] result1 = OldPasswordUtil.getMD5Password(plainTextPassword, saltLength);
|
assertNotNull(result);
|
||||||
String password1 = result1[0];
|
}
|
||||||
String salt1 = result1[1];
|
|
||||||
assertNotNull(result1);
|
|
||||||
assertNotNull(password1);
|
|
||||||
assertNotNull(salt1);
|
|
||||||
|
|
||||||
String[] result2 = OldPasswordUtil.getMD5Password(plainTextPassword, saltLength);
|
|
||||||
String password2 = result2[0];
|
|
||||||
String salt2 = result2[1];
|
|
||||||
assertNotNull(result2);
|
|
||||||
assertNotNull(password2);
|
|
||||||
assertNotNull(salt2);
|
|
||||||
|
|
||||||
assertNotSame(result1, result2);
|
|
||||||
assertNotSame(password1, password2);
|
|
||||||
assertNotSame(salt1, salt2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of getMD5Password method, of class PasswordUtil.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void getMD5Password() throws Exception {
|
||||||
|
System.out.println("getMD5Password");
|
||||||
|
String plainTextPassword = "";
|
||||||
|
int saltLength = 40;
|
||||||
|
String[] result1 = OldPasswordUtil.getMD5Password(plainTextPassword, saltLength);
|
||||||
|
String password1 = result1[0];
|
||||||
|
String salt1 = result1[1];
|
||||||
|
assertNotNull(result1);
|
||||||
|
assertNotNull(password1);
|
||||||
|
assertNotNull(salt1);
|
||||||
|
|
||||||
|
String[] result2 = OldPasswordUtil.getMD5Password(plainTextPassword, saltLength);
|
||||||
|
String password2 = result2[0];
|
||||||
|
String salt2 = result2[1];
|
||||||
|
assertNotNull(result2);
|
||||||
|
assertNotNull(password2);
|
||||||
|
assertNotNull(salt2);
|
||||||
|
|
||||||
|
assertNotSame(result1, result2);
|
||||||
|
assertNotSame(password1, password2);
|
||||||
|
assertNotSame(salt1, salt2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test of checkPassword method, of class PasswordUtil.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void checkPassword() throws Exception {
|
||||||
|
System.out.println("checkPassword");
|
||||||
|
String plainTextPassword = "welcome";
|
||||||
|
String plainTextPassword2 = "this is not the correct password";
|
||||||
|
|
||||||
|
String[] data = OldPasswordUtil.getMD5Password(plainTextPassword, 40);
|
||||||
|
String cryptedPassword = data[0];
|
||||||
|
String salt = data[1];
|
||||||
|
|
||||||
|
String salt2 = OldPasswordUtil.createSaltString(40);
|
||||||
|
String salt3 = OldPasswordUtil.createSaltString(10);
|
||||||
|
|
||||||
|
boolean expResult = true;
|
||||||
|
boolean result = OldPasswordUtil.checkPassword(plainTextPassword, cryptedPassword, salt);
|
||||||
|
assertTrue(expResult == result);
|
||||||
|
|
||||||
|
expResult = false;
|
||||||
|
result = OldPasswordUtil.checkPassword(plainTextPassword2, cryptedPassword, salt);
|
||||||
|
assertTrue(expResult == result);
|
||||||
|
|
||||||
|
expResult = false;
|
||||||
|
result = OldPasswordUtil.checkPassword(plainTextPassword, cryptedPassword, salt2);
|
||||||
|
assertTrue(expResult == result);
|
||||||
|
|
||||||
|
expResult = false;
|
||||||
|
result = OldPasswordUtil.checkPassword(plainTextPassword, cryptedPassword, salt3);
|
||||||
|
assertTrue(expResult == result);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Test of checkPassword method, of class PasswordUtil.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void checkPassword() throws Exception {
|
|
||||||
System.out.println("checkPassword");
|
|
||||||
String plainTextPassword = "welcome";
|
|
||||||
String plainTextPassword2 = "this is not the correct password";
|
|
||||||
|
|
||||||
String[] data = OldPasswordUtil.getMD5Password(plainTextPassword, 40);
|
|
||||||
String cryptedPassword = data[0];
|
|
||||||
String salt = data[1];
|
|
||||||
|
|
||||||
String salt2 = OldPasswordUtil.createSaltString(40);
|
|
||||||
String salt3 = OldPasswordUtil.createSaltString(10);
|
|
||||||
|
|
||||||
boolean expResult = true;
|
|
||||||
boolean result = OldPasswordUtil.checkPassword(plainTextPassword, cryptedPassword, salt);
|
|
||||||
assertEquals(expResult, result);
|
|
||||||
|
|
||||||
expResult = false;
|
|
||||||
result = OldPasswordUtil.checkPassword(plainTextPassword2, cryptedPassword, salt);
|
|
||||||
assertEquals(expResult, result);
|
|
||||||
|
|
||||||
expResult = false;
|
|
||||||
result = OldPasswordUtil.checkPassword(plainTextPassword, cryptedPassword, salt2);
|
|
||||||
assertEquals(expResult, result);
|
|
||||||
|
|
||||||
expResult = false;
|
|
||||||
result = OldPasswordUtil.checkPassword(plainTextPassword, cryptedPassword, salt3);
|
|
||||||
assertEquals(expResult, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getRandomString() throws SecurityException {
|
public void getRandomString() throws SecurityException {
|
||||||
System.out.println ("getRandomString");
|
System.out.println("getRandomString");
|
||||||
String randomString = OldPasswordUtil.getRandomString("test-", 32);
|
String randomString = OldPasswordUtil.getRandomString("test-", 32);
|
||||||
System.out.println(randomString);
|
System.out.println(randomString);
|
||||||
assertNotNull(randomString);
|
assertNotNull(randomString);
|
||||||
assertTrue("string must start with prefix", randomString.startsWith("test"));
|
assertTrue(randomString.startsWith("test"), "string must start with prefix");
|
||||||
assertEquals("string length check", 32, randomString.length());
|
assertTrue(32 == randomString.length(), "string length check");
|
||||||
|
|
||||||
String randomString2 = OldPasswordUtil.getRandomString("test-", 32);
|
String randomString2 = OldPasswordUtil.getRandomString("test-", 32);
|
||||||
System.out.println(randomString2);
|
System.out.println(randomString2);
|
||||||
assertNotNull(randomString2);
|
assertNotNull(randomString2);
|
||||||
assertTrue("string must start with prefix", randomString2.startsWith("test"));
|
assertTrue(randomString2.startsWith("test"), "string must start with prefix");
|
||||||
assertEquals("string length check", 32, randomString2.length());
|
assertTrue(32 == randomString2.length(), "string length check");
|
||||||
|
|
||||||
assertNotSame(randomString, randomString2);
|
assertNotSame(randomString, randomString2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getRandomStringBlankPrefix() throws SecurityException {
|
public void getRandomStringBlankPrefix() throws SecurityException {
|
||||||
System.out.println ("getRandomStringBlankPrefix");
|
System.out.println("getRandomStringBlankPrefix");
|
||||||
String randomString = OldPasswordUtil.getRandomString("", 32);
|
String randomString = OldPasswordUtil.getRandomString("", 32);
|
||||||
System.out.println(randomString);
|
System.out.println(randomString);
|
||||||
assertNotNull(randomString);
|
assertNotNull(randomString);
|
||||||
assertEquals("string length check", 32, randomString.length());
|
assertTrue(32 == randomString.length(), "string length check");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getRandomStringNullPrefix() throws SecurityException {
|
public void getRandomStringNullPrefix() throws SecurityException {
|
||||||
System.out.println ("getRandomStringNullPrefix");
|
System.out.println("getRandomStringNullPrefix");
|
||||||
String randomString = OldPasswordUtil.getRandomString(null, 32);
|
String randomString = OldPasswordUtil.getRandomString(null, 32);
|
||||||
System.out.println(randomString);
|
System.out.println(randomString);
|
||||||
assertNotNull(randomString);
|
assertNotNull(randomString);
|
||||||
assertEquals("string length check", 32, randomString.length());
|
assertTrue(32 == randomString.length(), "string length check");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test the hashPassword method
|
* test the hashPassword method
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetScryptHash() {
|
public void testGetScryptHash() {
|
||||||
String hash1 = getScryptHash("secret");
|
String hash1 = getScryptHash("secret");
|
||||||
String hash2 = getScryptHash("secret");
|
String hash2 = getScryptHash("secret");
|
||||||
System.out.println (hash1);
|
System.out.println(hash1);
|
||||||
System.out.println (hash2);
|
System.out.println(hash2);
|
||||||
assertNotNull (hash1);
|
assertNotNull(hash1);
|
||||||
assertNotNull (hash2);
|
assertNotNull(hash2);
|
||||||
// even if password is the same, the has must not be the same due to correct usage of salts
|
// even if password is the same, the has must not be the same due to correct usage of salts
|
||||||
assertFalse (hash1.equals (hash2));
|
assertFalse(hash1.equals(hash2));
|
||||||
|
|
||||||
assertTrue (hash1.length() == 79);
|
assertTrue(hash1.length() == 79);
|
||||||
assertTrue (hash2.length() == 79);
|
assertTrue(hash2.length() == 79);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test for validating passwords
|
* test for validating passwords
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testValidateScryptHash() {
|
public void testValidateScryptHash() {
|
||||||
String hash1 = getScryptHash("secret");
|
String hash1 = getScryptHash("secret");
|
||||||
String hash2 = getScryptHash("secret");
|
String hash2 = getScryptHash("secret");
|
||||||
assertTrue ("hash must match if correct password is given",validateScryptHash("secret", hash1));
|
assertTrue(validateScryptHash("secret", hash1), "hash must match if correct password is given");
|
||||||
assertTrue ("hash must match if correct password is given", validateScryptHash("secret", hash2));
|
assertTrue(validateScryptHash("secret", hash2), "hash must match if correct password is given");
|
||||||
assertFalse ("hash must not match if wrong password is given", validateScryptHash("secret2", hash1));
|
assertFalse(validateScryptHash("secret2", hash1), "hash must not match if wrong password is given");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,11 @@
|
|||||||
package de.muehlencord.shared.security;
|
package de.muehlencord.shared.security;
|
||||||
|
|
||||||
import de.muehlencord.shared.security.PasswordUtil;
|
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import org.bouncycastle.util.encoders.Base64;
|
import org.bouncycastle.util.encoders.Base64;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -18,7 +17,7 @@ public class PasswordUtilTest {
|
|||||||
private static String systemSalt64Coded;
|
private static String systemSalt64Coded;
|
||||||
private static byte[] systemSaltBytes;
|
private static byte[] systemSaltBytes;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void init() {
|
public static void init() {
|
||||||
secureRandom = new SecureRandom();
|
secureRandom = new SecureRandom();
|
||||||
|
|
||||||
|
|||||||
@ -15,7 +15,7 @@ public class NtlmAuthenticatorTest extends BaseTest {
|
|||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // Depends on available sharepoint currently
|
@Disabled // Depends on available sharepoint currently
|
||||||
public void testAuthentication() throws MalformedURLException, NoSuchAlgorithmException, KeyManagementException {
|
public void testAuthentication() throws MalformedURLException, NoSuchAlgorithmException, KeyManagementException {
|
||||||
SPSite instance = new SPSite(getContext());
|
SPSite instance = new SPSite(getContext());
|
||||||
// instance.getRootWeb();
|
// instance.getRootWeb();
|
||||||
|
|||||||
@ -14,7 +14,7 @@ public class SharepointConfigTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // Depends on available sharepoint currently
|
@Disabled // Depends on available sharepoint currently
|
||||||
public void testLoadFromFile() throws Exception {
|
public void testLoadFromFile() throws Exception {
|
||||||
SharepointConfig c = new SharepointConfig();
|
SharepointConfig c = new SharepointConfig();
|
||||||
c.loadFromFile();
|
c.loadFromFile();
|
||||||
|
|||||||
@ -23,7 +23,7 @@ import org.xml.sax.SAXException;
|
|||||||
public class SPListTest extends BaseTest {
|
public class SPListTest extends BaseTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // Depends on available sharepoint currently
|
@Disabled // Depends on available sharepoint currently
|
||||||
public void testFromXML() throws Exception {
|
public void testFromXML() throws Exception {
|
||||||
String xmlString = readFileContentFromTest("lists/testlist.xml", "UTF-8");
|
String xmlString = readFileContentFromTest("lists/testlist.xml", "UTF-8");
|
||||||
SPList list = new SPList(getContext(), "{924883B9-41B7-430C-8206-151786A67319}");
|
SPList list = new SPList(getContext(), "{924883B9-41B7-430C-8206-151786A67319}");
|
||||||
@ -32,7 +32,7 @@ public class SPListTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // Depends on available sharepoint currently
|
@Disabled // Depends on available sharepoint currently
|
||||||
public void addListItemByTitle() throws NoSuchAlgorithmException, KeyManagementException, JAXBException, SAXException, ParserConfigurationException,
|
public void addListItemByTitle() throws NoSuchAlgorithmException, KeyManagementException, JAXBException, SAXException, ParserConfigurationException,
|
||||||
IOException {
|
IOException {
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ public class SPListTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // Depends on available sharepoint currently
|
@Disabled // Depends on available sharepoint currently
|
||||||
public void addListItemBigList() throws NoSuchAlgorithmException, KeyManagementException, JAXBException, SAXException, ParserConfigurationException,
|
public void addListItemBigList() throws NoSuchAlgorithmException, KeyManagementException, JAXBException, SAXException, ParserConfigurationException,
|
||||||
IOException {
|
IOException {
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ public class SPListTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // Depends on available sharepoint currently
|
@Disabled // Depends on available sharepoint currently
|
||||||
public void testGetListItems() throws Exception {
|
public void testGetListItems() throws Exception {
|
||||||
SPLists instance = new SPLists(getContext());
|
SPLists instance = new SPLists(getContext());
|
||||||
SPList list = instance.getSpListByTitle("Questionnaire_Countries");
|
SPList list = instance.getSpListByTitle("Questionnaire_Countries");
|
||||||
@ -111,7 +111,7 @@ public class SPListTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // Depends on available sharepoint currently
|
@Disabled // Depends on available sharepoint currently
|
||||||
public void testGetListItemsQuery() throws Exception {
|
public void testGetListItemsQuery() throws Exception {
|
||||||
SPLists instance = new SPLists(getContext());
|
SPLists instance = new SPLists(getContext());
|
||||||
SPList list = instance.getSpListByTitle("Questionnaire_Countries");
|
SPList list = instance.getSpListByTitle("Questionnaire_Countries");
|
||||||
@ -135,7 +135,7 @@ public class SPListTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // Depends on available sharepoint currently
|
@Disabled // Depends on available sharepoint currently
|
||||||
public void testGetLookupValueMap() throws Exception {
|
public void testGetLookupValueMap() throws Exception {
|
||||||
SPLists instance = new SPLists(getContext());
|
SPLists instance = new SPLists(getContext());
|
||||||
SPList list = instance.getSpListByTitle("Questionnaire_Countries");
|
SPList list = instance.getSpListByTitle("Questionnaire_Countries");
|
||||||
@ -145,7 +145,7 @@ public class SPListTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // Depends on available sharepoint currently
|
@Disabled // Depends on available sharepoint currently
|
||||||
public void testGetColumnNameByDisplayName() throws Exception {
|
public void testGetColumnNameByDisplayName() throws Exception {
|
||||||
SPLists instance = new SPLists(getContext());
|
SPLists instance = new SPLists(getContext());
|
||||||
SPList list = instance.getSpListByTitle("Questionnaire");
|
SPList list = instance.getSpListByTitle("Questionnaire");
|
||||||
@ -153,7 +153,7 @@ public class SPListTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // Depends on available sharepoint currently
|
@Disabled // Depends on available sharepoint currently
|
||||||
public void testGetItemCount() throws Exception {
|
public void testGetItemCount() throws Exception {
|
||||||
SPLists instance = new SPLists(getContext());
|
SPLists instance = new SPLists(getContext());
|
||||||
SPList list = instance.getSpListByTitle("Questionnaire");
|
SPList list = instance.getSpListByTitle("Questionnaire");
|
||||||
|
|||||||
@ -18,7 +18,7 @@ public class SPListsTest extends BaseTest {
|
|||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // Depends on available sharepoint currently
|
@Disabled // Depends on available sharepoint currently
|
||||||
public void testFromXML() throws IOException, JAXBException, SAXException {
|
public void testFromXML() throws IOException, JAXBException, SAXException {
|
||||||
String xmlString = readFileContentFromTest("lists/testlists.xml", "UTF-8");
|
String xmlString = readFileContentFromTest("lists/testlists.xml", "UTF-8");
|
||||||
SPLists lists = new SPLists(getContext());
|
SPLists lists = new SPLists(getContext());
|
||||||
@ -27,7 +27,7 @@ public class SPListsTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // Depends on available sharepoint currently
|
@Disabled // Depends on available sharepoint currently
|
||||||
public void testGetListName() throws Exception {
|
public void testGetListName() throws Exception {
|
||||||
SPLists instance = new SPLists(getContext());
|
SPLists instance = new SPLists(getContext());
|
||||||
String listName = instance.getListNameByTitle("Questionnaire");
|
String listName = instance.getListNameByTitle("Questionnaire");
|
||||||
|
|||||||
@ -18,7 +18,7 @@ public class SPUserGroupTest extends BaseTest {
|
|||||||
private final static Logger LOGGER = LoggerFactory.getLogger(SPUserGroupTest.class.getName());
|
private final static Logger LOGGER = LoggerFactory.getLogger(SPUserGroupTest.class.getName());
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testFromXML() throws Exception {
|
public void testFromXML() throws Exception {
|
||||||
String xmlString = readFileContentFromTest("usergroups/user.xml", "UTF-8");
|
String xmlString = readFileContentFromTest("usergroups/user.xml", "UTF-8");
|
||||||
SPUser user = new SPUser(getContext());
|
SPUser user = new SPUser(getContext());
|
||||||
@ -27,7 +27,7 @@ public class SPUserGroupTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // Depends on available sharepoint currently
|
@Disabled // Depends on available sharepoint currently
|
||||||
public void testGetUserInfo() throws Exception {
|
public void testGetUserInfo() throws Exception {
|
||||||
SPUserGroup ug = new SPUserGroup(getContext());
|
SPUserGroup ug = new SPUserGroup(getContext());
|
||||||
String userId = ug.getUserId("wincor-nixdorf\\joern.muehlencord");
|
String userId = ug.getUserId("wincor-nixdorf\\joern.muehlencord");
|
||||||
@ -35,14 +35,14 @@ public class SPUserGroupTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // Depends on available sharepoint currently
|
@Disabled // Depends on available sharepoint currently
|
||||||
public void testAddUserToGroup() throws Exception {
|
public void testAddUserToGroup() throws Exception {
|
||||||
SPUserGroup ug = new SPUserGroup(getContext());
|
SPUserGroup ug = new SPUserGroup(getContext());
|
||||||
ug.addUserToGroup("wincor-nixdorf\\joern.muehlencord", "Test Group");
|
ug.addUserToGroup("wincor-nixdorf\\joern.muehlencord", "Test Group");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // Depends on available sharepoint currently
|
@Disabled // Depends on available sharepoint currently
|
||||||
public void testIsUserMemberOfGroup() throws Exception {
|
public void testIsUserMemberOfGroup() throws Exception {
|
||||||
SPUserGroup ug = new SPUserGroup(getContext());
|
SPUserGroup ug = new SPUserGroup(getContext());
|
||||||
boolean result = ug.isUserMemberOfGroup("wincor-nixdorf\\joern.muehlencord", "HQ All Members");
|
boolean result = ug.isUserMemberOfGroup("wincor-nixdorf\\joern.muehlencord", "HQ All Members");
|
||||||
@ -50,7 +50,7 @@ public class SPUserGroupTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // Depends on available sharepoint currently
|
@Disabled // Depends on available sharepoint currently
|
||||||
public void getUserLoginNameFromEmail() throws Exception {
|
public void getUserLoginNameFromEmail() throws Exception {
|
||||||
SPUserGroup ug = new SPUserGroup(getContext());
|
SPUserGroup ug = new SPUserGroup(getContext());
|
||||||
SPUser user = ug.getUserFromEmail("joern.muehlencord@wincor-nixdorf.com");
|
SPUser user = ug.getUserFromEmail("joern.muehlencord@wincor-nixdorf.com");
|
||||||
@ -58,7 +58,7 @@ public class SPUserGroupTest extends BaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore // Depends on available sharepoint currently
|
@Disabled // Depends on available sharepoint currently
|
||||||
public void getUserFromEmail() throws Exception {
|
public void getUserFromEmail() throws Exception {
|
||||||
SPUserGroup ug = new SPUserGroup(getContext());
|
SPUserGroup ug = new SPUserGroup(getContext());
|
||||||
String user1Email = "nicole.cravo@wincor-nixdorf.com";
|
String user1Email = "nicole.cravo@wincor-nixdorf.com";
|
||||||
|
|||||||
@ -22,8 +22,8 @@
|
|||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@ -2,8 +2,6 @@ package de.muehlencord.shared.util;
|
|||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|||||||
@ -7,8 +7,9 @@ package de.muehlencord.shared.util;
|
|||||||
|
|
||||||
import static de.muehlencord.shared.util.OSUtil.getOperationSystem;
|
import static de.muehlencord.shared.util.OSUtil.getOperationSystem;
|
||||||
import static java.lang.System.getProperties;
|
import static java.lang.System.getProperties;
|
||||||
import org.junit.Test;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@ -6,8 +6,8 @@
|
|||||||
|
|
||||||
package de.muehlencord.shared.util;
|
package de.muehlencord.shared.util;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.junit.Assert.*;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@ -3,8 +3,8 @@ package de.muehlencord.shared.util;
|
|||||||
import static de.muehlencord.shared.util.StringUtil.getValueBetweenKeywords;
|
import static de.muehlencord.shared.util.StringUtil.getValueBetweenKeywords;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic StringUtilTests
|
* Basic StringUtilTests
|
||||||
@ -18,6 +18,6 @@ public class StringUtilTest extends DefaultTest {
|
|||||||
String content = readContentFromFile("test.txt");
|
String content = readContentFromFile("test.txt");
|
||||||
|
|
||||||
String ipAddress = getValueBetweenKeywords(content, "The IP", "has just");
|
String ipAddress = getValueBetweenKeywords(content, "The IP", "has just");
|
||||||
assertEquals("ipAddress", "222.184.230.118", ipAddress);
|
assertEquals("222.184.230.118", ipAddress, "ipAddress");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,8 +7,8 @@ import java.net.URISyntaxException;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.junit.Ignore;
|
import org.junit.jupiter.api.Disabled;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -22,7 +22,7 @@ public class FileUtilTest {
|
|||||||
* @throws URISyntaxException if the testfile specification is wrong
|
* @throws URISyntaxException if the testfile specification is wrong
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Disabled
|
||||||
public void testGetFilesFromDirecotry() throws FileHandlingException, URISyntaxException {
|
public void testGetFilesFromDirecotry() throws FileHandlingException, URISyntaxException {
|
||||||
System.out.println("testGetFilesFromDirectory");
|
System.out.println("testGetFilesFromDirectory");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user