Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can create a access token that contains your desire information such as IP Address, user name etc. During the authentication phase create a custom token and put this token into spring security context. Later you could extract this token from other places such in your proxy classes. After extracting the token you validate or whatever you want.</p> <p><strong>Creating custom object and token:</strong></p> <pre><code>public class CustomAuthentication { private String userId; private String password; private String ipAddress; } public class CustomAuthenticationToken extends AbstractAuthenticationToken { private CustomAuthentication customAuthentication; public CustomAuthenticationToken(MobiLabAuthentication authentication, Collection&lt;? extends GrantedAuthority&gt; authorities) { super(authorities); this.customAuthentication = authentication; setAuthenticated(true); } public CustomAuthenticationToken() { super(null); setAuthenticated(false); } @Override public Object getCredentials() { return customAuthentication.getPassword(); } @Override public Object getPrincipal() { return customAuthentication.getUserId(); } } </code></pre> <p><strong>Store the token into Spring security context</strong></p> <pre><code>List&lt;GrantedAuthority&gt; authorities = new ArrayList&lt;GrantedAuthority&gt;(); authorities.add(new RestUserAuthrity("YOUR_APP_ROLE")); //Extract IP , user and pass etc and construct CustomAuthentication instance CustomAuthentication authentication = new CustomAuthentication(.....) CustomAuthenticationToken authenticationToken = new CustomAuthenticationToken( authentication, authorities); SecurityContextHolder.getContext().setAuthentication(authenticationToken); </code></pre> <p><strong>Validate security information from the Proxy bean</strong></p> <pre><code>SecurityContext context = SecurityContextHolder.getContext(); Authentication authentication = context.getAuthentication(); if (authentication instanceof CustomAuthenticationToken) { CustomAuthenticationToken token = (CustomAuthenticationToken) authentication; //now you can get your ip address from token } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload