@Bean public KeyStoreCallbackHandler serverValidationCallbackHandler() { KeyStoreCallbackHandler keyStoreCallbackHandler = new KeyStoreCallbackHandler(); keyStoreCallbackHandler.setPrivateKeyPassword(keyPassword); return keyStoreCallbackHandler; }
@Override public void afterPropertiesSet() throws Exception { if (keyStore == null) { loadDefaultKeyStore(); } if (symmetricKeyPassword == null) { symmetricKeyPassword = privateKeyPassword.toCharArray(); } }
switch (passwordCallback.getUsage()) { case WSPasswordCallback.DECRYPT: handleDecrypt(passwordCallback); break; case WSPasswordCallback.USERNAME_TOKEN: handleUsernameToken(passwordCallback); break; case WSPasswordCallback.SIGNATURE: handleSignature(passwordCallback); break; case WSPasswordCallback.SECURITY_CONTEXT_TOKEN: handleSecurityContextToken(passwordCallback); break; case WSPasswordCallback.CUSTOM_TOKEN: handleCustomToken(passwordCallback); break; case WSPasswordCallback.SECRET_KEY: handleSecretKey(passwordCallback); break; default: handleCleanup((CleanupCallback) callback); handleUsernameTokenPrincipal((UsernameTokenPrincipalCallback) callback);
@Override protected void handleUsernameTokenPrincipal(UsernameTokenPrincipalCallback callback) throws IOException, UnsupportedCallbackException { UserDetails user = loadUserDetails(callback.getPrincipal().getName()); WSUsernameTokenPrincipalImpl principal = callback.getPrincipal(); UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(principal, principal.getPassword(), user.getAuthorities()); if (logger.isDebugEnabled()) { logger.debug("Authentication success: " + authRequest.toString()); } SecurityContextHolder.getContext().setAuthentication(authRequest); }
/** * Invoked when the callback has a {@link WSPasswordCallback#USERNAME_TOKEN} usage. * * <p>This method is invoked when WSS4J needs the password to fill in or to verify a UsernameToken. * * <p>Default implementation throws an {@link UnsupportedCallbackException}. */ protected void handleUsernameToken(WSPasswordCallback callback) throws IOException, UnsupportedCallbackException { UserDetails user = loadUserDetails(callback.getIdentifier()); if (user != null) { SpringSecurityUtils.checkUserValidity(user); callback.setPassword(user.getPassword()); } }
private void processPrincipal(WSHandlerResult result) { List<WSSecurityEngineResult> results = result.getActionResults().get(WSConstants.UT); if (!CollectionUtils.isEmpty(results)) { WSSecurityEngineResult actionResult = results.get(0); Principal principal = (Principal) actionResult.get(WSSecurityEngineResult.TAG_PRINCIPAL); if (principal != null && principal instanceof WSUsernameTokenPrincipalImpl) { WSUsernameTokenPrincipalImpl usernameTokenPrincipal = (WSUsernameTokenPrincipalImpl) principal; UsernameTokenPrincipalCallback callback = new UsernameTokenPrincipalCallback(usernameTokenPrincipal); try { validationCallbackHandler.handle(new Callback[]{callback}); } catch (IOException ex) { logger.warn("Principal callback resulted in IOException", ex); } catch (UnsupportedCallbackException ex) { // ignore } } } }
switch (passwordCallback.getUsage()) { case WSPasswordCallback.DECRYPT: handleDecrypt(passwordCallback); break; case WSPasswordCallback.USERNAME_TOKEN: handleUsernameToken(passwordCallback); break; case WSPasswordCallback.SIGNATURE: handleSignature(passwordCallback); break; case WSPasswordCallback.SECURITY_CONTEXT_TOKEN: handleSecurityContextToken(passwordCallback); break; case WSPasswordCallback.CUSTOM_TOKEN: handleCustomToken(passwordCallback); break; case WSPasswordCallback.SECRET_KEY: handleSecretKey(passwordCallback); break; default: handleCleanup((CleanupCallback) callback); handleUsernameTokenPrincipal((UsernameTokenPrincipalCallback) callback);
@Override protected void handleUsernameTokenPrincipal(UsernameTokenPrincipalCallback callback) throws IOException, UnsupportedCallbackException { UserDetails user = loadUserDetails(callback.getPrincipal().getName()); WSUsernameTokenPrincipalImpl principal = callback.getPrincipal(); UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(principal, principal.getPassword(), user.getAuthorities()); if (logger.isDebugEnabled()) { logger.debug("Authentication success: " + authRequest.toString()); } SecurityContextHolder.getContext().setAuthentication(authRequest); }
@Override public void afterPropertiesSet() throws Exception { if (keyStore == null) { loadDefaultKeyStore(); } if (symmetricKeyPassword == null) { symmetricKeyPassword = privateKeyPassword.toCharArray(); } }
/** * Invoked when the callback has a {@link WSPasswordCallback#USERNAME_TOKEN} usage. * * <p>This method is invoked when WSS4J needs the password to fill in or to verify a UsernameToken. * * <p>Default implementation throws an {@link UnsupportedCallbackException}. */ protected void handleUsernameToken(WSPasswordCallback callback) throws IOException, UnsupportedCallbackException { UserDetails user = loadUserDetails(callback.getIdentifier()); if (user != null) { SpringSecurityUtils.checkUserValidity(user); callback.setPassword(user.getPassword()); } }
private void processPrincipal(WSHandlerResult result) { List<WSSecurityEngineResult> results = result.getActionResults().get(WSConstants.UT); if (!CollectionUtils.isEmpty(results)) { WSSecurityEngineResult actionResult = results.get(0); Principal principal = (Principal) actionResult.get(WSSecurityEngineResult.TAG_PRINCIPAL); if (principal != null && principal instanceof WSUsernameTokenPrincipalImpl) { WSUsernameTokenPrincipalImpl usernameTokenPrincipal = (WSUsernameTokenPrincipalImpl) principal; UsernameTokenPrincipalCallback callback = new UsernameTokenPrincipalCallback(usernameTokenPrincipal); try { validationCallbackHandler.handle(new Callback[]{callback}); } catch (IOException ex) { logger.warn("Principal callback resulted in IOException", ex); } catch (UnsupportedCallbackException ex) { // ignore } } } }
@Bean public KeyStoreCallbackHandler clientValidationCallbackHandler() { KeyStoreCallbackHandler keyStoreCallbackHandler = new KeyStoreCallbackHandler(); keyStoreCallbackHandler.setPrivateKeyPassword(keyPassword); return keyStoreCallbackHandler; } }
switch (passwordCallback.getUsage()) { case WSPasswordCallback.DECRYPT: handleDecrypt(passwordCallback); break; case WSPasswordCallback.USERNAME_TOKEN: handleUsernameToken(passwordCallback); break; case WSPasswordCallback.SIGNATURE: handleSignature(passwordCallback); break; case WSPasswordCallback.SECURITY_CONTEXT_TOKEN: handleSecurityContextToken(passwordCallback); break; case WSPasswordCallback.CUSTOM_TOKEN: handleCustomToken(passwordCallback); break; case WSPasswordCallback.SECRET_KEY: handleSecretKey(passwordCallback); break; default: handleCleanup((CleanupCallback) callback); handleUsernameTokenPrincipal((UsernameTokenPrincipalCallback) callback);
@Override protected void handleUsernameTokenPrincipal(UsernameTokenPrincipalCallback callback) throws IOException, UnsupportedCallbackException { UserDetails user = loadUserDetails(callback.getPrincipal().getName()); WSUsernameTokenPrincipalImpl principal = callback.getPrincipal(); UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(principal, principal.getPassword(), user.getAuthorities()); if (logger.isDebugEnabled()) { logger.debug("Authentication success: " + authRequest.toString()); } SecurityContextHolder.getContext().setAuthentication(authRequest); }
@Override public void afterPropertiesSet() throws Exception { if (keyStore == null) { loadDefaultKeyStore(); } if (symmetricKeyPassword == null) { symmetricKeyPassword = privateKeyPassword.toCharArray(); } }
/** * Invoked when the callback has a {@link WSPasswordCallback#USERNAME_TOKEN} usage. * * <p>This method is invoked when WSS4J needs the password to fill in or to verify a UsernameToken. * * <p>Default implementation throws an {@link UnsupportedCallbackException}. */ protected void handleUsernameToken(WSPasswordCallback callback) throws IOException, UnsupportedCallbackException { UserDetails user = loadUserDetails(callback.getIdentifier()); if (user != null) { SpringSecurityUtils.checkUserValidity(user); callback.setPassword(user.getPassword()); } }
private void processPrincipal(WSHandlerResult result) { List<WSSecurityEngineResult> results = result.getActionResults().get(WSConstants.UT); if (!CollectionUtils.isEmpty(results)) { WSSecurityEngineResult actionResult = results.get(0); Principal principal = (Principal) actionResult.get(WSSecurityEngineResult.TAG_PRINCIPAL); if (principal != null && principal instanceof WSUsernameTokenPrincipalImpl) { WSUsernameTokenPrincipalImpl usernameTokenPrincipal = (WSUsernameTokenPrincipalImpl) principal; UsernameTokenPrincipalCallback callback = new UsernameTokenPrincipalCallback(usernameTokenPrincipal); try { validationCallbackHandler.handle(new Callback[]{callback}); } catch (IOException ex) { logger.warn("Principal callback resulted in IOException", ex); } catch (UnsupportedCallbackException ex) { // ignore } } } }