How to enable Spring Security Annotations not using app-Context.xml file? - spring

I've implemented my Application using SecurityContextImpl as SecurityContext. anything works well (Authentication and Authorization).
Now I want to use Spring Security Annotations (#Secured , ...) , I my searched result in a single comment :"USE in your context.xml file"
is there any other way to embed security annotations using non-file-based ContextImpls?

Here's the config snippet you need. Not sure why you don't want to enable via XML.
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans
xmlns:security="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<security:global-method-security secured-annotations="enabled" />
</beans:beans>

Related

Project has many errors related to Spring data JPA, and these errors won't go at all

I have a lot of errors in my project and they won't go off and I know that they are related to Dependency related stuff but I'm confused. Can someone tell me how to fix this if you have also faced the same kind of issue?
Try out this one in your XML:
We use JPA namespace for XML based enabling like below:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/jpa
https://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
<jpa:repositories base-package="path.to.repository.package" />
</beans>

Spring Security Configuration : You cannot use a spring-security-2.0.xsd or spring

Could anybody help on this.
I am getting below exception not sure why?
Exception while starting server
Configuration problem: You cannot use a spring-security-2.0.xsd or
spring-security-3.0.xsd or spring-security-3.1.xsd schema with Spring
Security 3.2. Please update your schema declarations to the 3.2
schema.
could anybody help in this please. I am using 3.0.5.RELEASE in Pom.xml and giving spring-security-3.0.xsd in security-context.
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
**Please update your schema declarations to the 3.2 schema.**
Change schema declaration to 3.2..because you may be using Spring security 3.2 jar( exception ..or spring-security-3.1.xsd schema with Spring Security 3.2.)
http://www.springframework.org/schema/security/spring-security-3.2.xsd"
Or don't mention the version,it will automatically take the higher version provided.
http://www.springframework.org/schema/security/spring-security.xsd"

Spring bean configuration xml

In Spring config xml we have tag and in that tag we have xmlns, xsi etc..
what all these details means ? When and how these details matters?
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
</beans>
thanks,
You can find the nice answer of xsi:schema use here Use of xsi:schemaLocation
And this spring document will help you understand the spring configuration in details XML Schema-based configuration

Concurrent Session Control - Spring Security

HI I am trying to implement Spring Security: Concurrent Session Control to limit one session at a time. I see that I only need
<http>
...
<session-management>
<concurrency-control max-sessions="1" />
</session-management>
</http>
I get this from the reference http://docs.spring.io/spring-security/site/docs/3.1.x/reference/springsecurity-single.html#ns-config . The problem that I am facing is that i get this error saying, "Configuration problem: No AuthenticationEntryPoint could be established. Please make sure you have a login mechanism configured through the namespace (such as form-login) or specify a custom AuthenticationEntryPoint with the 'entry-point-ref' attribute" I do not need to use a login page in the configuration here. I saw other posts, but I cannot find a solution to this problem. Please help me with a solution here. I will post my code below.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring- mvc.xsd">
<security:http>
<security:session-management>
<security:concurrency-control max-sessions="1" error-if-maximum-exceeded="true" />
</security:session-management>
</security:http>

XML alternative for #Repository for translation native exceptions to DataAccessException

I'am trying to configure spring with XML syntax only and come into a problem with native resource exceptions translation to DataAccessException. According to documentation I always need to put #Repository on repository bean and declare PersistenceExceptionTranslationPostProcessor bean. I think that here should be the way to define some sort of filter using AOP which will perform exceptions translation but can't find anything like this in docs. The idea is to introduce convention, for example 'for everything what ends with Dao apply native exceptions translation'. Any ideas?
Similar to #Repository annotaion spring xml config looks like:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
...
<bean id="translationInterceptor" class="org.springframework.dao.support.PersistenceExceptionTranslationInterceptor" />
<aop:config>
<aop:advisor advice-ref="translationInterceptor" pointcut="within(org.example.spring.dao..*Dao)" />
</aop:config>
...
</beans>
Pointcut "within(org.example.spring.dao..*Dao)" applies interceptor to methods in classes located in package org.example.spring.dao and its subpackages ends with "Dao" suffix

Resources