Access Spring Security annotations from Spring Security filter











up vote
0
down vote

favorite












I am using annotation @Secured("ROLE") on spring mvc controllers, what I want to do is access the value of annotation '@Secured("ROLE") on the controller being invoked based on the request url using filter, then set a parameter on request object request.setParameter(key, value) based on the supplied value of annotation which is 'ROLE' in this case.



I wanted to know how do I access this value of annotation and which spring security filter I should be extending to add a parameter to request object request.setParameter(key, value) and this request parameter should be accessible in controller as well



EDIT:
As the question was marked too broad, let me add more detail.



So I am currently migrating struts 1 action classes to spring mvc, and also adding spring security.
In older implementation, what is happening is when the user is authenticated we put a HashMap<String, AuthObj> in session object where key for this HashMap is the role/privilege and value AuthObj is a object which contains multiple props related to that particular 'Role' and that particular user which was authenticated.



Then there is a org.apache.struts.tiles.TilesRequestProcessor which is executed just before any struts action is invoked, what we are doing in this TilesRequestProcessor is we access the action class config org.apache.struts.config.ActionConfig to read the role/privilege required to invoke that particular action class and then put some properties in request/session object based on the 'role' required to invoke that action class, and the key of this property is same for every action class so that when we access this property in action class later, we don't have to use different key.



My question was how can this be achieved using spring mvc and spring security, important thing is when we put this obj in session/request object, the key should be same for every action class, otherwise i'll have to modify 100s of methods in older code which i am migrating from struts to spring.










share|improve this question




















  • 2




    While you have give a very specific technical requirement, can you explain your primary intent first. For example, by doing what you have explained, what are you intending to achieve finally? It might so turn out, that there exists a better and neater approach to achieving the same end goal.
    – Arun Patra
    Nov 9 at 6:29










  • @ArunPatra I've added more detail to the question.
    – Hasnain Abidi
    Nov 9 at 19:18















up vote
0
down vote

favorite












I am using annotation @Secured("ROLE") on spring mvc controllers, what I want to do is access the value of annotation '@Secured("ROLE") on the controller being invoked based on the request url using filter, then set a parameter on request object request.setParameter(key, value) based on the supplied value of annotation which is 'ROLE' in this case.



I wanted to know how do I access this value of annotation and which spring security filter I should be extending to add a parameter to request object request.setParameter(key, value) and this request parameter should be accessible in controller as well



EDIT:
As the question was marked too broad, let me add more detail.



So I am currently migrating struts 1 action classes to spring mvc, and also adding spring security.
In older implementation, what is happening is when the user is authenticated we put a HashMap<String, AuthObj> in session object where key for this HashMap is the role/privilege and value AuthObj is a object which contains multiple props related to that particular 'Role' and that particular user which was authenticated.



Then there is a org.apache.struts.tiles.TilesRequestProcessor which is executed just before any struts action is invoked, what we are doing in this TilesRequestProcessor is we access the action class config org.apache.struts.config.ActionConfig to read the role/privilege required to invoke that particular action class and then put some properties in request/session object based on the 'role' required to invoke that action class, and the key of this property is same for every action class so that when we access this property in action class later, we don't have to use different key.



My question was how can this be achieved using spring mvc and spring security, important thing is when we put this obj in session/request object, the key should be same for every action class, otherwise i'll have to modify 100s of methods in older code which i am migrating from struts to spring.










share|improve this question




















  • 2




    While you have give a very specific technical requirement, can you explain your primary intent first. For example, by doing what you have explained, what are you intending to achieve finally? It might so turn out, that there exists a better and neater approach to achieving the same end goal.
    – Arun Patra
    Nov 9 at 6:29










  • @ArunPatra I've added more detail to the question.
    – Hasnain Abidi
    Nov 9 at 19:18













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am using annotation @Secured("ROLE") on spring mvc controllers, what I want to do is access the value of annotation '@Secured("ROLE") on the controller being invoked based on the request url using filter, then set a parameter on request object request.setParameter(key, value) based on the supplied value of annotation which is 'ROLE' in this case.



I wanted to know how do I access this value of annotation and which spring security filter I should be extending to add a parameter to request object request.setParameter(key, value) and this request parameter should be accessible in controller as well



EDIT:
As the question was marked too broad, let me add more detail.



So I am currently migrating struts 1 action classes to spring mvc, and also adding spring security.
In older implementation, what is happening is when the user is authenticated we put a HashMap<String, AuthObj> in session object where key for this HashMap is the role/privilege and value AuthObj is a object which contains multiple props related to that particular 'Role' and that particular user which was authenticated.



Then there is a org.apache.struts.tiles.TilesRequestProcessor which is executed just before any struts action is invoked, what we are doing in this TilesRequestProcessor is we access the action class config org.apache.struts.config.ActionConfig to read the role/privilege required to invoke that particular action class and then put some properties in request/session object based on the 'role' required to invoke that action class, and the key of this property is same for every action class so that when we access this property in action class later, we don't have to use different key.



My question was how can this be achieved using spring mvc and spring security, important thing is when we put this obj in session/request object, the key should be same for every action class, otherwise i'll have to modify 100s of methods in older code which i am migrating from struts to spring.










share|improve this question















I am using annotation @Secured("ROLE") on spring mvc controllers, what I want to do is access the value of annotation '@Secured("ROLE") on the controller being invoked based on the request url using filter, then set a parameter on request object request.setParameter(key, value) based on the supplied value of annotation which is 'ROLE' in this case.



I wanted to know how do I access this value of annotation and which spring security filter I should be extending to add a parameter to request object request.setParameter(key, value) and this request parameter should be accessible in controller as well



EDIT:
As the question was marked too broad, let me add more detail.



So I am currently migrating struts 1 action classes to spring mvc, and also adding spring security.
In older implementation, what is happening is when the user is authenticated we put a HashMap<String, AuthObj> in session object where key for this HashMap is the role/privilege and value AuthObj is a object which contains multiple props related to that particular 'Role' and that particular user which was authenticated.



Then there is a org.apache.struts.tiles.TilesRequestProcessor which is executed just before any struts action is invoked, what we are doing in this TilesRequestProcessor is we access the action class config org.apache.struts.config.ActionConfig to read the role/privilege required to invoke that particular action class and then put some properties in request/session object based on the 'role' required to invoke that action class, and the key of this property is same for every action class so that when we access this property in action class later, we don't have to use different key.



My question was how can this be achieved using spring mvc and spring security, important thing is when we put this obj in session/request object, the key should be same for every action class, otherwise i'll have to modify 100s of methods in older code which i am migrating from struts to spring.







java spring spring-mvc spring-boot spring-security






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 19:18

























asked Nov 8 at 23:42









Hasnain Abidi

134




134








  • 2




    While you have give a very specific technical requirement, can you explain your primary intent first. For example, by doing what you have explained, what are you intending to achieve finally? It might so turn out, that there exists a better and neater approach to achieving the same end goal.
    – Arun Patra
    Nov 9 at 6:29










  • @ArunPatra I've added more detail to the question.
    – Hasnain Abidi
    Nov 9 at 19:18














  • 2




    While you have give a very specific technical requirement, can you explain your primary intent first. For example, by doing what you have explained, what are you intending to achieve finally? It might so turn out, that there exists a better and neater approach to achieving the same end goal.
    – Arun Patra
    Nov 9 at 6:29










  • @ArunPatra I've added more detail to the question.
    – Hasnain Abidi
    Nov 9 at 19:18








2




2




While you have give a very specific technical requirement, can you explain your primary intent first. For example, by doing what you have explained, what are you intending to achieve finally? It might so turn out, that there exists a better and neater approach to achieving the same end goal.
– Arun Patra
Nov 9 at 6:29




While you have give a very specific technical requirement, can you explain your primary intent first. For example, by doing what you have explained, what are you intending to achieve finally? It might so turn out, that there exists a better and neater approach to achieving the same end goal.
– Arun Patra
Nov 9 at 6:29












@ArunPatra I've added more detail to the question.
– Hasnain Abidi
Nov 9 at 19:18




@ArunPatra I've added more detail to the question.
– Hasnain Abidi
Nov 9 at 19:18

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53217797%2faccess-spring-security-annotations-from-spring-security-filter%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53217797%2faccess-spring-security-annotations-from-spring-security-filter%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Schultheiß

Verwaltungsgliederung Dänemarks

Liste der Kulturdenkmale in Wilsdruff