Commit e55711f4 authored by Matija Obreza's avatar Matija Obreza

Source formatting

parent 61c0b948
......@@ -26,38 +26,42 @@ public class ReCaptchaImpl implements ReCaptcha {
public static final String PROPERTY_THEME = "theme";
public static final String PROPERTY_TABINDEX = "tabindex";
public static final String HTTP_SERVER = "http://www.google.com/recaptcha/api";
public static final String HTTPS_SERVER = "https://www.google.com/recaptcha/api";
// HTTPS Verify url
public static final String VERIFY_URL = "https://www.google.com/recaptcha/api/verify";
private String privateKey;
private String publicKey;
private String recaptchaServer = HTTP_SERVER;
private boolean includeNoscript = false;
private HttpLoader httpLoader = new SimpleHttpLoader();
public void setPrivateKey(String privateKey) {
this.privateKey = privateKey;
}
public void setPublicKey(String publicKey) {
this.publicKey = publicKey;
}
public void setRecaptchaServer(String recaptchaServer) {
this.recaptchaServer = recaptchaServer;
}
public void setIncludeNoscript(boolean includeNoscript) {
this.includeNoscript = includeNoscript;
}
public void setHttpLoader(HttpLoader httpLoader) {
this.httpLoader = httpLoader;
this.httpLoader = httpLoader;
}
public ReCaptchaResponse checkAnswer(String remoteAddr, String challenge, String response) {
String postParameters = "privatekey=" + URLEncoder.encode(privateKey) + "&remoteip=" + URLEncoder.encode(remoteAddr) +
"&challenge=" + URLEncoder.encode(challenge) + "&response=" + URLEncoder.encode(response);
String postParameters = "privatekey=" + URLEncoder.encode(privateKey) + "&remoteip=" + URLEncoder.encode(remoteAddr) + "&challenge="
+ URLEncoder.encode(challenge) + "&response=" + URLEncoder.encode(response);
String message = httpLoader.httpPost(VERIFY_URL, postParameters);
......@@ -77,7 +81,7 @@ public class ReCaptchaImpl implements ReCaptcha {
else
errorMessage = "recaptcha4j-missing-error-message";
}
return new ReCaptchaResponse(valid, errorMessage);
}
......@@ -90,17 +94,16 @@ public class ReCaptchaImpl implements ReCaptcha {
message += "<script type=\"text/javascript\" src=\"" + recaptchaServer + "/challenge?k=" + publicKey + errorPart + "\"></script>\r\n";
if (includeNoscript) {
String noscript = "<noscript>\r\n" +
" <iframe src=\""+recaptchaServer+"/noscript?k="+publicKey + errorPart + "\" height=\"300\" width=\"500\" frameborder=\"0\"></iframe><br>\r\n" +
" <textarea name=\"recaptcha_challenge_field\" rows=\"3\" cols=\"40\"></textarea>\r\n" +
" <input type=\"hidden\" name=\"recaptcha_response_field\" value=\"manual_challenge\">\r\n" +
"</noscript>";
String noscript = "<noscript>\r\n" + " <iframe src=\"" + recaptchaServer + "/noscript?k=" + publicKey + errorPart
+ "\" height=\"300\" width=\"500\" frameborder=\"0\"></iframe><br>\r\n"
+ " <textarea name=\"recaptcha_challenge_field\" rows=\"3\" cols=\"40\"></textarea>\r\n"
+ " <input type=\"hidden\" name=\"recaptcha_response_field\" value=\"manual_challenge\">\r\n" + "</noscript>";
message += noscript;
}
return message;
}
public String createRecaptchaHtml(String errorMessage, String theme, Integer tabindex) {
Properties options = new Properties();
......@@ -127,19 +130,17 @@ public class ReCaptchaImpl implements ReCaptcha {
return "";
}
String jsOptions =
"<script type=\"text/javascript\">\r\n" +
"var RecaptchaOptions = {";
for (Enumeration e = properties.keys(); e.hasMoreElements(); ) {
String jsOptions = "<script type=\"text/javascript\">\r\n" + "var RecaptchaOptions = {";
for (Enumeration e = properties.keys(); e.hasMoreElements();) {
String property = (String) e.nextElement();
jsOptions += property + ":'" + properties.getProperty(property)+"'";
jsOptions += property + ":'" + properties.getProperty(property) + "'";
if (e.hasMoreElements()) {
jsOptions += ",";
}
}
jsOptions += "};\r\n</script>\r\n";
......
......@@ -49,7 +49,7 @@ public class FaoInstituteBridge implements FieldBridge {
if (institute.getAccessionCount() > 0)
field.setBoost(2 * luceneOptions.getBoost());
document.add(field);
}
......
......@@ -18,7 +18,7 @@ package org.genesys2.server.model;
public enum UserRole {
USER("User"), ADMINISTRATOR("Administrator"), ORGANIZATION_ADMINISTRATOR("Organization Administrator"), NETWORK_ADMINISTRATOR("Network Administrator"), VALIDATEDUSER(
"Validated user"),VETTEDUSER("Vetted user");
"Validated user"), VETTEDUSER("Vetted user");
String label;
......
......@@ -26,7 +26,7 @@ import javax.persistence.UniqueConstraint;
import org.genesys2.server.model.BusinessModel;
@Entity
@Table(name = "accessiontrait", uniqueConstraints = { @UniqueConstraint(name="UQ_accessiontrait_all", columnNames = { "metadataId", "accessionId", "methodId" }) })
@Table(name = "accessiontrait", uniqueConstraints = { @UniqueConstraint(name = "UQ_accessiontrait_all", columnNames = { "metadataId", "accessionId", "methodId" }) })
public class AccessionTrait extends BusinessModel {
private static final long serialVersionUID = -240056837800843686L;
......
......@@ -173,7 +173,6 @@ public class Metadata extends VersionedAuditedModel implements AclAwareModel, Ge
this.uuid = uuid;
}
@Override
public String toString() {
return MessageFormat.format("Metadata id={0,number,#} inst={2} title={1}", id, title, instituteCode);
......
......@@ -25,7 +25,7 @@ import javax.persistence.UniqueConstraint;
import org.genesys2.server.model.BusinessModel;
@Entity
@Table(name = "metadataaccession", uniqueConstraints = { @UniqueConstraint(name="UI_metadataaccession_all", columnNames = { "metadataId", "accessionId" }) })
@Table(name = "metadataaccession", uniqueConstraints = { @UniqueConstraint(name = "UI_metadataaccession_all", columnNames = { "metadataId", "accessionId" }) })
public class MetadataAccession extends BusinessModel {
private static final long serialVersionUID = -240056837800843686L;
......
......@@ -217,7 +217,7 @@ public class User extends BusinessModel {
// We don't support password expiration
return false;
}
public boolean hasRole(String roleName) {
for (UserRole userRole : getRoles()) {
if (userRole.getName().equalsIgnoreCase(roleName)) {
......
......@@ -41,7 +41,6 @@ public interface AccessionTraitRepository extends JpaRepository<AccessionTrait,
List<AccessionTrait> findByMetadataIdAndAccession(Long id, Accession accession);
@Query("select count(id) from AccessionTrait at where at.metadataId = ?1 and at.accession = ?2")
long countByMetadataAndAccessionId(long metadataId, Accession accession);
......
......@@ -277,7 +277,7 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
}
}, rowCallbackHandler);
}
@Override
public void listMetadataAccessions(final long id, RowCallbackHandler rowCallbackHandler) {
jdbcTemplate.query(new PreparedStatementCreator() {
......@@ -292,14 +292,13 @@ public class GenesysLowlevelRepositoryImpl implements GenesysLowlevelRepository
}
}, rowCallbackHandler);
}
@Override
public void listAccessionsAccenames(RowCallbackHandler rowCallbackHandler) {
jdbcTemplate.query(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
PreparedStatement stmt = con
.prepareStatement("select accessionId, names, otherIds from accessionname");
PreparedStatement stmt = con.prepareStatement("select accessionId, names, otherIds from accessionname");
// Set mysql JConnector to stream results
stmt.setFetchSize(Integer.MIN_VALUE);
return stmt;
......
......@@ -341,16 +341,17 @@ public class TraitValueRepositoryImpl implements TraitValueRepository {
return this.jdbcTemplate.queryForObject(String.format("SELECT COUNT(*) FROM `%s` WHERE metadataId=? AND accessionId=?", methodId), Integer.class,
metadataId, accessionId);
}
@Override
public Map<String, Long> getStatistics(Method method) {
final HashMap<String, Long> stats=new HashMap<String, Long>();
this.jdbcTemplate.query(MessageFormat.format("SELECT `{0}`, COUNT(*) FROM `{1,number,#}` GROUP BY `{0}`", method.getFieldName(), method.getId()), new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException {
stats.put(rs.getString(1), rs.getLong(2));
}
});
final HashMap<String, Long> stats = new HashMap<String, Long>();
this.jdbcTemplate.query(MessageFormat.format("SELECT `{0}`, COUNT(*) FROM `{1,number,#}` GROUP BY `{0}`", method.getFieldName(), method.getId()),
new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException {
stats.put(rs.getString(1), rs.getLong(2));
}
});
return stats;
}
}
......@@ -16,6 +16,9 @@
package org.genesys2.server.service;
import java.util.List;
import java.util.Map;
import org.genesys2.server.model.AclAwareModel;
import org.genesys2.server.model.acl.AclEntry;
import org.genesys2.server.model.acl.AclObjectIdentity;
......@@ -23,48 +26,45 @@ import org.genesys2.server.model.acl.AclSid;
import org.genesys2.server.security.AuthUserDetails;
import org.springframework.security.acls.model.Permission;
import java.util.List;
import java.util.Map;
public interface AclService {
void addCreatorPermissions(AclAwareModel target);
void addCreatorPermissions(AclAwareModel target);
/**
/**
* List ObjectIdentities of specified class for user with specified
* permission
*
* @param clazz
* @param authUser
* @return
*/
List<Long> listIdentitiesForSid(Class<? extends AclAwareModel> clazz, AuthUserDetails authUser, Permission permission);
*
* @param clazz
* @param authUser
* @return
*/
List<Long> listIdentitiesForSid(Class<? extends AclAwareModel> clazz, AuthUserDetails authUser, Permission permission);
AclObjectIdentity getObjectIdentity(long id);
AclObjectIdentity getObjectIdentity(long id);
AclObjectIdentity getObjectIdentity(String clazz, long id);
AclObjectIdentity getObjectIdentity(String clazz, long id);
AclObjectIdentity ensureObjectIdentity(String clazz, long id);
AclObjectIdentity ensureObjectIdentity(String clazz, long id);
AclObjectIdentity getObjectIdentity(AclAwareModel entity);
AclObjectIdentity getObjectIdentity(AclAwareModel entity);
List<AclEntry> getAclEntries(AclObjectIdentity objectIdentity);
List<AclEntry> getAclEntries(AclObjectIdentity objectIdentity);
List<AclEntry> getAclEntries(AclAwareModel entity);
List<AclEntry> getAclEntries(AclAwareModel entity);
Permission[] getAvailablePermissions(String className);
Permission[] getAvailablePermissions(String className);
List<AclSid> getSids(AclAwareModel entity);
List<AclSid> getSids(AclAwareModel entity);
List<AclSid> getSids(long id, String className);
List<AclSid> getSids(long id, String className);
Map<String, Map<Integer, Boolean>> getPermissions(AclAwareModel entity);
Map<String, Map<Integer, Boolean>> getPermissions(long id, String className);
boolean addPermissions(long objectIdIdentity, String className, String uuid, boolean principal, Map<Integer, Boolean> permissions);
boolean addPermissions(long objectIdIdentity, String className, String uuid, boolean principal, Map<Integer, Boolean> permissions);
void updatePermission(AclObjectIdentity entity, String sid, Map<Integer, Boolean> permissionMap);
void updatePermission(AclObjectIdentity entity, String sid, Map<Integer, Boolean> permissionMap);
List<AclSid> getAllSids();
List<AclSid> getAllSids();
}
......@@ -25,8 +25,7 @@ public interface EMailVerificationService {
void sendPasswordResetEmail(User user);
void cancelValidation(String tokenUuid);
boolean validateEMail(String tokenUuid, String key);
boolean changePassword(String tokenUuid, String key, String password);
......
......@@ -28,7 +28,8 @@ import com.fasterxml.jackson.databind.JsonNode;
public interface GenesysFilterService {
String[] DEFAULT_FILTERS = { "crop", "genus", "taxon", "origin", "lat", "lon", "organization", "institute", "accenumb", "inSvalbard", "mls", "inTrust", "available" };
String[] DEFAULT_FILTERS = { "crop", "genus", "taxon", "origin", "lat", "lon", "organization", "institute", "accenumb", "inSvalbard", "mls", "inTrust",
"available" };
Page<Accession> listAccessions(JsonNode jsonTree, Pageable pageable);
......
......@@ -16,17 +16,17 @@
package org.genesys2.server.service;
import java.util.Collection;
import org.genesys2.server.model.oauth.OAuthAccessToken;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.ClientRegistrationService;
import java.util.Collection;
public interface OAuth2ClientDetailsService extends ClientDetailsService, ClientRegistrationService {
boolean exists(String clientId);
Collection<OAuthAccessToken> findTokensByClientId(String clientId);
Collection<OAuthAccessToken> findTokensByClientId(String clientId);
Collection<OAuthAccessToken> findTokensByUserUuid(String uuid);
Collection<OAuthAccessToken> findTokensByUserUuid(String uuid);
}
......@@ -20,9 +20,8 @@ import java.util.Set;
import org.genesys2.server.service.impl.EasySMTAConnector.EasySMTAUserData;
public interface RequestService {
void sendRequest(EasySMTAUserData pid, Set<Long> accessionIds);
}
......@@ -24,7 +24,7 @@ import org.springframework.data.domain.Pageable;
public interface SearchService {
Page<?> search(String searchQuery, String[] fields, Pageable pageable, Class<?> ... targetClass) throws SearchException;
Page<?> search(String searchQuery, String[] fields, Pageable pageable, Class<?>... targetClass) throws SearchException;
<T> List<T> autocomplete(String searchQuery, Class<T> clazz);
......
......@@ -16,6 +16,8 @@
package org.genesys2.server.service;
import java.util.List;
import org.genesys2.server.model.impl.FaoInstitute;
import org.genesys2.server.model.impl.Team;
import org.genesys2.server.model.impl.User;
......@@ -24,8 +26,6 @@ import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.security.access.prepost.PreAuthorize;
import java.util.List;
public interface TeamService {
/**
......@@ -100,6 +100,6 @@ public interface TeamService {
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#team, 'READ')")
List<User> getMembers(Team team);
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#team, 'WRITE')")
void updateTeamInformation(String teamUuid, String teamName);
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#team, 'WRITE')")
void updateTeamInformation(String teamUuid, String teamName);
}
......@@ -33,7 +33,7 @@ public interface UserService {
@PreAuthorize("hasRole('ADMINISTRATOR') || hasPermission(#user, 'WRITE')")
void updateUser(User user) throws UserException;
// @PreAuthorize("hasRole('ADMINISTRATOR') || principal.user.id == #userId")
// @PreAuthorize("hasRole('ADMINISTRATOR') || principal.user.id == #userId")
void updatePassword(long userId, String rawPassword) throws UserException;
@PreAuthorize("hasRole('ADMINISTRATOR') || hasPermission(#user, 'WRITE')")
......@@ -72,5 +72,5 @@ public interface UserService {
void userEmailValidated(String uuid);
void addVettedUserRole(String uuid);
void addVettedUserRole(String uuid);
}
......@@ -16,7 +16,12 @@
package org.genesys2.server.service.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.ehcache.CacheManager;
import org.genesys2.server.aspect.AsAdminAspect;
import org.genesys2.server.model.AclAwareModel;
import org.genesys2.server.model.acl.AclClass;
......@@ -40,10 +45,6 @@ import org.springframework.security.acls.model.Permission;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* TODO Add support for cleaning up after objects are removed
*/
......
......@@ -64,8 +64,7 @@ public class ContentServiceImpl implements ContentService {
@Autowired
private VelocityEngine velocityEngine;
@Override
public Locale getDefaultLocale() {
return Locale.getDefault();
......
......@@ -16,6 +16,10 @@
package org.genesys2.server.service.impl;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.oauth.OAuthAccessToken;
......@@ -35,10 +39,6 @@ import org.springframework.security.oauth2.provider.NoSuchClientException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@Service("clientDetails")
@Transactional
public class OAuth2ClientDetailsServiceImpl implements OAuth2ClientDetailsService {
......@@ -47,8 +47,8 @@ public class OAuth2ClientDetailsServiceImpl implements OAuth2ClientDetailsServic
@Autowired
private OAuthClientDetailsPersistence clientDetailsPersistence;
@Autowired
private OAuthAccessTokenPersistence accessTokenPersistence;
@Autowired
private OAuthAccessTokenPersistence accessTokenPersistence;
private PasswordEncoder passwordEncoder = NoOpPasswordEncoder.getInstance();
......@@ -63,15 +63,15 @@ public class OAuth2ClientDetailsServiceImpl implements OAuth2ClientDetailsServic
this.passwordEncoder = passwordEncoder;
}
@Override
public Collection<OAuthAccessToken> findTokensByClientId(String clientId) {
return accessTokenPersistence.findByClientId(clientId);
}
@Override
public Collection<OAuthAccessToken> findTokensByClientId(String clientId) {
return accessTokenPersistence.findByClientId(clientId);
}
@Override
public Collection<OAuthAccessToken> findTokensByUserUuid(String uuid) {
return accessTokenPersistence.findByUserName(uuid);
}
@Override
public Collection<OAuthAccessToken> findTokensByUserUuid(String uuid) {
return accessTokenPersistence.findByUserName(uuid);
}
@Override
public ClientDetails loadClientByClientId(String clientId) throws InvalidClientException {
......
......@@ -282,7 +282,7 @@ public class OAuth2JPATokenStoreImpl implements JPATokenStore {
persisted.setClientId(authentication.getAuthorizationRequest().getClientId());
persisted.setAuthentication(serializeAuthentication(authentication));
persisted.setRefreshToken(extractTokenKey(refreshToken));
persisted.setCreatedDate(new Date());
persisted.setCreatedDate(new Date());
accessTokenPersistence.save(persisted);
}
......
......@@ -51,7 +51,7 @@ public class RequestServiceImpl implements RequestService {
@Value("${base.url}")
private String baseUrl;
@Value("${mail.requests.to}")
private String requestsEmail;
......
......@@ -16,6 +16,10 @@
package org.genesys2.server.service.impl;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.model.impl.FaoInstitute;
......@@ -33,10 +37,6 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@Service
@Transactional(readOnly = true)
public class TeamServiceImpl implements TeamService {
......@@ -77,7 +77,7 @@ public class TeamServiceImpl implements TeamService {
@Transactional(readOnly = false)
@PreAuthorize("hasRole('ADMINISTRATOR') || hasPermission(#team, 'CREATE')")
public Team addTeamMember(String teamUuid, User user) {
Team team = teamRepository.findOneByUuid(teamUuid);
Team team = teamRepository.findOneByUuid(teamUuid);
if (team.getMembers().contains(user)) {
LOG.info("User already member of this team");
return team;
......@@ -94,7 +94,7 @@ public class TeamServiceImpl implements TeamService {
@PreAuthorize("hasRole('ADMINISTRATOR') || hasPermission(#team, 'CREATE')")
@Transactional(readOnly = false)
public Team removeTeamMember(String teamUuid, User user) {
Team team = teamRepository.findOneByUuid(teamUuid);
Team team = teamRepository.findOneByUuid(teamUuid);
if (team.getMembers().remove(user)) {
teamRepository.save(team);
LOG.info("Removed " + user + " from " + team);
......@@ -177,11 +177,11 @@ public class TeamServiceImpl implements TeamService {
return teamRepository.listMembers(team);
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#team, 'WRITE')")
public void updateTeamInformation(String teamUuid, String teamName) {
Team team = teamRepository.findOneByUuid(teamUuid);
team.setName(teamName);
teamRepository.saveAndFlush(team);
}
@Override
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#team, 'WRITE')")
public void updateTeamInformation(String teamUuid, String teamName) {
Team team = teamRepository.findOneByUuid(teamUuid);
team.setName(teamName);
teamRepository.saveAndFlush(team);
}
}
......@@ -16,6 +16,12 @@
package org.genesys2.server.service.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.exception.NoUserFoundException;
......@@ -46,8 +52,6 @@ import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
@Service
@Transactional(readOnly = true)
public class UserServiceImpl implements UserService {
......@@ -349,23 +353,22 @@ public class UserServiceImpl implements UserService {