简体   繁体   中英

Designing a java GUI program with user access control

I want to make an application in java that has a GUI and a database. I will be using MYSQL as the database and my recent experience with JavaFX has been quite pleasant so that's what I'll be using to code.

My issue is I want user access control and want to show GUI components based on who or what type of user logs in.

So let us say it's a school management system and if a teacher logs in the teacher can access his or her course and homework assignments ( via GUI of course) but not any other teacher's. If an admin user logs in he/she can make changes to student profile, etc. but nothing else.

Could someone point me in the right direction with regards to concepts, tutorials, books, sample code, etc. so I can accomplish something like this

if(user==teacher){
    stage.setscene(teacherOnlyScene);
    stage.show();
}

Thank you so much! Apologies if its too subjective. This is the one site that I use like 90% of the time for answers to all my programming related questions.

The scope of your question is probably too large to be successfully answered here as you are asking about a fairly sizeable and potentially complex portion of the architecture of your final system. User access systems are generally quite complex especially if they are highly configurable eg you can grant users privileges outside their basic group privileges etc.

Before starting to write any code have a think about what you want to achieve. You've already come up with the idea of using user groups which I think is very sensible but there are some questions you need to ask. Can users belong to multiple groups? Can permissions be assigned to users or can they only be assigned to groups? Is the administrator a special case or can it be handled as just another group?

Have a look at the way Linux handles users and groups to assign permissions. It's a very well thought out system should offer some inspiration. Additionally the JavaEE 6 documentation orangegoat linked to provides a good overview of security in Java EE (but be warned it's fairly complex).

Having said that I feel I must encourage you to consider making this a web based application rather than using JavaFX. It doesn't sound like you have any particularly complex graphical requirements and it also sounds like you want multiple concurrent access to the system / database (eg more than one teacher can be checking their assignments at a time).

Perhaps I'm a little biased but I think a JavaEE based web application is a better match for these requirements. The business logic and most of the complexity of the multi-user side of things would be handled well by a bunch of EJB 's with all the persistence handled by JPA . The GUI would be written in JSF and PrimeFaces and the whole lot hosted on GlassFish . The real benefit of this set up is that you have a zero installation footprint which will save you a ton of time when rolling out new versions. Going the JavaEE route will probably make it more difficult for you but I feel it's the correct solution given the requirements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM