Java Code Examples for javax.security.auth.message.MessageInfo#getRequestMessage()

The following examples show how to use javax.security.auth.message.MessageInfo#getRequestMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SessionSAM.java    From eplmp with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException {

    HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();
    LOGGER.log(Level.FINE, "Validating request @" + request.getMethod() + " " + request.getRequestURI());

    String login = (String) request.getSession().getAttribute("login");
    String groups = (String) request.getSession().getAttribute("groups");

    CallerPrincipalCallback callerPrincipalCallback = new CallerPrincipalCallback(clientSubject, login);
    GroupPrincipalCallback groupPrincipalCallback = new GroupPrincipalCallback(clientSubject, new String[]{groups});
    Callback[] callbacks = new Callback[]{callerPrincipalCallback, groupPrincipalCallback};

    try {
        callbackHandler.handle(callbacks);
    } catch (IOException | UnsupportedCallbackException e) {
        throw new AuthException(e.getMessage());
    }

    return AuthStatus.SUCCESS;
}
 
Example 2
Source File: GuestSAM.java    From eplmp with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException {

    HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();
    LOGGER.log(Level.FINE, "Validating request @" + request.getMethod() + " " + request.getRequestURI());

    CallerPrincipalCallback callerPrincipalCallback = new CallerPrincipalCallback(clientSubject, "");
    GroupPrincipalCallback groupPrincipalCallback = new GroupPrincipalCallback(clientSubject, new String[]{UserGroupMapping.GUEST_ROLE_ID});
    Callback[] callbacks = {callerPrincipalCallback, groupPrincipalCallback};

    try {
        callbackHandler.handle(callbacks);
    } catch (IOException | UnsupportedCallbackException e) {
        throw new AuthException(e.getMessage());
    }

    return AuthStatus.SUCCESS;

}
 
Example 3
Source File: CustomServerAuthContext.java    From eplmp with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException {

    HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();
    HttpServletResponse response = (HttpServletResponse) messageInfo.getResponseMessage();
    AuthServices.addCORSHeaders(response);

    LOGGER.log(Level.FINE, "validateRequest @" + request.getMethod() + " " + request.getRequestURI());

    if (isOptionsRequest(request)) {
        return AuthStatus.SUCCESS;
    }

    CustomSAM module = getModule(messageInfo);

    if (module != null) {
        return module.validateRequest(messageInfo, clientSubject, serviceSubject);
    }

    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);

    return AuthStatus.FAILURE;
}
 
Example 4
Source File: CustomServerAuthContext.java    From eplmp with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public AuthStatus secureResponse(MessageInfo messageInfo, Subject serviceSubject) throws AuthException {

    HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();
    HttpServletResponse response = (HttpServletResponse) messageInfo.getResponseMessage();
    AuthServices.addCORSHeaders(response);

    LOGGER.log(Level.FINE, "secureResponse @" + request.getMethod() + " " + request.getRequestURI());

    if (isOptionsRequest(request)) {
        return AuthStatus.SEND_SUCCESS;
    }

    CustomSAM module = getModule(messageInfo);

    if (module != null) {
        return module.secureResponse(messageInfo, serviceSubject);
    }

    return AuthStatus.SEND_FAILURE;
}
 
Example 5
Source File: TheServerAuthModule.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject)
        throws AuthException {

    HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();

    Callback[] callbacks;

    if (request.getParameter("doLogin") != null) {
        callbacks = new Callback[]{new CallerPrincipalCallback(clientSubject, "test"),
                new GroupPrincipalCallback(clientSubject, new String[]{"architect"})};
    } else {
        callbacks = new Callback[]{new CallerPrincipalCallback(clientSubject, (Principal) null)};
    }

    try {
        handler.handle(callbacks);
    } catch (IOException | UnsupportedCallbackException e) {
        throw (AuthException) new AuthException().initCause(e);
    }

    cdi(messageInfo, "vr");

    return SUCCESS;
}
 
Example 6
Source File: HttpServletServerAuthModule.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private Principal getUserName(MessageInfo messageInfo)
{
   Object requestInfo =  messageInfo.getRequestMessage();
   String userNameParam = (String) options.get("userNameParam");
   if(requestInfo instanceof HttpServletRequest == false)
      throw PicketBoxMessages.MESSAGES.invalidType(HttpServletRequest.class.getName());
   HttpServletRequest hsr = (HttpServletRequest)requestInfo;
   return new SimplePrincipal(hsr.getParameter(userNameParam));
}
 
Example 7
Source File: HttpServletServerAuthModule.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private Object getCredential(MessageInfo messageInfo)
{
   Object requestInfo = messageInfo.getRequestMessage();
   String passwordParam = (String) options.get("passwordParam");
   if(requestInfo instanceof HttpServletRequest == false)
      throw PicketBoxMessages.MESSAGES.invalidType(HttpServletRequest.class.getName());
   HttpServletRequest hsr = (HttpServletRequest)requestInfo;
   return  hsr.getParameter(passwordParam);
}
 
Example 8
Source File: JWTSAM.java    From eplmp with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public AuthStatus validateRequest(MessageInfo messageInfo, Subject clientSubject, Subject serviceSubject) throws AuthException {

    HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();
    HttpServletResponse response = (HttpServletResponse) messageInfo.getResponseMessage();

    LOGGER.log(Level.FINE, "Validating request @" + request.getMethod() + " " + request.getRequestURI());

    String authorization = request.getHeader("Authorization");
    String[] splitAuthorization = authorization.split(" ");
    String jwt = splitAuthorization[1];

    JWTokenUserGroupMapping jwTokenUserGroupMapping = JWTokenFactory.validateAuthToken(key, jwt);

    if (jwTokenUserGroupMapping != null) {

        UserGroupMapping userGroupMapping = jwTokenUserGroupMapping.getUserGroupMapping();
        CallerPrincipalCallback callerPrincipalCallback = new CallerPrincipalCallback(clientSubject, userGroupMapping.getLogin());
        GroupPrincipalCallback groupPrincipalCallback = new GroupPrincipalCallback(clientSubject, new String[]{userGroupMapping.getGroupName()});
        Callback[] callbacks = new Callback[]{callerPrincipalCallback, groupPrincipalCallback};

        try {
            callbackHandler.handle(callbacks);
        } catch (IOException | UnsupportedCallbackException e) {
            throw new AuthException(e.getMessage());
        }

        JWTokenFactory.refreshTokenIfNeeded(key, response, jwTokenUserGroupMapping);

        return AuthStatus.SUCCESS;
    }

    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    return AuthStatus.FAILURE;

}
 
Example 9
Source File: JWTSAM.java    From eplmp with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean canHandle(MessageInfo messageInfo) {
    HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();

    // Check in headers
    String authorization = request.getHeader("Authorization");
    if (authorization != null && authorization.startsWith("Bearer ")) {
        return authorization.split(" ").length == 2;
    }

    return false;
}
 
Example 10
Source File: SessionSAM.java    From eplmp with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean canHandle(MessageInfo messageInfo) {
    HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();
    HttpSession session = request.getSession(false);

    if(session == null){
        return false;
    }

    String login = (String) session.getAttribute("login");
    String groups = (String) session.getAttribute("groups");
    return login != null && !login.isEmpty() && groups != null && !groups.isEmpty();
}
 
Example 11
Source File: BasicHeaderSAM.java    From eplmp with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean canHandle(MessageInfo messageInfo) {
    HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();
    String authorization = request.getHeader("Authorization");
    return authorization != null && authorization.startsWith("Basic ") && authorization.split(" ").length == 2;
}
 
Example 12
Source File: GuestSAM.java    From eplmp with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean canHandle(MessageInfo messageInfo) {
    HttpServletRequest request = (HttpServletRequest) messageInfo.getRequestMessage();
    return AuthServices.isPublicRequestURI(request.getContextPath(), request.getRequestURI());
}