Wildfly and JAAS login module

前端 未结 2 2222
灰色年华
灰色年华 2021-01-16 06:04

I\'m playing with Wildfly-9.0.1.Final and JAAS but I\'m not having so much fun.. I implemented my custom login module:

public class         


        
相关标签:
2条回答
  • 2021-01-16 06:16

    It's probably an issue (or feature) of the WildFly. I've reported it as WildFly JIRA WFLY-5569.

    You can still use standard servlet authentication which works correctly.

    Add WEB-INF/jboss-web.xml file to your deployment:

    <jboss-web>
        <security-domain>MongoLoginRealm</security-domain>
    </jboss-web>
    

    Adjust your code to use HttpServletRequest.login(String, String) method

    @Context
    private HttpServletRequest req;
    
    @POST
    @Path("/login")
    @PermitAll
    @Consumes(MediaType.APPLICATION_JSON)
    public Response login(User userCredentials) {
        try {
            req.login(userCredentials.getUserName(),
                userCredentials.getPassword());
            Subject subject = org.jboss.security.SecurityContextAssociation.getSubject();
            Optional<Group> rolesGroup = subject.getPrincipals(Group.class).stream().filter(p -> "Roles".equals(p.getName()))
                    .findFirst();
            if (rolesGroup.isPresent()) {
                List<String> roleNames = Collections.list(rolesGroup.get().members()).stream().map(p -> p.getName())
                        .collect(Collectors.toList());
                // ...
            } else {
                // ...
            }
        } catch (ServletException e) {
            log.error("login fails.", e);
            return Response.status(Status.FORBIDDEN).entity("Not logged")
                .type(MediaType.APPLICATION_JSON_TYPE).build();
        }
    }
    
    0 讨论(0)
  • 2021-01-16 06:25

    My application can't find the module because I forgot to add Dependency to it's MANIFEST or to declare login.mongodb as a global module in Wildfly. Thanks @kwart for your suggestion and your answer, you point me to the right direction.

    0 讨论(0)
提交回复
热议问题