Jetspeed2 如何在jetspeed中设置用户信息?

Jetspeed2 如何在jetspeed中设置用户信息?,jetspeed2,Jetspeed2,我们在一个项目中使用Jetspeed,并要求Jetspeed应该针对第三方rest服务进行身份验证,该服务接受用户名和密码并返回用户对象 我发现实现此功能而不影响jetspeed的最简单、最直接的方法是编写自定义AuthenticationProvider,扩展DefaultAuthenticationProvider类并重写login方法 在对用户进行身份验证后,我会返回用户详细信息,包括角色、电子邮件等。现在,如果用户已经存在于jetspeed数据库中,我会同步他的角色,否则我会创建该用户并

我们在一个项目中使用Jetspeed,并要求Jetspeed应该针对第三方rest服务进行身份验证,该服务接受用户名和密码并返回用户对象

我发现实现此功能而不影响jetspeed的最简单、最直接的方法是编写自定义AuthenticationProvider,扩展DefaultAuthenticationProvider类并重写login方法

在对用户进行身份验证后,我会返回用户详细信息,包括角色、电子邮件等。现在,如果用户已经存在于jetspeed数据库中,我会同步他的角色,否则我会创建该用户并为其分配远程服务返回的角色

现在我想要一种设置user.email、user.firstname和user.lastname属性的方法,这样就可以在psml文件中使用$jetspeed.getUserAttribute访问它。知道我们怎么做吗

这是我的代码[删除不必要的东西]--

公共类CustomAuthenticationProvider扩展了BaseAuthenticationProvider{
....
公共身份验证用户身份验证(字符串用户名、字符串密码)引发SecurityException{
试一试{
//登录用户
UserSessionDTO customSession=Security.login(用户名、密码);
//获取用户详细信息
UserDTO customUser=customSession.getUser();
//获取用户角色
列表角色=customUser.getUserRoleDTOList();
//在jetspeed用户数据库中验证/创建用户
UserImpl user=null;
如果(!um.userExists(customUser.getLoginId())){
user=(UserImpl)um.addUser(customUser.getLoginId(),true);
//标准数据
user.setMapping(true);
user.setEnabled(true);
}否则{
user=(UserImpl)um.getUser(customUser.getLoginId());
}
//将门户用户角色与CMGI用户角色同步
List portalRoles=rm.getRolesForUser(customUser.getLoginId());
for(角色portalRole:portalRoles){
Boolean found=Boolean.FALSE;
for(UserRoleDTO角色:角色){
if(role.getRoleName().equalsIgnoreCase(portalRole.getName())){
found=Boolean.TRUE;
打破
}
}
如果(!找到){
rm.removolefromuser(用户名,portalRole.getName());
}
}
for(UserRoleDTO角色:角色){
rm.addRoleToUser(用户名,role.getRoleName());
}
PasswordCredential pwc=新的PasswordCredentialImpl(用户,密码);
UserCredentialImpl uc=新的UserCredentialImpl(普华永道);
AuthenticatedUserImpl authUser=新的AuthenticatedUserImpl(用户,uc);
返回authUser;
} 
。。。。 }
}

您可以在security-managers.xml中的Jetspeed用户bean“org.apache.Jetspeed.security.JetspeedPrincipalType.user”中添加自定义用户属性

这些属性应该这样定义 e、 g


public class CustomAuthenticationProvider extends BaseAuthenticationProvider {

....

    public AuthenticatedUser authenticate(String userName, String password) throws SecurityException {


        try {

            //Login the user
            UserSessionDTO customSession = Security.login(userName, password);

            //Fetch the user details
            UserDTO customUser = customSession.getUser();

            //Get the user roles
            List<UserRoleDTO> roles = customUser.getUserRoleDTOList();

            //Verify/create the user in jetspeed user database
            UserImpl user = null;
            if (!um.userExists(customUser.getLoginId())) {
                user = (UserImpl) um.addUser(customUser.getLoginId(), true);

                //Standard data
                user.setMapped(true);
                user.setEnabled(true);
            } else {
                user = (UserImpl) um.getUser(customUser.getLoginId());
            }

            //Sync the portal user roles with the CMGI user roles
            List<Role> portalRoles = rm.getRolesForUser(customUser.getLoginId());
            for (Role portalRole : portalRoles) {
                Boolean found = Boolean.FALSE;
                for (UserRoleDTO role : roles) {
                    if (role.getRoleName().equalsIgnoreCase(portalRole.getName())) {
                        found = Boolean.TRUE;
                        break;
                    }
                }
                if(!found){
                    rm.removeRoleFromUser(userName, portalRole.getName());
                }
            }

            for(UserRoleDTO role : roles){
                rm.addRoleToUser(userName, role.getRoleName()); 
            }



            PasswordCredential pwc = new PasswordCredentialImpl(user, password);
            UserCredentialImpl uc = new UserCredentialImpl(pwc);
            AuthenticatedUserImpl authUser = new AuthenticatedUserImpl(user, uc);
            return authUser;


        } 
        <bean class="org.apache.jetspeed.security.impl.SecurityAttributeTypeImpl">
          <constructor-arg index="0" value="user.lastname" />
          <constructor-arg index="1" value="info" />
        </bean>