Created
October 19, 2012 13:59
-
-
Save cbmeeks/3918368 to your computer and use it in GitHub Desktop.
Portal User Interface
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// not real code...but you get the idea | |
public interface PortalUserService { | |
public PortalUser get(int id); | |
public PortalUser updatePassword(PortalUser paUser, String paNewPassword); | |
} | |
public class PortalUser { | |
String username; | |
String password; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Notice we are IMPLEMENTING a PortalUser here. Which requires us implement the "get" and "updatePassword" methods. | |
// PortalUserService could care less on HOW we change the password. Just so as long as we provide a method to do so | |
// Also, this makes KKMSUser == PortalUser. They can be used interchangeably | |
// And since KKMS users are NOT stored in the same database as the Portal's users, | |
// the Portal can still work with KKMS users because of this interface. This "Impl" is telling Portal HOW to handle KKMS users. | |
// Plus, since the Portal would probably have multiple database connections, the "kkmsService" below would point the SQL Server DB. | |
// Once again, Portal could care less. But the Portal would be able to use KKMS users as if they were all in the same database. :-) | |
public class KKMSUserImpl implements PortalUserService { | |
String username; | |
String password; // this must be 10 characters | |
public KKMSUser get(int id) { | |
return kkmsService.getUserById(id); // kkmsService would have been Autowired | |
} | |
public KKMSUser updatePassword(KKMSUser paUser, String paNewPassword) { | |
// remember, the portal has no idea WHERE or HOW this KKMS user is handled. We are TELLING it here. | |
// also, let's pretend that KKMS requires 10 characters for password. Portal doesn't know about this. Doesn't care. | |
// but if you try to update a user that is of type KKMS, and the password < 10 characters, portal automatically knows there's a problem | |
if(paNewPassword.length < 10) { | |
throw new PasswordLengthInvalidException(); | |
} | |
kkmsService.updatePassword(paNewPassword); | |
return paUser; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Here, we are implementing a YMS version of a Portal User. | |
// Let's pretend that YMS is super strict and requires 12 characters in password and it must start with the letter 'A' | |
public class YMSUserImpl implements PortalUserService { | |
String username; | |
String password; // must be 12 characters and start with the letter 'A' | |
public YMSUser get(int id) { | |
return ymsservice.getUserById(int id); | |
} | |
public YMSUser updatePassword(YMSUser paUser, String paNewPassword) { | |
if(paNewPassword.length < 12) { | |
throw new PasswordLengthInvalidException(); | |
} | |
if( ! paNewPassword.startsWith('A') ) { | |
throw new PasswordValidationException(); | |
} | |
ymsService.updatePassword(paNewPassword); | |
return paUser; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment