@Test public void callback() { setSettings(true); DumbCallbackContext callbackContext = new DumbCallbackContext(request, response, "encoded_full_response.txt", SQ_CALLBACK_URL); underTest.callback(callbackContext); assertThat(callbackContext.redirectedToRequestedPage.get()).isTrue(); assertThat(callbackContext.userIdentity.getLogin()).isEqualTo("johndoe"); assertThat(callbackContext.verifyState.get()).isTrue(); }
@Override public void callback(CallbackContext context) { HttpServletRequest processedRequest = useProxyHeadersInRequest(context.getRequest()); Auth auth = newAuth(initSettings(null), processedRequest, context.getResponse()); processResponse(auth); context.verifyCsrfState(STATE_REQUEST_PARAMETER); LOGGER.trace("Name ID : {}", auth.getNameId()); checkAuthentication(auth); LOGGER.trace("Attributes received : {}", auth.getAttributes()); String login = getNonNullFirstAttribute(auth, samlSettings.getUserLogin()); UserIdentity.Builder userIdentityBuilder = UserIdentity.builder() .setLogin(login) .setProviderLogin(login) .setName(getNonNullFirstAttribute(auth, samlSettings.getUserName())); samlSettings.getUserEmail().ifPresent( email -> userIdentityBuilder.setEmail(getFirstAttribute(auth, email))); samlSettings.getGroupName().ifPresent( group -> userIdentityBuilder.setGroups(getGroups(auth, group))); context.authenticate(userIdentityBuilder.build()); context.redirectToRequestedPage(); }
SamlIdentityProvider implements OAuth2IdentityProvider { @Override public void callback(CallbackContext context) { HttpServletRequest processedRequest = useProxyHeadersInRequest(context.getRequest()); Auth auth = newAuth(initSettings(null), processedRequest, context.getResponse()); processResponse(auth); context.verifyCsrfState(STATE_REQUEST_PARAMETER); LOGGER.trace("Name ID : {}", auth.getNameId()); checkAuthentication(auth); LOGGER.trace("Attributes received : {}", auth.getAttributes()); String login = getNonNullFirstAttribute(auth, samlSettings.getUserLogin()); UserIdentity.Builder userIdentityBuilder = UserIdentity.builder() .setLogin(login) .setProviderLogin(login) .setName(getNonNullFirstAttribute(auth, samlSettings.getUserName())); samlSettings.getUserEmail().ifPresent( email -> userIdentityBuilder.setEmail(getFirstAttribute(auth, email))); samlSettings.getGroupName().ifPresent( group -> userIdentityBuilder.setGroups(getGroups(auth, group))); context.authenticate(userIdentityBuilder.build()); context.redirectToRequestedPage(); } }
SamlIdentityProvider implements OAuth2IdentityProvider { @Override public void callback(CallbackContext context) { HttpServletRequest processedRequest = useProxyHeadersInRequest(context.getRequest()); Auth auth = newAuth(initSettings(null), processedRequest, context.getResponse()); processResponse(auth); context.verifyCsrfState(STATE_REQUEST_PARAMETER); LOGGER.trace("Name ID : {}", auth.getNameId()); checkAuthentication(auth); LOGGER.trace("Attributes received : {}", auth.getAttributes()); String login = getNonNullFirstAttribute(auth, samlSettings.getUserLogin()); UserIdentity.Builder userIdentityBuilder = UserIdentity.builder() .setLogin(login) .setProviderLogin(login) .setName(getNonNullFirstAttribute(auth, samlSettings.getUserName())); samlSettings.getUserEmail().ifPresent( email -> userIdentityBuilder.setEmail(getFirstAttribute(auth, email))); samlSettings.getGroupName().ifPresent( group -> userIdentityBuilder.setGroups(getGroups(auth, group))); context.authenticate(userIdentityBuilder.build()); context.redirectToRequestedPage(); } SamlIdentityProvider(SamlSettings samlSettings); }
SamlIdentityProvider implements OAuth2IdentityProvider { @Override public void callback(CallbackContext context) { HttpServletRequest processedRequest = useProxyHeadersInRequest(context.getRequest()); Auth auth = newAuth(initSettings(null), processedRequest, context.getResponse()); processResponse(auth); context.verifyCsrfState(STATE_REQUEST_PARAMETER); LOGGER.trace("Name ID : {}", auth.getNameId()); checkAuthentication(auth); LOGGER.trace("Attributes received : {}", auth.getAttributes()); String login = getNonNullFirstAttribute(auth, samlSettings.getUserLogin()); UserIdentity.Builder userIdentityBuilder = UserIdentity.builder() .setLogin(login) .setProviderLogin(login) .setName(getNonNullFirstAttribute(auth, samlSettings.getUserName())); samlSettings.getUserEmail().ifPresent( email -> userIdentityBuilder.setEmail(getFirstAttribute(auth, email))); samlSettings.getGroupName().ifPresent( group -> userIdentityBuilder.setGroups(getGroups(auth, group))); context.authenticate(userIdentityBuilder.build()); context.redirectToRequestedPage(); } SamlIdentityProvider(SamlSettings samlSettings); @Override String getKey(); @Override String getName(); @Override Display getDisplay(); @Override boolean isEnabled(); @Override boolean allowsUsersToSignUp(); @Override void init(InitContext context); @Override void callback(CallbackContext context); }
SamlIdentityProvider implements OAuth2IdentityProvider { @Override public void callback(CallbackContext context) { HttpServletRequest processedRequest = useProxyHeadersInRequest(context.getRequest()); Auth auth = newAuth(initSettings(null), processedRequest, context.getResponse()); processResponse(auth); context.verifyCsrfState(STATE_REQUEST_PARAMETER); LOGGER.trace("Name ID : {}", auth.getNameId()); checkAuthentication(auth); LOGGER.trace("Attributes received : {}", auth.getAttributes()); String login = getNonNullFirstAttribute(auth, samlSettings.getUserLogin()); UserIdentity.Builder userIdentityBuilder = UserIdentity.builder() .setLogin(login) .setProviderLogin(login) .setName(getNonNullFirstAttribute(auth, samlSettings.getUserName())); samlSettings.getUserEmail().ifPresent( email -> userIdentityBuilder.setEmail(getFirstAttribute(auth, email))); samlSettings.getGroupName().ifPresent( group -> userIdentityBuilder.setGroups(getGroups(auth, group))); context.authenticate(userIdentityBuilder.build()); context.redirectToRequestedPage(); } SamlIdentityProvider(SamlSettings samlSettings); @Override String getKey(); @Override String getName(); @Override Display getDisplay(); @Override boolean isEnabled(); @Override boolean allowsUsersToSignUp(); @Override void init(InitContext context); @Override void callback(CallbackContext context);  }