diff options
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/db')
3 files changed, 46 insertions, 49 deletions
diff --git a/src/main/java/org/openslx/imagemaster/db/DbSatellite.java b/src/main/java/org/openslx/imagemaster/db/DbSatellite.java index 65450ed..a1c9b1a 100644 --- a/src/main/java/org/openslx/imagemaster/db/DbSatellite.java +++ b/src/main/java/org/openslx/imagemaster/db/DbSatellite.java @@ -17,7 +17,7 @@ public class DbSatellite { private static final Logger LOG = Logger.getLogger( DbSatellite.class ); - private String organization, address, name, prefix, publickeyString; + private String organizationId, address, name, publickeyString; private PublicKey publickey = null; private static final KeyFactory keyFact; @@ -33,31 +33,44 @@ public class DbSatellite } // needs to be public in order to be found by MySQL - public DbSatellite( String organization, String address, String name, String prefix, String publickeyString ) + public DbSatellite( String organizationId, String address, String name, String prefix, String publickeyString ) { - this.organization = organization; + this.organizationId = organizationId; this.address = address; this.name = name; - this.prefix = prefix; this.publickeyString = publickeyString; } - public static DbSatellite fromOrganization( String organization ) + public static DbSatellite fromOrganizationId( String organizationId ) { return MySQL .findUniqueOrNull( DbSatellite.class, - "SELECT satellite.organization, satellite.address, satellite.name, satellite.prefix, satellite.publickey FROM satellite WHERE satellite.organization = ? LIMIT 1", - organization ); + "SELECT satellite.organizationid, satellite.address, satellite.name, satellite.publickey FROM satellite WHERE satellite.organizationid = ? LIMIT 1", + organizationId ); + } + + public static DbSatellite fromSuffix( String suffix ) + { + return MySQL + .findUniqueOrNull( + DbSatellite.class, + "SELECT satellite.organizationid, satellite.address, satellite.name, satellite.publickey FROM satellite" + + " INNER JOIN satellite_suffix USING (organizationid)" + + " WHERE satellite_suffix.suffix = ? LIMIT 1", + suffix ); } public static DbSatellite fromPrefix( String prefix ) { + /* return MySQL .findUniqueOrNull( DbSatellite.class, - "SELECT satellite.organization, satellite.address, satellite.name, satellite.prefix, satellite.publickey FROM satellite WHERE satellite.prefix = ? LIMIT 1", + "SELECT satellite.organization, satellite.address, satellite.name, satellite.publickey FROM satellite WHERE satellite.prefix = ? LIMIT 1", prefix ); + */ + return null; } public String getAddress() @@ -70,14 +83,9 @@ public class DbSatellite return name; } - public String getOrganization() - { - return organization; - } - - public String getPrefix() + public String getOrganizationId() { - return this.prefix; + return organizationId; } /** @@ -99,9 +107,9 @@ public class DbSatellite publickey = keyFact.generatePublic( keySpec ); } } catch ( InvalidKeySpecException e ) { - LOG.info( "PubKey of " + this.organization + " is not valid.", e ); + LOG.info( "PubKey of " + this.name + " is not valid.", e ); } catch ( NumberFormatException e ) { - LOG.info( "PubKey of " + this.organization + " is corrupted in database!", e ); + LOG.info( "PubKey of " + this.name + " is corrupted in database!", e ); } } return publickey; diff --git a/src/main/java/org/openslx/imagemaster/db/DbUser.java b/src/main/java/org/openslx/imagemaster/db/DbUser.java index c486da3..b822e4d 100644 --- a/src/main/java/org/openslx/imagemaster/db/DbUser.java +++ b/src/main/java/org/openslx/imagemaster/db/DbUser.java @@ -12,11 +12,11 @@ public class DbUser extends User private static Logger log = Logger.getLogger( DbUser.class ); - public DbUser( int userId, String username, String password, String organization, + public DbUser( int userId, String eppn, String password, String organizationId, String firstName, String lastName, String eMail, String satelliteAddress ) { - super( userId, username, password, organization, firstName, lastName, eMail, + super( userId, eppn, password, organizationId, firstName, lastName, eMail, satelliteAddress ); } @@ -24,22 +24,19 @@ public class DbUser extends User * Query database for user with given login * * @param login - * (user@organization) + * (user@organizationSuffix) * @return instance of DbUser for matching entry from DB, or null if not * found */ public static DbUser forLogin( final String login ) { - final String[] parts = login.split( "@" ); - if ( parts.length != 2 ) - return null; return MySQL .findUniqueOrNull( DbUser.class, - "SELECT user.userid, user.username, user.password, user.organization, user.firstname, user.lastname, user.email, satellite.address FROM user" - + " LEFT JOIN satellite USING (organization)" - + " WHERE user.username = ? AND user.organization = ? LIMIT 1", - parts[0], parts[1] ); + "SELECT user.userid, user.eppn, user.password, user.organizationid, user.firstname, user.lastname, user.email, satellite.address FROM user" + + " LEFT JOIN satellite USING (organizationid)" + + " WHERE user.eppn = ? LIMIT 1", + login ); } /** @@ -54,8 +51,8 @@ public class DbUser extends User return MySQL .findUniqueOrNull( DbUser.class, - "SELECT user.userid, user.username, user.password, user.organization, user.firstname, user.lastname, user.email, satellite.address FROM user" - + " LEFT JOIN satellite USING (organization)" + "SELECT user.userid, user.eppn, user.password, user.organizationid, user.firstname, user.lastname, user.email, satellite.address FROM user" + + " LEFT JOIN satellite USING (organizationid)" + " WHERE user.userid = ? LIMIT 1", userid ); } @@ -75,21 +72,17 @@ public class DbUser extends User public static boolean insertOrUpdate( User user ) { - log.debug( "Inserted user '" + user.username + "' into db." ); + log.debug( "Inserted user '" + user.eppn + "' into db." ); MySQL.update( - "INSERT INTO user (username, password, organization, firstname, lastname, email) VALUES (?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE password=VALUES(password), organization=VALUES(organization), firstname=VALUES(firstname), lastname=VALUES(lastname), email=VALUES(email)", - user.username, user.password, user.organization, user.firstName, user.lastName, user.eMail ); + "INSERT INTO user (eppn, password, organizationid, firstname, lastname, email) VALUES (?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE password=VALUES(password), organizationid=VALUES(organizationid), firstname=VALUES(firstname), lastname=VALUES(lastname), email=VALUES(email)", + user.eppn, user.password, user.organizationId, user.firstName, user.lastName, user.eMail ); return false; } + /* public static int getUserIdByName( String username ) { - DbUser user = MySQL - .findUniqueOrNull( - DbUser.class, - "SELECT user.userid, user.username, user.password, user.organization, user.firstname, user.lastname, user.email, satellite.address FROM user" - + " LEFT JOIN satellite USING (organization)" - + " WHERE user.username = ? LIMIT 1", username ); + DbUser user = forLogin( username ); if ( user == null ) return 0; return user.userId; @@ -97,15 +90,11 @@ public class DbUser extends User public static String getUserNameById( int id ) { - DbUser user = MySQL - .findUniqueOrNull( - DbUser.class, - "SELECT user.userid, user.username, user.password, user.organization, user.firstname, user.lastname, user.email, satellite.address FROM user" - + " LEFT JOIN satellite USING (organization)" - + " WHERE user.userid = ? LIMIT 1", id ); + DbUser user = forLogin( id ); if ( user == null ) - return ""; + return null; return user.username; } + */ } diff --git a/src/main/java/org/openslx/imagemaster/db/LdapUser.java b/src/main/java/org/openslx/imagemaster/db/LdapUser.java index 2812755..b026e7e 100644 --- a/src/main/java/org/openslx/imagemaster/db/LdapUser.java +++ b/src/main/java/org/openslx/imagemaster/db/LdapUser.java @@ -105,7 +105,7 @@ public class LdapUser extends User eMail = entry.get( "mail" ).getString(); // get the satellite address from db - DbSatellite dbSatellite = DbSatellite.fromOrganization( organization ); + DbSatellite dbSatellite = DbSatellite.fromSuffix( organization ); if ( dbSatellite != null ) { satelliteAddress = dbSatellite.getAddress(); } else { @@ -118,7 +118,7 @@ public class LdapUser extends User if ( e.getMessage().contains( "Cannot connect on the server" ) ) { DbSatellite dbSatellite = DbSatellite.fromPrefix(split[0]); if (dbSatellite == null) throw new AuthenticationException(AuthenticationError.INVALID_CREDENTIALS, "Credentials invalid."); - String lo = split[1] + "@" + dbSatellite.getOrganization(); + String lo = split[1] + "@" + dbSatellite.getOrganizationId(); log.info( "LDAP server could not be reached. Trying to connect locally with: " + lo ); return LdapUser.localLogin(lo, password); } @@ -150,7 +150,7 @@ public class LdapUser extends User /** * Login user locally if external Ldap server is not available - * @param username Must be in form "username@organization" + * @param eppn Must be in form "username@organization" * @param password The user's password */ private static LdapUser localLogin( String login, String password ) @@ -162,7 +162,7 @@ public class LdapUser extends User if (!Sha512Crypt.verifyPassword( password, user.password )) return null; // return ldapuser if valid - return new LdapUser( user.userId, user.username, Sha512Crypt.Sha512_crypt( password, null, 0 ), user.organization, user.firstName, + return new LdapUser( user.userId, user.eppn, Sha512Crypt.Sha512_crypt( password, null, 0 ), user.organizationId, user.firstName, user.lastName, user.eMail, user.satelliteAddress ); } } |