DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Container based Security and Spring Security

Container based Security and Spring Security

Krishna Prasad user avatar by
Krishna Prasad
·
Dec. 19, 12 · Interview
Like (0)
Save
Tweet
Share
13.71K Views

Join the DZone community and get the full member experience.

Join For Free

One of the materials on internet that talks about the differences between Container based Security framework and Spring Security is Spring Security FAQ. It lays down the power of Spring Security. Spring MVC based application and other Spring Based application can take advantage of Spring Security

Authentication is a way to provide user identity so that the application identifies who logged into the system. Authorization is a way to tell who can access which part of the application.

As mentioned in that material Container offers Realm based authentication that resides within a containers server.xml vs as opposed to Spring Security that offers Authentication Providers that sits in the application config file,

A simple Realm is Tomcat’s MemoryRealm and it depends on tomcat-users.xml to configure the users, in reality we use LDAP or any database to store user information.

<Realm className="org.apache.catalina.realm.MemoryRealm" />
<role rolename="secureconn"/>
<user username="client" password="password" roles="secureconn"/>
<role rolename="secureconn1"/>
<user username="client1" password="password" roles="secureconn1"/>

A simple Authentication Provider looks as below, and it is not specific to a container. Again in reality the user information will be in LDAP or Database.

<authentication-manager>
<authentication-provider>
<!-- <password-encoder ref="encoder"/>-->
<user-service id="accountService">
<user name="client" password="" authorities="secureconn" />
<user name="client1" password="" authorities="secureconn1" />
</user-service>
</authentication-provider>
</authentication-manager>

In container based security the Authorization can be achieved by a simple, security constraint mechanism as below,

<security-constraint>
<web-resource-collection>
<web-resource-name>Demo App</web-resource-name>
<url-pattern>/secure/*</url-pattern>
<http-method>GET</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>secureconn</role-name>
</auth-constraint>
</security-constraint>

In spring we can achieve Authorization as below, in the spring-security context. The authorization in Container based Security is limited to virtual folder within the container. But with Spring Security we can provide regular expression and secure portions of application.

<http use-expressions="true">
<intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY" requires-channel="https"/>
<intercept-url pattern="/secure1/**" access="hasRole('supervisor')"/>
<intercept-url pattern="/secure/**" access="isAuthenticated()" />
</http>

Spring also extends security further to Service layer using a technique called ACL, refer Spring Security document.

If you notice for simple authentication/authorization capabilities container based security is enough, but for more complex enterprise service level security, it make sense to consider Spring Security.

I hope this blog helped.

Spring Security Spring Framework Container

Published at DZone with permission of Krishna Prasad, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Fraud Detection With Apache Kafka, KSQL, and Apache Flink
  • ChatGPT: The Unexpected API Test Automation Help
  • Select ChatGPT From SQL? You Bet!
  • Express Hibernate Queries as Type-Safe Java Streams

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: