Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Project Management > Entities - Es wird die Entity-Klasse User.java mit den Attributen username vom Typ String sowie password vom Typ byte generiert oder durch Auswahl ein bereits existierendes User Entity verwendet. 

  • Project Management > Data Access - Es wird die Entity-Klasse UserDAO.java generiert oder durch Auswahl eines bereits existierendes User Entity das entsprecehnde UserDAO verwendet. 

  • Project Management > Business Objects - Es wird die Klasse ExampleAuthenticationProvider.java generiert.

    Code Block
    languagejava
    themeConfluence
    package com.company.example.business;
    
    import com.company.example.entities.User;
    import com.xdev.security.authentication.Authenticator;
    import com.xdev.security.authentication.AuthenticatorProvider;
    import com.xdev.security.authentication.CredentialsUsernamePassword;
    import com.xdev.security.authentication.jpa.JPAAuthenticator;
    import com.xdev.security.authentication.jpa.HashStrategy.MD5;
    
    public class ExampleAuthenticationProvider
    		implements AuthenticatorProvider<CredentialsUsernamePassword, CredentialsUsernamePassword> {
    	private static ExampleAuthenticationProvider INSTANCE;
    
    	public static ExampleAuthenticationProvider getInstance() {
    		if (INSTANCE == null) {
    			INSTANCE = new ExampleAuthenticationProvider();
    		}
    
    		return INSTANCE;
    	}
    
    	private JPAAuthenticator authenticator;
    
    	private ExampleAuthenticationProvider() {
    	}
    
    	@Override
    	public Authenticator<CredentialsUsernamePassword, CredentialsUsernamePassword> provideAuthenticator() {
    		if (this.authenticator == null) {
    			this.authenticator = new JPAAuthenticator(User.class);
    			this.authenticator.setHashStrategy(new MD5());
    		}
    
    		return this.authenticator;
    	}
    }
Example:
  • Zugangsdaten Passwort verschlüsselt speichern

    Image Added

    Code Block
    languagejava
    themeConfluence
    String password = this.passwordField.getValue();
    byte[] encryptedPassword = new HashStrategy.SHA2().hashPassword(pw.getBytes());
    
    User user = new User();
    user.setUsername(this.textField.getValue());
    user.setPassword(encryptedPassword);
    
    try 
    {
    	new UserDAO().save(user);
    } 
    catch (Exception e) {
    	Notification.show("Error", Type.ERROR_MESSAGE);
    }


...