Spring Security Flashcards

Normal spring projects that have to be converted to WAR and deployed in container.

1
Q

Which configuration is used to automatically generate login and logout functionality in Spring security?

A

auto-config = “true” property means that Spring will generate default login page and logout functionality.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to define in memory users with roles in Spring Security XML configuration?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to get authenticated user’s name in JSP?

A

<h1>${title}</h1>

<h2>${message}</h2>

	<h2>Welcome: ${pageContext.request.userPrincipal.name}

	<a href="%24%7BlogoutUrl%7D">Sign Out</a> </h2>

pageContext.request.userPrincipal.name will contain the name of the authenticated user.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which security expression evaluates to true if the user has been granted the specified role?

A

hasRole(role) and this expression has to be provided in spring-security xml.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which tags are useful for security in view layer?

A

Security in view layer can be achieved using JSP tag library.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Use of tag

A

Allows body of the tag to be rendered if the currently authenticated user has on of the stipulated permissions in the specified domain object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Use of tag

A

Accesses properties of the current user’s authentication object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Use of object

A

Allows the body of the tag to be rendered if a specified security constraint has been met

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Using which mechanisms can we authenticate user

A

1) In memory user repository
2) JDBC based user repository
3) LDAP based user repository
4) OpenID decentralized user identity systems
5) Central Authentication systems (CAS)

6) X.509 certificates
7) JAAS based providers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which tag is used to provide jdbc user repository?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to define SQL to use for querying .

A

users-by-username-query: Queries for a user’s username, password and enabled status given the username
authorities-by-username-query: Queries for a user’s granted authorities given the username
group-authorities-by-username-query: Queries for a user’s group authorities given the username

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Configuration for configuring custom login page in Spring Security?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

In what ways we can provide method security?

A

1) Method annotated with @Secured from Spring security
2) Method annotated with @RolesAllowed from JSR 250
3) Methods annotated with Spring pre and post invocation annotations
4) Methods matching one or more explicitly declared pointcuts

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What should be enabled in XML to allow annotation driven security?

A

should be configured in spring-security context.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Example of method with method level security using Secured annotation

A

@Secured({“ROLE_ADMIN”, “ROLE_TELLER”})

public Account post(Account account, double amount)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What configuration is required in web.xml Web Context file to enable Spring security?

A

We need to configure filter chain so that it will call Security before calling actual controller.

DelegatingFilterProxy needs to be configured in filter chain. Along with that URL mapping is also needed to configure which paths need to be protected using security.

17
Q

How to configure spring security filter chain?

A

springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy

		springSecurityFilterChain
		/*
18
Q

If there are some root level beans that need to be configured like Service, Dao, Security then where should they be kept? In web.xml or some other file?

A

They should be loaded using root context. So for that we need to configure bean ContextLoaderListener and provide path to the root context xml which will contain definitions of all the beans related to Service, Dao or Security.

19
Q

If there are some root level beans that need to be configured like Service, Dao, Security then where should they be kept? In web.xml or some other file?

A

They should be loaded using root context. So for that we need to configure bean ContextLoaderListener and provide path to the root context xml which will contain definitions of all the beans related to Service, Dao or Security.

20
Q

How to link call to logout in JSP? Which tags are needed?

A

“c:url” tag is needed which needs to be imported from JSTL core tag lib.

	<a href="%24%7BlogoutUrl%7D">Sign Out</a>