添加角色jhipster 4.0.1

时间:2017-02-21 08:39:15

标签: angular typescript jhipster

我想在我的应用程序jhipster 4.0.1中添加一些角色。使用文档mongo jhi_authorities以及java端和webapp端添加这些角色之后。我可以添加具有特定角色的用户,但我无法与他一起登录。 这是我添加的代码: 在src/main/java/com/mycompany/myapp/security/AuthoritiesConstants.java`包com.mycompany.myapp.security;

/ **  * Spring Security当局的常量。  * / 公共最终类AuthoritiesConstants {

public static final String ADMIN = "ROLE_ADMIN";

public static final String USER = "ROLE_USER";

public static final String ANONYMOUS = "ROLE_ANONYMOUS";

public static final String MANAGER = "ROLE_MANAGER"; // role added

public static final String MEDECIN = "ROLE_MEDECIN"; // role added

public static final String CHEF_SERVICE = "ROLE_CHEF_SERVICE"; // role added

public static final String SERVICE_FINANCIER = "ROLE_SERVICE_FINANCIER"; // role added

public static final String INFIRMIER = "ROLE_INFIRMIER";  // role added

public static final String GESTIONNAIREDEMATERIEL = "ROLE_GESTIONNAIREDEMATERIEL";  // role added

public static final String PHARMACIEN = "ROLE_PHARMACIEN";  // role added



private AuthoritiesConstants() {
}

}`并在thewebapp方面我补充道:

' /src/main/webapp/app/admin/user-management/user-management-dialog.component.ts ' i added in the function ' ngOnInit() '  
'  ngOnInit() {
        this.isSaving = false;
        this.authorities = ['ROLE_USER', 'ROLE_ADMIN', 'ROLE_MANAGER', 'ROLE_MEDECIN','ROLE_CHEF_SERVICE','ROLE_SERVICE_FINANCIER','ROLE_INFIRMIER','ROLE_GESTIONNAIREDEMATERIEL', 'ROLE_PHARMACIEN']; // All Roles
        this.languageHelper.getAll().then((languages) => {
            this.languages = languages;
        });
        this.jhiLanguageService.setLocations(['user-management']);
    } ' 
and in 'login.service.ts' the modifction is :
'login (credentials, callback?) {
    let cb = callback || function() {};

    return new Promise((resolve, reject) => {
        this.authServerProvider.login(credentials).subscribe(data => {
            this.principal.identity(true).then(account => {
                // After the login the language will be changed to
                // the language selected by the user during his registration
                if (account !== null) {
                    this.languageService.changeLanguage(account.langKey);
                }
                resolve(data);
            });
            return cb();
        }, err => {
            this.logout();
            reject(err);
            return cb(err);
        });
    });
}' 

并在'login.component.ts'中修改为:

' login () {
    this.loginService.login({
        username: this.username,
        password: this.password,
        rememberMe: this.rememberMe
    }).then((account: Account) => {
        this.authenticationError = false;
        this.activeModal.dismiss('login success');
        if (this.router.url === '/register' || this.router.url === '/activate' ||
            this.router.url === '/finishReset' || this.router.url === '/requestReset') {
            this.router.navigate(['']);
        }

        this.eventManager.broadcast({
            name: 'authenticationSuccess',
            content: 'Sending Authentication Success'
        });

        // // previousState was set in the authExpiredInterceptor before being redirected to login modal.
        // // since login is succesful, go to stored previousState and clear previousState
        let previousState = this.stateStorageService.getPreviousState();
        //**CHANGED** check if we have are a manager
        let isManager = account.authorities.indexOf("ROLE_MANAGER") > -1;
        if(isManager) { 
            this.stateStorageService.resetPreviousState();
            this.router.navigate(['your-manager-specific-state']);
        } 
        else if (previousState) {
            this.stateStorageService.resetPreviousState();
            this.router.navigate([previousState.name], { queryParams:  previousState.params });
        }
    }).catch(() => {
        this.authenticationError = true;
    });}

我可以管理新角色并注册,但我无法使用它们登录,也无法更改密码。

0 个答案:

没有答案