Skip to content

Commit

Permalink
JASPIC updates (minus the AuthenticatorBase integration)
Browse files Browse the repository at this point in the history
Fix the wrapping and the register-session javaee7-samples tests

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1729925 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Feb 11, 2016
1 parent 364895d commit c3b57c9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
6 changes: 5 additions & 1 deletion java/org/apache/catalina/authenticator/Constants.java
Expand Up @@ -55,7 +55,11 @@ public class Constants {
* request is associated.
*/
public static final String REQ_SSOID_NOTE =
"org.apache.catalina.request.SSOID";
"org.apache.catalina.request.SSOID";


public static final String REQ_JASPIC_SUBJECT_NOTE =
"org.apache.catalina.authenticator.jaspic.SUBJECT";


// ---------------------------------------------------------- Session Notes
Expand Down
Expand Up @@ -19,6 +19,7 @@ authenticator.check.authorize=Authorizing connector provided user [{0}] via Tomc
authenticator.check.authorizeFail=Realm did not recognise user [{0}]. Creating a Principal with that name and no roles.
authenticator.check.found=Already authenticated [{0}]
authenticator.check.sso=Not authenticated but SSO session ID [{0}] found. Attempting re-authentication.
authenticator.jaspicCleanSubjectFail=Failed to clean JASPIC subject
authenticator.formlogin=Invalid direct reference to form login page
authenticator.loginFail=Login failed
authenticator.manager=Exception initializing trust managers
Expand Down
Expand Up @@ -29,7 +29,6 @@
import javax.security.auth.message.callback.CallerPrincipalCallback;
import javax.security.auth.message.callback.GroupPrincipalCallback;

import org.apache.catalina.connector.Request;
import org.apache.catalina.realm.GenericPrincipal;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
Expand All @@ -40,18 +39,12 @@ public class CallbackHandlerImpl implements CallbackHandler {
private static final Log log = LogFactory.getLog(CallbackHandlerImpl.class);
private static final StringManager sm = StringManager.getManager(CallbackHandlerImpl.class);

private Request request;
private String name;
private Principal principal;
private Subject subject;
private String[] groups;


public CallbackHandlerImpl(Request request) {
this.request = request;
}


@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
if (callbacks != null) {
Expand All @@ -74,19 +67,19 @@ public void handle(Callback[] callbacks) throws IOException, UnsupportedCallback
}

// Create the GenericPrincipal
GenericPrincipal gp = getGenericPrincipal();
if (gp != null) {
request.setUserPrincipal(gp);

if (subject != null) {
subject.getPrivateCredentials().add(gp);
}
Principal gp = getPrincipal();
if (subject != null && gp != null) {
subject.getPrivateCredentials().add(gp);
}
}
}


public GenericPrincipal getGenericPrincipal() {
private Principal getPrincipal() {
// If the Principal is cached in the session JASPIC may simply return it
if (principal instanceof GenericPrincipal) {
return principal;
}
String name = this.name;
if (name == null && principal != null) {
name = principal.getName();
Expand Down
Expand Up @@ -20,9 +20,9 @@
import java.util.Map;

import javax.security.auth.message.MessageInfo;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.catalina.connector.Request;
import org.apache.tomcat.util.res.StringManager;

public class MessageInfoImpl implements MessageInfo {
Expand All @@ -31,13 +31,13 @@ public class MessageInfoImpl implements MessageInfo {
public static final String IS_MANDATORY = "javax.security.auth.message.MessagePolicy.isMandatory";

private final Map<String, Object> map = new HashMap<>();
private Request request;
private HttpServletRequest request;
private HttpServletResponse response;

public MessageInfoImpl() {
}

public MessageInfoImpl(Request request, HttpServletResponse response, boolean authMandatory) {
public MessageInfoImpl(HttpServletRequest request, HttpServletResponse response, boolean authMandatory) {
this.request = request;
this.response = response;
map.put(IS_MANDATORY, Boolean.toString(authMandatory));
Expand All @@ -62,11 +62,11 @@ public Object getResponseMessage() {

@Override
public void setRequestMessage(Object request) {
if (!(request instanceof Request)) {
if (!(request instanceof HttpServletRequest)) {
throw new IllegalArgumentException(sm.getString("authenticator.jaspic.badRequestType",
request.getClass().getName()));
}
this.request = (Request) request;
this.request = (HttpServletRequest) request;
}

@Override
Expand Down

0 comments on commit c3b57c9

Please sign in to comment.